feat(core): concrete Protocol with custom-method overloads + deprecated v1 schema-arg shims#1891
Draft
felixweinberger wants to merge 5 commits intomainfrom
Draft
feat(core): concrete Protocol with custom-method overloads + deprecated v1 schema-arg shims#1891felixweinberger wants to merge 5 commits intomainfrom
felixweinberger wants to merge 5 commits intomainfrom
Conversation
🦋 Changeset detectedLatest commit: 070a9cd 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 |
@modelcontextprotocol/client
@modelcontextprotocol/server
@modelcontextprotocol/express
@modelcontextprotocol/fastify
@modelcontextprotocol/hono
@modelcontextprotocol/node
commit: |
This was referenced Apr 15, 2026
…erloads - Protocol becomes concrete: 5 assert*Capability abstracts → no-op virtuals, buildContext → virtual with default. Client/Server override to enforce. - setRequestHandler/setNotificationHandler gain a 3-arg (method: string, paramsSchema, handler) overload alongside the existing 2-arg spec-typed form. One method, any method name. - request() gains string-form (method, params, resultSchema) overload for custom methods (object-form already returns method-keyed ResultTypeMap[M]). - notification() gains (method, params, paramsSchema?) overload. - removeRequestHandler/removeNotificationHandler accept string. - isRequestMethod/isNotificationMethod predicates added. - Protocol and mergeCapabilities exported from public surface. Enables vendor-prefixed extension methods (which the MCP spec permits) without a separate setCustom* API.
…ient (C3/C6 in core) - setRequestHandler/setNotificationHandler: accept Zod schema (extracts method literal, warns once) - request(): accept (req, ResultSchema, opts?) deprecated form (schema ignored) - callTool(): accept (params, ResultSchema, opts?) deprecated form - sendNotification(): non-overloaded alias for notification() (test-mock friendly) - Export AnySchema/SchemaOutput/ZodLikeRequestSchema from core/public
…m() for string-form custom methods
notification() reverts to a single (Notification, opts?) signature so test
code can do client.notification = mockFn without TS rejecting the mock for
not matching the intersection of all overloads (the fastmcp regression).
The typed string-form sender moves to a new notifyCustom(method, params,
{paramsSchema?}). Removes the sendNotification() workaround alias.
db49955 to
070a9cd
Compare
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.
Part of the v2 backwards-compatibility series — see reviewer guide.
Makes
Protocolconcrete and exported; adds 3-argsetRequestHandler(method, paramsSchema, handler)overload for custom (non-spec) methods; method-keyedrequest()return type; restores@deprecatedv1 schema-argument overloads; addsnotifyCustom()sonotification()stays single-signature (mock-assignable).Motivation and Context
v2's
setRequestHandler<M extends RequestMethod>is a closed union — custom (vendor-prefixed) methods crash at runtime. This restores extensibility via a 3-arg overload, makesrequest()method-keyed sorequest({method:'tools/list'})returnsListToolsResult, and brings backsetRequestHandler(ZodSchema, h)as a@deprecatedoverload so v1 code keeps compiling.v1 vs v2 patterns
v1:
v2-native:
How Has This Been Tested?
customMethods.test.ts,protocol.compat.test.ts— 3-arg overload, schema-arg dispatch, mock-assignment,notifyCustomvalidationv2-bc-integrationvalidation branchpnpm typecheck:all && pnpm lint:all && pnpm test:allgreen (core 507/507)Breaking Changes
None vs current main — additive. Supersedes the closed #1846/#1868 approach.
Types of changes
Checklist
Additional context
Stacks on: C1 (
deprecate()helper). This is the largest PR in the series (~+1000 LOC) — could split into "concrete Protocol + overloads" / "deprecated schema-arg shims" if preferred, but they touch the sameprotocol.ts.