modelcontextprotocol / modelcontextprotocol/typescript-sdk

SSEServerTransport doesn't seem to close properly

Open
#321 9 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

bug fix proposed P2 ready for work
Dominant language
TypeScript
Stars
13.4k
Forks
2.2k
Avg merge
3d 15h
Merged PRs (30d)
4

Description

Describe the bug
While reviewing the source code, I noticed that the close method is never actually called, which means res.end is never triggered:
https://github.com/modelcontextprotocol/typescript-sdk/blob/main/src/server/sse.ts

In multiple places, it seems like onclose is called directly when close should be used instead, to ensure proper cleanup.

To Reproduce
I created a minimal reproduction here:
https://github.com/nichtsam/transport-issue

Steps to reproduce the behavior:

  1. npm run start
  2. npx @modelcontextprotocol/inspector
  3. connect to http://localhost:3001/sse
  4. disconnect

Expected behavior
res.end should be called via the close method to cleanly terminate the SSE connection.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in src/server/sse.ts and trace the SSEServerTransport close and onclose paths, focusing on where res.end should be reached. Run the reproduction with npm run start, then connect and disconnect using the MCP Inspector; done means the SSE response terminates cleanly through close and the observed cleanup matches the expected behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
backend, networking
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
67/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.