feat(core): support registerTool/registerResource/registerPrompt in MCP integration#20071
feat(core): support registerTool/registerResource/registerPrompt in MCP integration#20071
Conversation
…CP integration The @modelcontextprotocol/sdk introduced register* methods alongside the legacy tool/resource/prompt API in 1.x, and made them the only option in 2.x. - MCPServerInstance now accepts both old and new method names - validateMcpServerInstance accepts servers with either API set - wrapAllMCPHandlers instruments whichever methods are present - captureHandlerError maps register* names to the same error categories Co-Authored-By: claude-sonnet-4-6 <noreply@anthropic.com>
- Add createMockMcpServerWithRegisterApi() to test utilities - Test validation accepts register*-only servers and rejects invalid ones - Test that registerTool/registerResource/registerPrompt get wrapped - Add registerTool handler to node-express, node-express-v5, tsx-express e2e apps Co-Authored-By: claude-sonnet-4-6 <noreply@anthropic.com>
Semver Impact of This PR🟡 Minor (new features) 📋 Changelog PreviewThis is how your changes will appear in the changelog. New Features ✨
Bug Fixes 🐛
Internal Changes 🔧Core
Other
🤖 This preview updates automatically when you update the PR. |
size-limit report 📦
|
node-overhead report 🧳Note: This is a synthetic benchmark with a minimal express app and does not necessarily reflect the real-world performance impact in an application.
|
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Call echo-register tool in SSE transport tests across node-express, node-express-v5, and tsx-express, verifying that tools/call transactions are recorded for handlers registered via registerTool. Co-Authored-By: claude-sonnet-4-6 <noreply@anthropic.com>
68356d4 to
8984639
Compare
JPeer264
left a comment
There was a problem hiding this comment.
Nice addition. It would be nice if there would be an additional e2e test that has the v2 of the @modelcontextprotocol/sdk as well. Right now we only test against v1

The
@modelcontextprotocol/sdkintroducedregisterTool,registerResource, andregisterPromptas a new API in 1.x, and in 2.x these are the only methods available — the oldtool/resource/promptnames are gone.Before this change, servers using the new API would silently get no instrumentation:
validateMcpServerInstancewould reject them (it only checked for the old names), sowrapMcpServerWithSentrywould return the unwrapped instance. The cloudflare-mcp e2e app already usedregisterTooland was affected by this.Changes
MCPServerInstancetype now includes optionalregisterTool?,registerResource?,registerPrompt?alongside the legacy methods (also made legacy ones optional with@deprecatedtags since 2.x removed them)validateMcpServerInstancenow accepts instances with eithertool+resource+prompt+connectorregisterTool+registerResource+registerPrompt+connectwrapAllMCPHandlersconditionally wraps whichever set of methods exists on the instancecaptureHandlerErrormapsregisterTool→tool_execution,registerResource→resource_execution,registerPrompt→prompt_executionregisterToolhandlers added to the node-express, node-express-v5, and tsx-express e2e appsThe existing
wrapMethodHandlerlogic (intercepts the last argument as the callback) works identically for both old and new signatures, so no changes were needed there.Closes #16666