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

View File

@@ -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
: [];

View File

@@ -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),
]);

View File

@@ -286,7 +286,10 @@ export class McpClient {
this.resourceRegistry.setResourcesForServer(this.serverName, resources);
}
async readResource(uri: string): Promise<ReadResourceResult> {
async readResource(
uri: string,
options?: { signal?: AbortSignal },
): Promise<ReadResourceResult> {
this.assertConnected();
return this.client!.request(
{
@@ -294,6 +297,7 @@ export class McpClient {
params: { uri },
},
ReadResourceResultSchema,
options,
);
}