modelcontextprotocol / modelcontextprotocol/typescript-sdk
SSE stream disconnected: TypeError: terminated
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 13.4k
- Forks
- 2.2k
- Avg merge
- 3d 15h
- Merged PRs (30d)
- 4
Description
I got an error "SSE stream disconnected: TypeError: terminated" every 5 minutes with the server connection on the cline or cursor, does anyone know why?
ts code:
`import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
import { StreamableHTTPServerTransport } from '@modelcontextprotocol/sdk/server/streamableHttp.js';
import express from 'express';
import * as z from 'zod/v4';
const app = express();
app.use(express.json());
// Create the MCP server once (can be reused across requests)
const server = new McpServer({
name: 'example-server',
version: '1.0.0'
});
// Set up your tools, resources, and prompts
server.registerTool(
'echo',
{
title: 'Echo',
description: 'echo',
inputSchema: { name: z.string() },
},
async ({ name }) => {
return { content: [{ type: 'text', text: `Hello ${name}` }] };
}
);
app.post('/mcp', async (req, res) => {
try {
const transport = new StreamableHTTPServerTransport({
sessionIdGenerator: undefined,
enableJsonResponse: true
});
res.on('close', () => {
transport.close();
});
await server.connect(transport);
await transport.handleRequest(req, res, req.body);
} catch (error) {
console.error('Error handling MCP request:', error);
if (!res.headersSent) {
res.status(500).json({
jsonrpc: '2.0',
error: {
code: -32603,
message: 'Internal server error'
},
id: null
});
}
}
});
// Reusable handler for GET and DELETE requests
const handleSessionRequest = async (req: express.Request, res: express.Response) => {
const transport = new StreamableHTTPServerTransport({
sessionIdGenerator: undefined,
enableJsonResponse: true
});
await transport.handleRequest(req, res);
};
// Handle GET requests for server-to-client notifications via SSE
app.get('/mcp', handleSessionRequest);
const port = parseInt(process.env.PORT || '3000');
app.listen(port, () => {
console.log(MCP Server running on http://localhost:${port}/mcp);
}).on('error', error => {
console.error('Server error:', error);
process.exit(1);
});
mcp setting:"demo": {
"disabled": false,
"timeout": 1800,
"type": "streamableHttp",
"url": "http://localhost:3000/mcp"
}`
cline version 3.38.3
cursor version 1.4.3
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the reported disconnect with the provided Express /mcp handlers and the StreamableHTTPServerTransport setup. Inspect how the POST and GET handlers manage the transport and compare the behavior with the Cline and Cursor configurations; done means identifying the cause of the five-minute termination and documenting a verified resolution.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- express, typescript
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Needs clarification
- Newbie friendliness
- 38/100