@@ -5,6 +5,7 @@ vi.mock('@/mcp/official-mcp-access', async (orig) => ({ ...(await orig<any>()),
55const api = vi . hoisted ( ( ) => ( { getN8nApiClient : vi . fn ( ) } ) ) ;
66vi . mock ( '@/mcp/handlers-n8n-manager' , ( ) => ( { getN8nApiClient : api . getN8nApiClient } ) ) ;
77import { handleExploreNodeResources , handleListCatalog , callOfficialTool , resolveProjectChoices } from '@/mcp/handlers-official-tools' ;
8+ import { PUBLIC_API_CONTEXT_HINT } from '@/services/mcp-exposure' ;
89import { N8nApiError } from '@/utils/n8n-errors' ;
910import { N8nOfficialMcpClient } from '@/services/n8n-official-mcp-client' ;
1011import { startFakeOfficialMcp , FakeOfficialMcp , FakeTool } from '../../helpers/fake-official-mcp-server' ;
@@ -174,6 +175,28 @@ describe('handleListCatalog', () => {
174175 const r = await handleListCatalog ( { kind : 'tags' , query : 'prod' , limit : 1 } ) ;
175176 expect ( r ) . toMatchObject ( { success : true , kind : 'tags' , backend : 'public-api' , data : { items : [ { id : 't1' , name : 'Prod' } ] } } ) ;
176177 } ) ;
178+ it ( 'does not fall back to the environment API for tags on a url + token context' , async ( ) => {
179+ api . getN8nApiClient . mockReturnValue ( { listTags : vi . fn ( ) } ) ;
180+
181+ const r = await handleListCatalog (
182+ { kind : 'tags' } ,
183+ { n8nApiUrl : 'https://other.test.com' , n8nMcpAccessToken : 'tok' }
184+ ) ;
185+
186+ expect ( api . getN8nApiClient ) . not . toHaveBeenCalled ( ) ;
187+ expect ( r ) . toMatchObject ( { success : false , code : 'NOT_CONFIGURED' , error : PUBLIC_API_CONTEXT_HINT } ) ;
188+ } ) ;
189+ it ( 'uses the context-specific hint when projects have no matching client' , async ( ) => {
190+ api . getN8nApiClient . mockReturnValue ( null ) ;
191+ access . getOfficialMcpClient . mockReturnValue ( null ) ;
192+
193+ const r = await handleListCatalog (
194+ { kind : 'projects' } ,
195+ { n8nApiUrl : 'https://other.test.com' , n8nMcpAccessToken : 'tok' }
196+ ) ;
197+
198+ expect ( r ) . toMatchObject ( { success : false , code : 'NOT_CONFIGURED' , error : PUBLIC_API_CONTEXT_HINT } ) ;
199+ } ) ;
177200 it ( 'rejects unknown kinds' , async ( ) => {
178201 expect ( await handleListCatalog ( { kind : 'users' } ) ) . toMatchObject ( { success : false , code : 'INVALID_ARGS' } ) ;
179202 } ) ;
0 commit comments