Skip to content

Conversation

@bkarakaya01
Copy link

@bkarakaya01 bkarakaya01 commented Nov 7, 2025

This PR introduces server-side tool timeout support and ensures proper JSON-RPC $/cancelRequest handling.

Summary of Changes

  • Added DefaultToolTimeout to McpServerOptions
  • Added IMcpToolWithTimeout interface for per-tool override
  • Enforced tool execution timeout inside the tools/call pipeline via linked CTS
  • Added NotificationMethods.JsonRpcCancelRequest constant
  • Introduced SlowTool fixture for timeout scenarios
  • Added tests covering:
    • per-tool timeout
    • default server timeout
    • client-initiated $/cancelRequest cancellation path
  • Normalized English summaries / comments

Fixes #922

Motivation and Context

Timeout control at the server/tool level is required for predictable behavior when dealing with long-running tool executions.
$/cancelRequest handling complements this by ensuring JSON-RPC cancellation semantics correctly surface to the caller.

How Has This Been Tested?

All new behavior is covered via unit tests under McpServerToolTimeoutTests using TestServerTransport.

Breaking Changes

No breaking changes. Existing server implementations continue to work without modification.

Types of Changes

  • New feature (non-breaking enhancement)
  • Bug fix
  • Breaking change
  • Documentation update

Checklist

  • I have read the MCP documentation
  • My code follows the repository style guidelines
  • All tests pass locally
  • I have added tests to cover the new behavior

Additional Context

N/A

…lation

This introduces support for parsing and honoring JSON-RPC \$/cancelRequest\
notifications, making cancellation semantics compliant with MCP protocol
expectations. Includes a new \JsonRpcCancelRequest\ constant in
\NotificationMethods\ and integrates proper cancellation token linkage inside
the server message loop.

Additionally:
- Added SlowTool test fixture to simulate long-running tools
- Implemented full timeout vs external cancellation tests
- Normalized English summaries / comments in related areas

Fixes modelcontextprotocol#922
@stephentoub
Copy link
Contributor

Support JSON-RPC $/cancelRequest cancellation

I'm not understanding the purpose of this. Cancellation is already supported with notifications/cancelled

@stephentoub stephentoub added the NO MERGE PR should not be merged until the label is removed label Nov 7, 2025
@bkarakaya01 bkarakaya01 changed the title Support JSON-RPC $/cancelRequest cancellation in server + tests (#922) Add server tool timeouts (default & per-tool) and honor JSON-RPC $/cancelRequest (#922) Nov 7, 2025
@bkarakaya01
Copy link
Author

Support JSON-RPC $/cancelRequest cancellation

I'm not understanding the purpose of this. Cancellation is already supported with notifications/cancelled

I see how my original wording made this look like a cancellation feature PR. The actual primary goal here is server-side tool timeout support. The $ /cancelRequest part was only added because during implementation/tests we noticed cancellation didn’t properly propagate to the running tool without the CTS linkage, so it was more of a supporting fix, not the main feature.

I’ve updated the PR title/description to reflect the real scope (tool timeout) much clearer. Thanks for pointing it out!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

NO MERGE PR should not be merged until the label is removed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

McpServerTool Add timeout

2 participants