Skip to content

Example MCP Project does not work with MCP Inspector #14

@cirego

Description

@cirego

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:

  1. Create a new project using the MCPR CLI: mcpr generate-project --name simple-mcp-server
  2. Build the server: cd simple-mcp-server/server && cargo build
  3. Run the MCP Inspector: npx @modelcontextprotocol/inspector ./target/debug/simple-mcp-server-server
  4. Open the Connector in your browser and hit the Connect button.

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": {},
                },
            }),
        );

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions