Skip to content
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

Unpredictable timeout error #15

Open
luiyongsheng opened this issue Mar 9, 2025 · 1 comment
Open

Unpredictable timeout error #15

luiyongsheng opened this issue Mar 9, 2025 · 1 comment

Comments

@luiyongsheng
Copy link

luiyongsheng commented Mar 9, 2025

The error message:

server is running on SSE at http://localhost:8080/sse
node:events:507
    const err = new ERR_UNHANDLED_ERROR(stringifiedEr);
                ^

Error [ERR_UNHANDLED_ERROR]: Unhandled error. ({
  error: Error: Not connected
      at file:///Users/<project-dir>/node_modules/fastmcp/node_modules/@modelcontextprotocol/sdk/dist/esm/shared/protocol.js:221:24
      at new Promise (<anonymous>)
      at Server.request (file:///Users/<project-dir>/node_modules/fastmcp/node_modules/@modelcontextprotocol/sdk/dist/esm/shared/protocol.js:218:16)
      at Server.ping (file:///Users/<project-dir>/node_modules/fastmcp/node_modules/@modelcontextprotocol/sdk/dist/esm/server/index.js:167:21)
      at Timeout._onTimeout (file:///Users/<project-dir>/node_modules/fastmcp/dist/FastMCP.js:262:28)
      at listOnTimeout (node:internal/timers:573:17)
      at process.processTimers (node:internal/timers:514:7)
})
    at FastMCPSession.emit (node:events:507:17)
    at Timeout._onTimeout (file:///Users/<project-dir>/node_modules/fastmcp/dist/FastMCP.js:264:14) {
  code: 'ERR_UNHANDLED_ERROR',
  context: {
    error: Error: Not connected
        at file:///Users/<project-dir>/node_modules/fastmcp/node_modules/@modelcontextprotocol/sdk/dist/esm/shared/protocol.js:221:24
        at new Promise (<anonymous>)
        at Server.request (file:///Users/<project-dir>/node_modules/fastmcp/node_modules/@modelcontextprotocol/sdk/dist/esm/shared/protocol.js:218:16)
        at Server.ping (file:///Users/<project-dir>/node_modules/fastmcp/node_modules/@modelcontextprotocol/sdk/dist/esm/server/index.js:167:21)
        at Timeout._onTimeout (file:///Users/<project-dir>/node_modules/fastmcp/dist/FastMCP.js:262:28)
        at listOnTimeout (node:internal/timers:573:17)
        at process.processTimers (node:internal/timers:514:7)
  }
}

error message when run using bun:

server is running on SSE at http://localhost:8080/sse
[warning] FastMCP could not infer client capabilities
259 |     }
260 |     this.#pingInterval = setInterval(async () => {
261 |       try {
262 |         await this.#server.ping();
263 |       } catch (error) {
264 |         this.emit("error", {
                   ^
error: Unhandled error. ({
  error: McpError: MCP error -32001: Request timed out
      at new McpError (/Users/<project-dir>/node_modules/fastmcp/node_modules/@modelcontextprotocol/sdk/dist/esm/types.js:998:9)
      at timeoutHandler (/Users/<project-dir>/node_modules/fastmcp/node_modules/@modelcontextprotocol/sdk/dist/esm/shared/protocol.js:277:53) {
    code: -32001,
    data: { timeout: 60000 }
  }
})
 context: {
  error: 993 |     CallToolResultSchema,
994 |     ListToolsResultSchema,
995 | ]);
996 | export class McpError extends Error {
997 |     constructor(code, message, data) {
998 |         super(`MCP error ${code}: ${message}`);
              ^
McpError: MCP error -32001: Request timed out
 code: -32001,
 data: [Object ...],

      at new McpError (/Users/<project-dir>/node_modules/fastmcp/node_modules/@modelcontextprotocol/sdk/dist/esm/types.js:998:9)
,
},
    code: "ERR_UNHANDLED_ERROR"

      at emitError (node:events:52:31)
      at <anonymous> (/Users/<project-dir>/node_modules/fastmcp/dist/FastMCP.js:264:14)

Bun v1.2.4 (macOS arm64)

I'm serving the FastMCP server like this:

#!/usr/bin/env node

import { FastMCP } from "fastmcp"

const server = new FastMCP({
  name: "Rokuyo",
  version: "1.0.0",
})

server.addTool({
  // ...
})

async function main() {
  server.start({
    transportType: "sse",
    sse: {
      port: 8080,
      endpoint: "/sse",
    },
  })
}

main().catch((error) => {
  console.error("Server error:", error)
  process.exit(1)
})

The way I write my MCP client and call the MCP server:

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

export const runtime = "nodejs"

export async function GET(req) {
  const transport = new SSEClientTransport(new URL("http://localhost:8080/sse"))
  const client = new Client({
    name: "6ren",
    version: "1.0.0",
  })
  await client.connect(transport)
  const tools = await client.listTools()
  console.log("Tools:", tools)
  return NextResponse.json({ id: 1, ...tools })
}
@punkpeye
Copy link
Owner

punkpeye commented Mar 9, 2025

My best guess is that these timeouts are coming from SDK itself.

https://github.com/search?q=repo%3Amodelcontextprotocol%2Ftypescript-sdk%20fetch&type=code

fetch has some unfortunate timeout defaults.

CC @jspahrsummers

I was just dealing with a related issue in another context.

nodejs/undici#1373

Ended up replacing fetch with undici's fetch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants