[JS] Aborting generate() doesn't cancel an MCP tool call, and generate() waits for the tool to finish
Maintainers usually reply within 2 days
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 75/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- typescript
- Domain
- backend-api-design
Research direction
Start with the MCP tool actions in js/plugins/mcp/src/util/tools.ts and check how their second argument provides abortSignal. Compare the client.callTool options with the MCP TypeScript SDK behavior described in the issue, then review the unit test in tests/tools_test.ts. Done when aborting generate() promptly rejects and the MCP server receives cancellation.
Written by the indexing model from the issue text.
Description
Describe the bug
When ai.generate() is aborted with abortSignal while it runs a tool from @genkit-ai/mcp, the MCP request is never cancelled. The server runs the tool to the end, and generate() only rejects after the tool returns.
The tool actions in js/plugins/mcp/src/util/tools.ts receive the abort signal (abortSignal in the action's second argument) but call client.callTool({ name, arguments, _meta }) without it, so the MCP client never sends notifications/cancelled and keeps waiting for the result.
To Reproduce
A scripted model asks for one MCP tool call (slow_task, 5 s) and the call is aborted after 1 s. Full repro (server and client, no API key): https://github.com/Koobi33/seams-lab/tree/main/repro/genkit-mcp-abort
const controller = new AbortController();
setTimeout(() => controller.abort(), 1000);
await ai.generate({ model, prompt: 'go', tools, abortSignal: controller.signal });
Output:
[server] slow_task ran all 5s
generate rejected after 5166 ms: This operation was aborted
Expected behavior
generate() rejects right after the abort, and the server is told to stop (notifications/cancelled), as the MCP TypeScript SDK does when callTool gets a signal.
Runtime (please complete the following information):
- OS: macOS
- Version: genkit and @genkit-ai/mcp 1.44.0, also main at 97115d9
** Node version
- v26.13.1
Additional context
Reproduces 2 out of 2 runs on 1.44.0 and on main. Passing the signal through fixes it: async (args, { context, abortSignal }) and client.callTool(params, undefined, { signal: abortSignal }) in the four tool definitions. With that change the same repro gives:
generate rejected after 1007 ms: MCP error -32001: AbortError: This operation was aborted
[server] slow_task cancelled after 1s
I'd like to work on this. I have the change with a unit test in tests/tools_test.ts (27 passed) and can open a PR once you're OK with the approach.
- Dominant language
- TypeScript
- Stars
- 6.6k
- Forks
- 896
- Avg merge
- 4d 8h
- Merged PRs (30d)
- 138
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from genkit-ai/genkit
-
cli
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
Maintainers usually reply within 2 days
-
cli
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Maintainers usually reply within 2 days
-
[CLI] Ephemeral flow:run logs "Code: undefined" and "Message: undefined" on JSON-RPC action errorsOpenbug cli
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Maintainers usually reply within 2 days
-
Difficulty 2/5 1-3 hours Newbie friendliness 66/100
genkit-ai/genkit#7464 · 1 comment ·
Maintainers usually reply within 2 days
-
[JS] Support GENKIT_LOG_LEVEL environment variable in core loggerPossibly taken @austinchennn claimed this 4 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
genkit-ai/genkit#7389 · 1 comment ·
Maintainers usually reply within 2 days
All issues in genkit-ai/genkit
Similar issues
-
Difficulty 1/5 Under an hour Newbie friendliness 92/100
Techiebutler/freeframe#687 ·
Maintainers usually reply within 1 day
-
enhancement from-app needs-triage
Difficulty 2/5 1-3 hours Newbie friendliness 67/100
nightly-labs/openbot#23050 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 66/100
vercel-labs/skills#2967 ·
Maintainers usually reply within 1 day
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
OHDSI/Data2Evidence#3846 ·
Maintainers usually reply within 3 days
-
frontend: EditorDialog: Save & Apply on an empty or comment-only document reports success and applies nothingPossibly taken @shubhamrai9122-creator claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
kubernetes-sigs/headlamp#9086 ·
Maintainers usually reply within 1 day