Skip to content

Server panic on initialize message with no params #269

@fmcato

Description

@fmcato

Describe the bug
Got a panic sending an incomplete initialization message against an http streaming server

To Reproduce
Steps to reproduce the behavior:

curl http://localhost:8080/mcp -H "Content-Type: application/json" -H "Accept: text/event-stream, application/json" -d '{
      "jsonrpc": "2.0",
      "method": "initialize"
  }'

Expected behavior
400 Error with explanation about missing data

Logs

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x20 pc=0x6ba9f4]

goroutine 3 [running]:
github.com/modelcontextprotocol/go-sdk/mcp.(*ServerSession).initialize(0xc0000f28c0, {0x0?, 0x0?}, 0x0)
	/home/redacted/go/pkg/mod/github.com/modelcontextprotocol/go-sdk@v0.2.0/mcp/server.go:681 +0xf4
github.com/modelcontextprotocol/go-sdk/mcp.init.sessionMethod[...].func41(0xc0000a0b60?, 0xa?)
	/home/redacted/go/pkg/mod/github.com/modelcontextprotocol/go-sdk@v0.2.0/mcp/shared.go:218 +0x30
github.com/modelcontextprotocol/go-sdk/mcp.init.newMethodInfo[...].func43(0xc0000a0b60?, {0xa?, 0x900000000000000?}, {0x0?, 0x0?})
	/home/redacted/go/pkg/mod/github.com/modelcontextprotocol/go-sdk@v0.2.0/mcp/shared.go:185 +0x6f
github.com/modelcontextprotocol/go-sdk/mcp.defaultReceivingMethodHandler[...]({0x869de0, 0xc000012030}, 0xc0000f28c0, {0xc0000a0b60, 0xa}, {0x0, 0x0})
	/home/redacted/go/pkg/mod/github.com/modelcontextprotocol/go-sdk@v0.2.0/mcp/shared.go:122 +0xab
github.com/modelcontextprotocol/go-sdk/mcp.handleReceive[...]({0x869de0, 0xc000012030}, 0xc0000f28c0, 0xc0000b5300)
	/home/redacted/go/pkg/mod/github.com/modelcontextprotocol/go-sdk@v0.2.0/mcp/shared.go:137 +0x18e
github.com/modelcontextprotocol/go-sdk/mcp.(*ServerSession).handle(0xc0000f28c0, {0x869e18, 0xc000282000}, 0xc0000b5300)
	/home/redacted/go/pkg/mod/github.com/modelcontextprotocol/go-sdk@v0.2.0/mcp/server.go:660 +0x157
github.com/modelcontextprotocol/go-sdk/internal/jsonrpc2.HandlerFunc.Handle(0xc000129110?, {0x869e18?, 0xc000282000?}, 0x0?)
	/home/redacted/go/pkg/mod/github.com/modelcontextprotocol/go-sdk@v0.2.0/internal/jsonrpc2/jsonrpc2.go:91 +0x29
github.com/modelcontextprotocol/go-sdk/internal/jsonrpc2.(*Connection).handleAsync(0xc000129110)
	/home/redacted/go/pkg/mod/github.com/modelcontextprotocol/go-sdk@v0.2.0/internal/jsonrpc2/conn.go:661 +0x105
created by github.com/modelcontextprotocol/go-sdk/internal/jsonrpc2.(*Connection).acceptRequest.func2 in goroutine 23
	/home/redacted/go/pkg/mod/github.com/modelcontextprotocol/go-sdk@v0.2.0/internal/jsonrpc2/conn.go:624 +0x13f

Additional context

Haven't tried with stdio but expecting the same to happen.

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions