Uh oh!
There was an error while loading. Please reload this page.
feat(core): custom-method support (3-arg setRequestHandler + request schema overload) - #1974
Conversation
@modelcontextprotocol/client@modelcontextprotocol/server@modelcontextprotocol/express@modelcontextprotocol/fastify@modelcontextprotocol/hono@modelcontextprotocol/nodecommit: |
🦋 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 |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
5497a22 to
37df126CompareUh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
8f12176 to
e69c6a7Compare37df126 to
c3382ebCompareUh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
KKonstantinov
left a comment
There was a problem hiding this comment.
LGTM, some potential nits, not blocking.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
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
dc09b1dCompare…nstead of ProtocolError(InternalError)
felixweinberger
commented
Apr 29, 2026
@claude review |
…and §5 scenario table
Uh oh!
There was an error while loading. Please reload this page.
…RequestHandler/removeNotificationHandler/assertCanSetRequestHandler
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
…nySchema removed in #1974)
…dardSchemaV1 (post-#1974)
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.