Skip to content

fix: add | undefined to transport option callbacks for exactOptionalPropertyTypes#1855

Open
Christian-Sidak wants to merge 1 commit intomodelcontextprotocol:mainfrom
Christian-Sidak:fix/session-id-generator-undefined-type
Open

fix: add | undefined to transport option callbacks for exactOptionalPropertyTypes#1855
Christian-Sidak wants to merge 1 commit intomodelcontextprotocol:mainfrom
Christian-Sidak:fix/session-id-generator-undefined-type

Conversation

@Christian-Sidak
Copy link
Copy Markdown

Summary

Adds | undefined to optional callback type properties in WebStandardStreamableHTTPServerTransportOptions to support TypeScript projects using exactOptionalPropertyTypes: true.

Fixes #1397

Changes

WebStandardStreamableHTTPServerTransportOptions (packages/server/src/server/streamableHttp.ts):

  • sessionIdGenerator?: (() => string) | undefined
  • onsessioninitialized?: ((sessionId: string) => void | Promise<void>) | undefined
  • onsessionclosed?: ((sessionId: string) => void | Promise<void>) | undefined

Corresponding private fields on the class and the test helper interface are updated to match.

Why

Without this fix, users with exactOptionalPropertyTypes: true get:

error TS2379: Argument of type '{ sessionIdGenerator: undefined; enableJsonResponse: true; }'
is not assignable to parameter of type 'WebStandardStreamableHTTPServerTransportOptions' with
'exactOptionalPropertyTypes: true'.
  Types of property 'sessionIdGenerator' are incompatible.
    Type 'undefined' is not assignable to type '() => string'.

This is the standard TypeScript pattern for exactOptionalPropertyTypes compatibility. The Transport interface in @modelcontextprotocol/core already follows this pattern -- this PR brings the server transport options in line.

Testing

  • tsc --noEmit passes for both packages/core and packages/server
  • No behavioral changes -- purely a type-level fix

…ertyTypes support

Optional properties sessionIdGenerator, onsessioninitialized, and onsessionclosed
in WebStandardStreamableHTTPServerTransportOptions need the | undefined union to
support TypeScript projects with exactOptionalPropertyTypes: true.

Fixes modelcontextprotocol#1397
@Christian-Sidak Christian-Sidak requested a review from a team as a code owner April 6, 2026 04:05
@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Apr 6, 2026

⚠️ No Changeset found

Latest commit: 4cbeade

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
Copy Markdown

pkg-pr-new bot commented Apr 6, 2026

Open in StackBlitz

@modelcontextprotocol/client

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

@modelcontextprotocol/server

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

@modelcontextprotocol/express

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

@modelcontextprotocol/fastify

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

@modelcontextprotocol/hono

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

@modelcontextprotocol/node

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

commit: 4cbeade

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.

bug: invalid types for sessionIdGenerator in 1.25.2

1 participant