propagate abortSignal (#18477)

This commit is contained in:
Tommaso Sciortino
2026-02-08 13:56:26 -08:00
committed by GitHub
parent 92012365ca
commit 29a6aecffc
3 changed files with 11 additions and 4 deletions
@@ -1291,7 +1291,9 @@ describe('handleAtCommand', () => {
signal: abortController.signal, signal: abortController.signal,
}); });
expect(readResource).toHaveBeenCalledWith(resourceUri); expect(readResource).toHaveBeenCalledWith(resourceUri, {
signal: abortController.signal,
});
const processedParts = Array.isArray(result.processedQuery) const processedParts = Array.isArray(result.processedQuery)
? result.processedQuery ? result.processedQuery
: []; : [];
@@ -371,6 +371,7 @@ function constructInitialQuery(
async function readMcpResources( async function readMcpResources(
resourceParts: AtCommandPart[], resourceParts: AtCommandPart[],
config: Config, config: Config,
signal: AbortSignal,
): Promise<{ ): Promise<{
parts: PartUnion[]; parts: PartUnion[];
displays: IndividualToolCallDisplay[]; displays: IndividualToolCallDisplay[];
@@ -396,7 +397,7 @@ async function readMcpResources(
`MCP client for server '${resource.serverName}' is not available or not connected.`, `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); const resourceParts = convertResourceContentsToParts(response);
return { return {
success: true, success: true,
@@ -665,7 +666,7 @@ export async function handleAtCommand({
} }
const [mcpResult, fileResult] = await Promise.all([ const [mcpResult, fileResult] = await Promise.all([
readMcpResources(resourceParts, config), readMcpResources(resourceParts, config, signal),
readLocalFiles(resolvedFiles, config, signal, userMessageTimestamp), readLocalFiles(resolvedFiles, config, signal, userMessageTimestamp),
]); ]);
+5 -1
View File
@@ -286,7 +286,10 @@ export class McpClient {
this.resourceRegistry.setResourcesForServer(this.serverName, resources); this.resourceRegistry.setResourcesForServer(this.serverName, resources);
} }
async readResource(uri: string): Promise<ReadResourceResult> { async readResource(
uri: string,
options?: { signal?: AbortSignal },
): Promise<ReadResourceResult> {
this.assertConnected(); this.assertConnected();
return this.client!.request( return this.client!.request(
{ {
@@ -294,6 +297,7 @@ export class McpClient {
params: { uri }, params: { uri },
}, },
ReadResourceResultSchema, ReadResourceResultSchema,
options,
); );
} }