diff --git a/packages/cli/src/ui/hooks/atCommandProcessor.test.ts b/packages/cli/src/ui/hooks/atCommandProcessor.test.ts index 809d8f20b4b..b3a53c9b7ee 100644 --- a/packages/cli/src/ui/hooks/atCommandProcessor.test.ts +++ b/packages/cli/src/ui/hooks/atCommandProcessor.test.ts @@ -1291,7 +1291,9 @@ describe('handleAtCommand', () => { signal: abortController.signal, }); - expect(readResource).toHaveBeenCalledWith(resourceUri); + expect(readResource).toHaveBeenCalledWith(resourceUri, { + signal: abortController.signal, + }); const processedParts = Array.isArray(result.processedQuery) ? result.processedQuery : []; diff --git a/packages/cli/src/ui/hooks/atCommandProcessor.ts b/packages/cli/src/ui/hooks/atCommandProcessor.ts index 08d61cf2412..a316e5df36d 100644 --- a/packages/cli/src/ui/hooks/atCommandProcessor.ts +++ b/packages/cli/src/ui/hooks/atCommandProcessor.ts @@ -371,6 +371,7 @@ function constructInitialQuery( async function readMcpResources( resourceParts: AtCommandPart[], config: Config, + signal: AbortSignal, ): Promise<{ parts: PartUnion[]; displays: IndividualToolCallDisplay[]; @@ -396,7 +397,7 @@ async function readMcpResources( `MCP client for server '${resource.serverName}' is not available or not connected.`, ); } - const response = await client.readResource(resource.uri); + const response = await client.readResource(resource.uri, { signal }); const resourceParts = convertResourceContentsToParts(response); return { success: true, @@ -665,7 +666,7 @@ export async function handleAtCommand({ } const [mcpResult, fileResult] = await Promise.all([ - readMcpResources(resourceParts, config), + readMcpResources(resourceParts, config, signal), readLocalFiles(resolvedFiles, config, signal, userMessageTimestamp), ]); diff --git a/packages/core/src/tools/mcp-client.ts b/packages/core/src/tools/mcp-client.ts index 37a7cfc8700..3a009d37d65 100644 --- a/packages/core/src/tools/mcp-client.ts +++ b/packages/core/src/tools/mcp-client.ts @@ -286,7 +286,10 @@ export class McpClient { this.resourceRegistry.setResourcesForServer(this.serverName, resources); } - async readResource(uri: string): Promise { + async readResource( + uri: string, + options?: { signal?: AbortSignal }, + ): Promise { this.assertConnected(); return this.client!.request( { @@ -294,6 +297,7 @@ export class McpClient { params: { uri }, }, ReadResourceResultSchema, + options, ); }