fix: add explicit | undefined to Transport optional properties (v1.x backport of #1766) - #2814
Open
kishormorol wants to merge 2 commits into
Conversation
Under `exactOptionalPropertyTypes: true`, `onclose?: () => void` means the property may be absent but never explicitly `undefined`. The concrete transports declare these members as accessors typed `(() => void) | undefined`, so the SDK's own transports are not assignable to the SDK's own `Transport` interface and `server.connect(new StreamableHTTPServerTransport(...))` fails with TS2379. Consumers currently have to cast at the call site or turn the flag off for their whole project. Backport of modelcontextprotocol#1766, already merged on main. Fixes modelcontextprotocol#2083 for the v1 line.
🦋 Changeset detectedLatest commit: 2450dfe The changes in this PR will be included in the next version bump. 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 |
commit: |
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.
Backport of #1766 to the
v1.xline. Fixes #2083 for v1.Problem
Under
exactOptionalPropertyTypes: true,onclose?: () => voidmeans the property may be absent, but never explicitlyundefined. The concrete transports declare these members as accessors typed(() => void) | undefined, so the SDK's own transports are not assignable to the SDK's ownTransportinterface:Reproduce with
strict+exactOptionalPropertyTypes: true, thenserver.connect(new StreamableHTTPServerTransport({ sessionIdGenerator: () => randomUUID() })).Consumers currently have to cast at the call site or disable the flag for their whole project.
Change
Four optional members of
Transportgain an explicit| undefined:Source-compatible for every existing consumer: it only permits an explicit
undefinedthat the interface previously rejected. This is the same change already accepted onmainin #1766, which has not reachedv1.x— so 1.30.0 still ships the issue.Verification
npm run typecheckcleannpm test— 1647 tests across 52 files, all passingexactOptionalPropertyTypes: falsebecause of this, turned the flag back on, and typechecked cleanpatch, matching fix(core): add explicit | undefined to Transport interface optional properties #1766Happy to adjust or close if a v1 patch release isn't planned — filing it because #2083 notes a backport is what's needed.