Repository navigation
Closed
Labels
documentationImprovements or additions to documentationImprovements or additions to documentation
Description
I have the following server:
import { McpServer, ResourceTemplate } from "@modelcontextprotocol/sdk/server/mcp.js";
import { SSEServerTransport } from "@modelcontextprotocol/sdk/server/sse.js";
import express from "express";
import { z } from "zod";
// Create an Express app
const app = express();
// Create an MCP server
const server = new McpServer({
name: "Demo",
version: "1.0.0"
});
// Add an addition tool
server.tool("add",
{ a: z.number(), b: z.number() },
async ({ a, b }) => ({
content: [{ type: "text", text: String(a + b) }]
})
);
// Add a dynamic greeting resource
server.resource(
"greeting",
new ResourceTemplate("greeting://{name}", { list: undefined }),
async (uri, { name }) => ({
contents: [{
uri: uri.href,
text: `Hello, ${name}!`
}]
})
);
let transport: SSEServerTransport | null = null;
app.get("/sse", (req, res) => {
transport = new SSEServerTransport("/messages", res);
server.connect(transport);
});
app.post("/messages", (req, res) => {
if (transport) {
transport.handlePostMessage(req, res);
}
});
app.listen(3001);Which is an extension of the example server in the Typescript SDK repo.
I run the inspector with npx @modelcontextprotocol/inspector npm start -s src/index.ts and the UI comes up:
On clicking 'connect' I get a connection error in the UI, and on the console I have:
New SSE connection
Query parameters: { transportType: 'sse', url: 'http://localhost:3001/sse' }
SSE transport: url=http://localhost:3001/sse
Error in /sse route: Error: SSE error: {"type":"error","message":""}
at _eventSource.onerror (file:///Users/antontroynikov/.npm/_npx/5a9d879542beca3a/node_modules/@modelcontextprotocol/sdk/dist/esm/client/sse.js:23:31)
at EventSource.emit (node:events:518:28)
at _emit (/Users/antontroynikov/.npm/_npx/5a9d879542beca3a/node_modules/eventsource/lib/eventsource.js:287:17)
at onConnectionClosed (/Users/antontroynikov/.npm/_npx/5a9d879542beca3a/node_modules/eventsource/lib/eventsource.js:58:5)
at ClientRequest.<anonymous> (/Users/antontroynikov/.npm/_npx/5a9d879542beca3a/node_modules/eventsource/lib/eventsource.js:276:7)
at ClientRequest.emit (node:events:518:28)
at emitErrorEvent (node:_http_client:101:11)
at Socket.socketErrorListener (node:_http_client:504:5)
at Socket.emit (node:events:518:28)
at emitErrorNT (node:internal/streams/destroy:169:8)
What am I doing wrong?
Metadata
Metadata
Assignees
Labels
documentationImprovements or additions to documentationImprovements or additions to documentation

Activity
[-]How to connect inspector to a locally developed MCP server using SSE?[/-][+]How to connect inspector to a locally developed TypeScript MCP server using SSE?[/+]jspahrsummers commentedon Jan 22, 2025
With SSE servers, the MCP client (in this case, the inspector) will no longer be responsible for their lifetime, so will not automatically start it up.
It should work to launch the SSE server separately, the connect to it from the inspector. (We should definitely update the README to make this clearer!)
atroyn commentedon Jan 22, 2025
I understand now, thanks! Up and running with SSE.
zhoujingchao commentedon Mar 22, 2025
node version: v20.17.0
@modelcontextprotocol/sdk: 1.7.0
macos: 14.3.1
I have the same problem with the demo code and the same inspector debugging operation, but get different errors log
req.query is {}, is this a bug? source code:
jasonkang14 commentedon Apr 27, 2025
@zhoujingchao did you resolve the error?
chore(deps): bump vite to ^7.3.5 (CVE fixes)
chore(deps): bump vite to ^7.3.5 (CVE fixes) (#1709)