Skip to content

fix(mcp): cancelled and timed-out MCP calls are stopped on the server - #120

Merged
huangjeff5 merged 1 commit into
mainfrom
fix/py-mcp-cancel-notification
Nov 30, 2026
Merged

huangjeff5 merged 1 commit into
mainfrom
fix/py-mcp-cancel-notification

Conversation

@hilariie

@hilariie hilariie commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

Ported from genkit-ai/genkit#6958. Part of genkit-ai/genkit#6194.

A tool call that times out, or whose caller is cancelled, now sends the server notifications/cancelled for that request, so the server stops working on it. With request_timeout_millis=None, an abandoned call no longer keeps running on the client until the connection closes.

client = define_mcp_client(ai, 'files', command='files-server', request_timeout_millis=5000)
# a tool call that runs past 5s
# before: the caller gets DEADLINE_EXCEEDED, the server keeps running the tool
# after: same error, and the server is sent notifications/cancelled for that request

Changes

  • A timed-out or cancelled call sends notifications/cancelled with its request id. Other calls on the same connection keep running.
  • A cancelled caller also stops its call on the client side, instead of leaving it running until the connection closes.
  • No notice is sent while the connection is closing or broken, for the handshake, or for the liveness probe.

Breaking changes

None.

Fixes #191.

@huangjeff5 huangjeff5 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verified genkit-mcp connection tests locally against the stdio fake server (83 passed). Timed-out and cancelled calls now send notifications/cancelled with the right request id and stop cleanly without disrupting sibling calls or sending spurious cancellations on close(). Looks good!

@huangjeff5
huangjeff5 merged commit dd66a35 into main Nov 30, 2026
21 checks passed
@huangjeff5
huangjeff5 deleted the fix/py-mcp-cancel-notification branch November 30, 2026 21:30
@huangjeff5 huangjeff5 mentioned this pull request Dec 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

mcp: cancelled and timed-out tool calls keep running on the server

2 participants