mcp: fix broken client root capabilities (#698)

To address #607, add ClientCapabilities.RootsV2, and populate it when
constructing sending and receiving InitializeParams.

Fixes #607
This commit is contained in:
Robert Findley 2025-12-11 10:16:56 -05:00 • committed by GitHub
commit a5e369ed12
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 288 additions and 57 deletions

View file

@ -30,3 +30,9 @@ v2.
- `AudioContent.MarshalJSON` should have had a pointer receiver, to be
consistent with other content types.
- `ClientCapabilities.Roots` should have been a distinguished struct pointer
([see #607](https://github.com/modelcontextprotocol/go-sdk/issues/607)).
**Workaround**: use `ClientCapabilities.RootsV2`, which aligns with the
semantics of other capability fields.

View file

@ -51,7 +51,7 @@ func ExampleLoggingTransport() {
// Output:
// read: {"jsonrpc":"2.0","id":1,"result":{"capabilities":{"logging":{}},"protocolVersion":"2025-06-18","serverInfo":{"name":"server","version":"v0.0.1"}}}
// write: {"jsonrpc":"2.0","id":1,"method":"initialize","params":{"capabilities":{"roots":{"listChanged":true}},"clientInfo":{"name":"client","version":"v0.0.1"},"protocolVersion":"2025-06-18"}}
// write: {"jsonrpc":"2.0","id":1,"method":"initialize","params":{"clientInfo":{"name":"client","version":"v0.0.1"},"protocolVersion":"2025-06-18","capabilities":{"roots":{"listChanged":true}}}}
// write: {"jsonrpc":"2.0","method":"notifications/initialized","params":{}}
}
```