Description
Describe the bug
When I start Claude desktop, it perhaps connects the first time to the code below, but then all subsequent restarts fail until I reboot (or, seemingly, leave it overnight). I'm on the latest of everything, including macOS - I started trying out the code just yesterday.
To Reproduce
import {
McpServer,
ResourceTemplate,
} from "@modelcontextprotocol/sdk/server/mcp.js";
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
import { z } from "zod";
// 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) }],
}));
// Start receiving messages on stdin and sending messages on stdout
const transport = new StdioServerTransport();
console.error("[*] Server started");
await server.connect(transport);
console.error("[**] Server connect over");
What I see in the logs is that [**] Server connect over
is immediately reached, which I think means execution has completed
Expected behavior
I expect to be able to find my mcp here - that has happened once but as soon as a I restart Claude (after editing the code for example) then it is no longer visible (even if the edit is reverted or just a comment etc)
Interestingly, the mcp inspector seems to be ale to run the code reliably
npx @modelcontextprotocol/inspector node src/index.js
Logs
Here are the full logs
[simon] [info] Initializing server...
[simon] [info] Server started and connected successfully
[simon] [info] Message from client: {"method":"initialize","params":{"protocolVersion":"2024-11-05","capabilities":{},"clientInfo":{"name":"claude-ai","version":"0.1.0"}},"jsonrpc":"2.0","id":0}
[*] Server started
[**] Server connect over
[simon] [info] Message from client: {"jsonrpc":"2.0","method":"notifications/cancelled","params":{"requestId":0,"reason":"Error: MCP error -32001: Request timed out"}}
[simon] [info] Client transport closed
[simon] [info] Server transport closed
[simon] [info] Client transport closed
[simon] [info] Server transport closed unexpectedly, this is likely due to the process exiting early. If you are developing this MCP server you can add output to stderr (i.e. `console.error('...')` in JavaScript, `print('...', file=sys.stderr)` in python) and it will appear in this log.
[simon] [error] Server disconnected. For troubleshooting guidance, please visit our [debugging documentation](https://modelcontextprotocol.io/docs/tools/debugging) {"context":"connection"}
[simon] [info] Server transport closed
[simon] [info] Client transport closed
Additional context
Add any other context about the problem here.