mongodb-js/mongodb-mcp-server

[Clarification] How to generate the session id for the HTTP Transport

Closed this issue · 3 comments

Problem Statement:

I've connected to the MongoDB MCP using the http transport. I get the below error message when I invoke the /mcp endpoint. How do I generate and pass the session id?

{"jsonrpc":"2.0","error":{"code":-32001,"message":"session id is required"}}

When I try to generate a session id and pass it, I get the below error message:

{"jsonrpc":"2.0","error":{"code":-32003,"message":"session not found"}}

It would be helpful if an example can be shared for this

Thanks for opening this issue. The ticket MCP-97 was created for internal tracking.

You can try this test script:

curl -X POST http://localhost:3000/mcp \
  -H "Content-Type: application/json" \
  -H "Accept: application/json, text/event-stream" \
  -d '{
    "jsonrpc": "2.0",
    "id": 1,
    "method": "initialize",
    "params": {
      "protocolVersion": "2024-11-05",
      "capabilities": {},
      "clientInfo": {
        "name": "test-client",
        "version": "1.0.0"
      }
    }
  }'

the post address is follow yours.

Here are the results of my test:

event: message
data: {"result":{"protocolVersion":"2024-11-05","capabilities":{"logging":{},"tools":{"listChanged":true},"resources":{"listChanged":true},"completions":{}},"serverInfo":{"name":"MongoDB MCP Server","version":"0.2.0"}},"jsonrpc":"2.0","id":1}

But I think you can test directly with MCP HOST, for example mcp inspector or Claude host, etc

as @jasonnan1 commented you need to use the initialize method as described in the MCP spec. Server should create it's own session id.