Skip to content

Conversation

@felixweinberger
Copy link
Contributor

Removes the generic type parameters <RequestT, NotificationT, ResultT> from Server, Client, and Protocol (as <SendRequestT, SendNotificationT, SendResultT>).

Motivation and Context

After #1446 switched setRequestHandler to string method names from a closed set, these generics no longer serve any purpose. They were originally needed to support custom/arbitrary method schemas, which is no longer possible.

No other official SDK (Python, Go, C#) supports custom method generics, and the protocol spec defines a closed set of methods.

Changes

  • Remove <SendRequestT, SendNotificationT, SendResultT> from Protocol class
  • Remove <RequestT, NotificationT, ResultT> from Server and Client classes
  • Remove generics from RequestHandlerExtra type (hardcode to base Request/Notification)
  • Remove generics from ExperimentalServerTasks and ExperimentalClientTasks
  • Remove 4 @ts-expect-error comments that existed solely to work around the generic constraints
  • Remove multiple as unknown as SendResultT / as SendNotificationT casts
  • Remove old JSDoc examples showing custom generic usage
  • Clean up unused imports (ServerRequest, ServerNotification, Request, Notification, Result)

Net -103 lines.

How Has This Been Tested?

  • pnpm typecheck:all — zero errors
  • pnpm test:all — all tests pass (1 pre-existing failure in authExtensions unrelated)
  • pnpm lint:all — clean

Breaking Changes

  • Server<CustomRequest, CustomNotification, CustomResult> pattern is no longer supported. Server is already deprecated in favor of McpServer.
  • Client<CustomRequest, CustomNotification, CustomResult> — same.
  • RequestHandlerExtra is no longer generic. Code using RequestHandlerExtra<ServerRequest, ServerNotification> should use plain RequestHandlerExtra.

Types of changes

  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist

  • I have read the MCP Documentation
  • My code follows the repository's style guidelines
  • New and existing tests pass locally
  • I have added appropriate error handling
  • I have added or updated documentation as needed

Additional context

This stacks on top of #1446. The RequestTypeMap[M] from that PR actually provides better per-method type safety than the old generics, which defaulted to base types and were routinely bypassed with @ts-expect-error.

@changeset-bot
Copy link

changeset-bot bot commented Feb 2, 2026

⚠️ No Changeset found

Latest commit: 011d185

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@pkg-pr-new
Copy link

pkg-pr-new bot commented Feb 2, 2026

Open in StackBlitz

@modelcontextprotocol/client

npm i https://pkg.pr.new/modelcontextprotocol/typescript-sdk/@modelcontextprotocol/client@1451

@modelcontextprotocol/server

npm i https://pkg.pr.new/modelcontextprotocol/typescript-sdk/@modelcontextprotocol/server@1451

@modelcontextprotocol/express

npm i https://pkg.pr.new/modelcontextprotocol/typescript-sdk/@modelcontextprotocol/express@1451

@modelcontextprotocol/hono

npm i https://pkg.pr.new/modelcontextprotocol/typescript-sdk/@modelcontextprotocol/hono@1451

@modelcontextprotocol/node

npm i https://pkg.pr.new/modelcontextprotocol/typescript-sdk/@modelcontextprotocol/node@1451

commit: 011d185

Base automatically changed from feat/set-request-handler to main February 2, 2026 23:57
…ver, and Client

After the string-based setRequestHandler API (PR #1446), the generic type
parameters <RequestT, NotificationT, ResultT> on Server/Client and
<SendRequestT, SendNotificationT, SendResultT> on Protocol no longer
serve any purpose since custom methods cannot be registered.

This removes them entirely, simplifying:
- Protocol class declaration and all methods
- RequestHandlerExtra type (no longer generic)
- Server and Client class declarations
- ExperimentalServerTasks and ExperimentalClientTasks
- 4 @ts-expect-error comments that were needed to work around the generics

Net -103 lines of type complexity.
@felixweinberger felixweinberger force-pushed the fweinberger/remove-custom-method-generics branch from cf4db2b to b504ef6 Compare February 3, 2026 09:46
@felixweinberger felixweinberger changed the title refactor: remove vestigial generic type parameters from Protocol, Server, and Client [RFC] refactor: remove vestigial generic type parameters from Protocol, Server, and Client Feb 3, 2026
@felixweinberger felixweinberger marked this pull request as ready for review February 3, 2026 10:01
@felixweinberger felixweinberger requested a review from a team as a code owner February 3, 2026 10:01
…etRequestHandler

Adds a ResultTypeMap that maps each method string to its specific result type,
matching the existing RequestTypeMap pattern. This gives handlers correct return
type inference per method, eliminating the need for explicit return type
annotations and 'as const' assertions on literal values.
@felixweinberger felixweinberger marked this pull request as draft February 3, 2026 11:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants