Skip to content

feat(core): restore v1 Zod-schema overloads on setRequestHandler/setNotificationHandler/request#1891

Draft
felixweinberger wants to merge 1 commit intomainfrom
fweinberger/protocol-concrete
Draft

feat(core): restore v1 Zod-schema overloads on setRequestHandler/setNotificationHandler/request#1891
felixweinberger wants to merge 1 commit intomainfrom
fweinberger/protocol-concrete

Conversation

@felixweinberger
Copy link
Copy Markdown
Contributor

@felixweinberger felixweinberger commented Apr 14, 2026

Part of the v2 BC series — see reviewer guide.

Restores the v1 calling forms on Protocol (inherited by Client/Server) so v1 code keeps working unchanged:

  • setRequestHandler(ZodSchema, handler) / setNotificationHandler(ZodSchema, handler) — method name read from the schema's method literal
  • request(req, resultSchema, options?) — explicit-result-schema form, plus method-keyed return type for spec methods
  • callTool(params, resultSchema?, options?) — accepts the v1 schema arg (ignored) for source compat
  • removeRequestHandler / removeNotificationHandler / assertCanSetRequestHandler accept any method string

Custom (non-spec) methods work via the Zod-schema form, same as v1. schema.ts/standardSchema.ts are unchanged from main.

The 3-arg validator-agnostic form is split out as #1916. Exporting Protocol + ProtocolSpec is #1917.

Motivation and Context

v1 → v2 backwards compatibility. The largest single source of v2 typecheck breaks across consumer audits was setRequestHandler no longer accepting the Zod-schema form; this restores it as a first-class overload.

How Has This Been Tested?

packages/core/test/shared/customMethods.test.ts — Zod-schema round-trip, invalid-params rejection, removeRequestHandler('any/string'), two-arg spec form, notification() mock-assignability.

Breaking Changes

None — additive.

Types of changes

  • New feature (non-breaking change which adds functionality)

Additional context

#1916 and #1917 stack on this.

@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Apr 14, 2026

🦋 Changeset detected

Latest commit: 0daaa15

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 6 packages
Name Type
@modelcontextprotocol/client Minor
@modelcontextprotocol/server Minor
@modelcontextprotocol/express Major
@modelcontextprotocol/fastify Major
@modelcontextprotocol/hono Major
@modelcontextprotocol/node Major

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

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new bot commented Apr 14, 2026

Open in StackBlitz

@modelcontextprotocol/client

npm i https://pkg.pr.new/@modelcontextprotocol/client@1891

@modelcontextprotocol/server

npm i https://pkg.pr.new/@modelcontextprotocol/server@1891

@modelcontextprotocol/express

npm i https://pkg.pr.new/@modelcontextprotocol/express@1891

@modelcontextprotocol/fastify

npm i https://pkg.pr.new/@modelcontextprotocol/fastify@1891

@modelcontextprotocol/hono

npm i https://pkg.pr.new/@modelcontextprotocol/hono@1891

@modelcontextprotocol/node

npm i https://pkg.pr.new/@modelcontextprotocol/node@1891

commit: 0daaa15

@felixweinberger felixweinberger force-pushed the fweinberger/protocol-concrete branch from db49955 to 070a9cd Compare April 15, 2026 19:38
@felixweinberger felixweinberger added the v2-bc v2 backwards-compatibility series label Apr 15, 2026
@felixweinberger felixweinberger changed the title feat(core): make Protocol concrete and exported (alternative to #1846) feat(core): concrete Protocol with custom-method overloads + deprecated v1 schema-arg shims Apr 15, 2026
@felixweinberger felixweinberger added this to the v2.0.0-bc milestone Apr 15, 2026
@felixweinberger felixweinberger force-pushed the fweinberger/protocol-concrete branch from 070a9cd to 54c7b21 Compare April 16, 2026 09:35
@felixweinberger felixweinberger force-pushed the fweinberger/protocol-concrete branch 3 times, most recently from 31f4544 to fec9cce Compare April 16, 2026 14:01
@felixweinberger felixweinberger changed the title feat(core): concrete Protocol with custom-method overloads + deprecated v1 schema-arg shims feat(core): custom-method overloads + deprecated v1 schema-arg shims + ProtocolSpec generic Apr 16, 2026
@felixweinberger felixweinberger force-pushed the fweinberger/protocol-concrete branch 7 times, most recently from f573eb9 to f20ca3b Compare April 16, 2026 18:11
@felixweinberger felixweinberger changed the title feat(core): custom-method overloads + deprecated v1 schema-arg shims + ProtocolSpec generic feat(core): restore v1 Zod-schema overloads on setRequestHandler/setNotificationHandler/request Apr 16, 2026
…otificationHandler/request

Adds to Protocol (inherited by Client/Server):
- setRequestHandler/setNotificationHandler(ZodSchema, handler) — the v1 form, first-class
- request(req, resultSchema, opts?) — the v1 explicit-schema form, first-class
- callTool(params, resultSchema?, opts?) — accepts the v1 schema arg (ignored) for source compat
- removeRequestHandler/removeNotificationHandler/assertCanSetRequestHandler accept any method string

Custom (non-spec) methods work via the Zod-schema form, same as v1.
schema.ts/standardSchema.ts unchanged from main.
@felixweinberger felixweinberger force-pushed the fweinberger/protocol-concrete branch from f20ca3b to 0daaa15 Compare April 16, 2026 18:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

v2-bc v2 backwards-compatibility series

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant