fastmcp: "Server did not connect" error
I tried https://github.com/punkpeye/fastmcp/blob/main/src/examples/addition.ts but changing
server.start({
transportType: "stdio",
});
to
server.start({
transportType: "sse",
sse: {
endpoint: "/ca",
port: 8080,
},
});
then when using npx fastmcp inspect to debug it
I always got below error.
node_modules/fastmcp/dist/FastMCP.js:251
throw new UnexpectedStateError("Server did not connect");
I debugged the source, and found out that error is happened at https://github.com/punkpeye/fastmcp/blob/main/src/FastMCP.ts#L554-L556 and the reason is clientCapabilities is empty, because though https://github.com/punkpeye/fastmcp/blob/main/src/FastMCP.ts#L542-L552 seems to be waiting for https://github.com/modelcontextprotocol/typescript-sdk/blob/main/src/server/index.ts#L246-L261 to execute, after 10 times trying, if _oninitialize is still not invoked, the error happens.
I’m not sure why _oninitialize isn’t invoke quickly enough to prevent the error. But I’m not doing anything special here.
And I also tried original mcp server as below https://github.com/modelcontextprotocol/servers/blob/main/src/everything/sse.ts it just works.
I’m not sure it’s a bug, or I didn’t do it the correct way. I’ll appreciate if you could give me some help.
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Reactions: 4
- Comments: 17 (7 by maintainers)
Since this was causing a lot of confusion, I refactored the code to log warning instead of throwing an error.
https://github.com/punkpeye/fastmcp/releases/tag/v1.18.0
@alexgorbatchev The server is not expected to start without inspector/actual client.
That’s because the initialization phase depends on getting the client capabilities.
So since you are not starting with a client… it cannot.
I have the same problem with my Clever Cloud Documentation MCP server:
or
It seems the problem happens with FastMCP in all versions from 1.8.0, and it works in versions 1.7.0 and lower.
The same problem happens to piapi-mcp-server, and with a simple project using the example in the Quickstarter section.