-
Notifications
You must be signed in to change notification settings - Fork 25
Description
I'm trying to write an MCP server that will work with Zed as an extension. I initially tested using the client that was generated as part of the sample application and that seemed to work. But once I tried using my server with other tools, it failed. As part of debugging this, I tried using the MCP Inspector to test the server that I had written and it gave me connection errors. It looks like the example generated by scaffolding project doesn't work properly.
Steps to reproduce:
- Create a new project using the MCPR CLI:
mcpr generate-project --name simple-mcp-server - Build the server:
cd simple-mcp-server/server && cargo build - Run the MCP Inspector:
npx @modelcontextprotocol/inspector ./target/debug/simple-mcp-server-server - Open the Connector in your browser and hit the
Connectbutton.
Expected result:
The inspector shows a "connected" status and shows the hello tool
Actual result:
The inspector shows a "Connection error" message. Looking in the console logs, I see these two error messages:
index-BK1TrpAN.js:13731 Failed to connect to MCP server: ZodError: [
{
"code": "invalid_type",
"expected": "string",
"received": "undefined",
"path": [
"protocolVersion"
],
"message": "Required"
},
{
"code": "invalid_type",
"expected": "object",
"received": "undefined",
"path": [
"capabilities"
],
"message": "Required"
},
{
"code": "invalid_type",
"expected": "object",
"received": "undefined",
"path": [
"serverInfo"
],
"message": "Required"
}
]
at get error (index-BK1TrpAN.js:7922:23)
at ZodObject.parse (index-BK1TrpAN.js:7998:18)
at index-BK1TrpAN.js:12430:39
at Client._onresponse (index-BK1TrpAN.js:12361:7)
at _transport.onmessage (index-BK1TrpAN.js:12251:14)
at _eventSource.onmessage (index-BK1TrpAN.js:13429:71)
at index-BK1TrpAN.js:12884:119
at dispatchEvent (index-BK1TrpAN.js:12754:24)
at parseLine (index-BK1TrpAN.js:12707:7)
at Object.feed (index-BK1TrpAN.js:12702:7)
connect @ index-BK1TrpAN.js:13731
index-BK1TrpAN.js:13759 ZodError: [
{
"code": "invalid_type",
"expected": "string",
"received": "undefined",
"path": [
"protocolVersion"
],
"message": "Required"
},
{
"code": "invalid_type",
"expected": "object",
"received": "undefined",
"path": [
"capabilities"
],
"message": "Required"
},
{
"code": "invalid_type",
"expected": "object",
"received": "undefined",
"path": [
"serverInfo"
],
"message": "Required"
}
]
at get error (index-BK1TrpAN.js:7922:23)
at ZodObject.parse (index-BK1TrpAN.js:7998:18)
at index-BK1TrpAN.js:12430:39
at Client._onresponse (index-BK1TrpAN.js:12361:7)
at _transport.onmessage (index-BK1TrpAN.js:12251:14)
at _eventSource.onmessage (index-BK1TrpAN.js:13429:71)
at index-BK1TrpAN.js:12884:119
at dispatchEvent (index-BK1TrpAN.js:12754:24)
at parseLine (index-BK1TrpAN.js:12707:7)
at Object.feed (index-BK1TrpAN.js:12702:7)
connect @ index-BK1TrpAN.js:13759
Fixes:
I modified handle_initialize to return the following and now MCP inspector will connect (although tools listing is broken):
let response = mcpr::schema::json_rpc::JSONRPCResponse::new(
id,
serde_json::json!({
"protocolVersion": mcpr::constants::LATEST_PROTOCOL_VERSION,
"serverInfo": {
"name": self.config.name,
"version": self.config.version
},
"capabilities": {
"tools": {},
},
}),
);