feat(core): custom-method support (3-arg setRequestHandler + request schema overload)#1974
Merged
Merged
Conversation
@modelcontextprotocol/client
@modelcontextprotocol/server
@modelcontextprotocol/express
@modelcontextprotocol/fastify
@modelcontextprotocol/hono
@modelcontextprotocol/node
commit: |
🦋 Changeset detectedLatest commit: 5568303 The changes in this PR will be included in the next version bump. This PR includes changesets to release 7 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
This was referenced Apr 28, 2026
5497a22 to
37df126
Compare
8f12176 to
e69c6a7
Compare
37df126 to
c3382eb
Compare
KKonstantinov
left a comment
Contributor
There was a problem hiding this comment.
LGTM, some potential nits, not blocking.
KKonstantinov
previously approved these changes
Apr 29, 2026
The base branch was changed.
…t()/mcpReq.send schema overloads for custom methods
…ation as 2nd arg; export StandardSchemaV1; fix example headers
…g for discoverability (KKonstantinov)
…ce during async result validation); add core to changeset; setNotificationHandler JSDoc notes 2nd arg
ab1115e to
dc09b1d
Compare
…nstead of ProtocolError(InternalError)
Contributor
Author
|
@claude review |
…and §5 scenario table
…RequestHandler/removeNotificationHandler/assertCanSetRequestHandler
KKonstantinov
approved these changes
Apr 29, 2026
felixweinberger
added a commit
that referenced
this pull request
Apr 29, 2026
…nySchema removed in #1974)
felixweinberger
added a commit
that referenced
this pull request
Apr 29, 2026
…dardSchemaV1 (post-#1974)
This was referenced Apr 29, 2026
This was referenced May 12, 2026
This was referenced May 14, 2026
This was referenced Jun 21, 2026
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.
Custom (non-spec) method support: typed registration and sending. Replaces the #1891 / #1916 / #1917 chain with a single overload-based design.
Protocolstays private (dispatcher RFC handles framework subclassing).setRequestHandler/setNotificationHandlergain a 3-arg form:(method, { params, result? }, handler).paramsis any Standard Schema; the handler receives the parsed params object._metais stripped before validation (available asctx.mcpReq._meta). Supplyingresulttypes the handler's return value.request()andctx.mcpReq.sendgain a(req, resultSchema)overload for typed custom-method results.Spec-method calls are unchanged (2-arg
setRequestHandler, 1-argrequest()). 2 overloads each onsetRequestHandler/setNotificationHandler/request.Motivation and Context
v2-main's
setRequestHandler/request()only accept the closedRequestMethod/NotificationMethodunions, so vendor-prefixed methods (which the spec permits) cannot be registered or sent. The #1891/#1916/#1917 stack solved this with both v1-compat ZodSchema overloads and aProtocolSpec<SpecT>typed-vocabulary mechanism; this PR is the minimal cut: one new overload per method. See discussion on #1891.How Has This Been Tested?
packages/core/test/shared/customMethods.test.ts(9 tests): 3-arg registration, params validation,_metastrip, typed return viaresult,request()schema overload,mcpReq.sendschema overload. typecheck/lint/build/docs/test:all clean locally.Breaking Changes
None to v2-main. v1's
setRequestHandler(ZodSchema, h)form is not restored here; it is mechanically codemod-able to the 3-arg form (#1950).Types of changes
Checklist
Additional context
Alternative to #1891 / #1916 / #1917 (which stay open for comparison). Internally widens
_requestWithSchemaand the TaskManager send-chain from Zod-onlyAnySchematoStandardSchemaV1; Zod schemas implementStandardSchemaV1so existing internal callers are unchanged.Protocolis intentionally not exported in this PR. A separate dispatcher RFC (gist) covers the framework-subclassing use case; until that lands,Protocolstays internal-only.Includes a
_wrapHandlerprotected hook so subclass per-method validation (tools/callinServer,elicitation/create/sampling/createMessageinClient) does not require redeclaringsetRequestHandler's overload set. The hook runs for both registration paths; validation behavior is unchanged.