Skip to content

fix: allow transport restart after close()#1647

Open
matantsach wants to merge 1 commit intomodelcontextprotocol:mainfrom
matantsach:fix/1641-transport-restart-after-close
Open

fix: allow transport restart after close()#1647
matantsach wants to merge 1 commit intomodelcontextprotocol:mainfrom
matantsach:fix/1641-transport-restart-after-close

Conversation

@matantsach
Copy link

Summary

Fixes #1641. StreamableHTTPClientTransport and SSEClientTransport cannot be restarted after close() because internal guard variables are not reset to undefined.

Changes

  • StreamableHTTPClientTransport.close(): Reset _abortController to undefined after aborting, so start() can create a fresh controller
  • SSEClientTransport.close(): Reset _abortController, _eventSource, and _endpoint to undefined — clears both start guards and avoids stale endpoint URLs on restart

Testing

  • Added lifecycle test for StreamableHTTPClientTransport: start → close → start → send → verify functional
  • Added lifecycle test for SSEClientTransport: start → close → start → send → verify functional
  • All existing tests pass (pnpm test:all, pnpm check:all)

close() aborts _abortController but never resets it to undefined, so
start() sees a truthy guard and throws "already started." Same issue in
SSEClientTransport with _eventSource. Also reset _endpoint in SSE to
avoid stale endpoint URLs after restart.

Fixes modelcontextprotocol#1641

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@matantsach matantsach requested a review from a team as a code owner March 9, 2026 10:25
@changeset-bot
Copy link

changeset-bot bot commented Mar 9, 2026

⚠️ No Changeset found

Latest commit: 4ee8087

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 Mar 9, 2026

Open in StackBlitz

@modelcontextprotocol/client

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

@modelcontextprotocol/server

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

@modelcontextprotocol/express

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

@modelcontextprotocol/hono

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

@modelcontextprotocol/node

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

commit: 616b9ae

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.

StreamableHTTPClientTransport cannot be restarted after close() — breaks OAuth re-authentication

1 participant