Propagate MCP tool cancellation to host executors - #803
Merged
Conversation
|
I hit an error while handling your request (Model unavailable on AI Gateway free tier: Free tier users do not have access to this model. Upgrade to paid credits at https://vercel.com/d?to=%2F%5Bteam%5D%2F%7E%2Fai%3Fmodal%3Dtop-up for unrestricted…). Please try again, rephrase, or reach out if it keeps failing. Error id: 180318f6-425c-46ee-acfc-1d58c991f3d9 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
MCP hosts that queue tool handlers need the SDK request cancellation signal before executing queued work. The server wrapper now passes each handler's
AbortSignaltoexecuteTooland applies the wrapper to bothregisterTool()and the deprecatedtool()registration surface, so tools added after server creation cannot bypass host sequencing or cancellation policy.Validation
bun test packages/mcp/src— 359 tests, 1,361 assertions passed.bunx ultracite check packages/mcp/src/server.ts packages/mcp/src/server.test.tsgit diff --checkNote
Medium Risk
Extends the public
executeToolcontract and changes when queued hosts may run or skip tool callbacks on cancellation.Overview
MCP hosts that wrap tool execution (e.g. to queue work) can now observe request cancellation before the underlying handler runs.
PascalMcpToolExecutorgains a requiredsignal: AbortSignal, andinstallToolExecutorforwards the SDK request signal from handler arguments for bothregisterTooland the deprecatedtool()path so late-registered tools still go through the host wrapper. Tests cover signal presence, abort-before-callback (tool body never runs), and legacy registration.Reviewed by Cursor Bugbot for commit 6ac73da. Bugbot is set up for automated code reviews on this repo. Configure here.