Skip to content

SSEServerTransport doesn't seem to close properly #321

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
nichtsam opened this issue Apr 12, 2025 · 4 comments
Open

SSEServerTransport doesn't seem to close properly #321

nichtsam opened this issue Apr 12, 2025 · 4 comments
Labels
bug Something isn't working

Comments

@nichtsam
Copy link

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.

@nichtsam nichtsam added the bug Something isn't working label Apr 12, 2025
@reustle
Copy link

reustle commented Apr 19, 2025

Would you mind please adding some of the symptoms you noticed because of this issue? I'm trying to debug some issues on an MCP server and suspect it could be related to something like this. Thanks!

@nichtsam
Copy link
Author

Would you mind please adding some of the symptoms you noticed because of this issue? I'm trying to debug some issues on an MCP server and suspect it could be related to something like this. Thanks!

The core issue is that these responses never properly close, so they occupy memory until timeout. This can build up and create memory pressure. Not sure if there's any obvious symptoms.

@TranquilMarmot
Copy link

Running into this as well.

import { Client } from "@modelcontextprotocol/sdk/client/index.js";
import { SSEClientTransport } from "@modelcontextprotocol/sdk/client/sse.js";

const client = new Client(
  {
    name: "mcp-typescript-client",
    version: "1.0.0",
  },
  {
    capabilities: {},
  }
);

const transport = new SSEClientTransport(
  new URL(
    ".../sse"
  )
);

async function main() {
   await client.connect(transport);

   // ... do stuff with client

  // these don't seem to do anything - the connection stays open indefinitely
  await client.transport?.close();
  await client.close();
}

main();

@nichtsam
Copy link
Author

Running into this as well.

It could be two things, one is that the transport itself doesn't close properly,
the other one is that onclose gets overwritten by protocol class.

You're using the client part so I'm not sure if it's the same, but I'm guessing it is.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants