Skip to content

Commit a817f61

Browse files
mcp: add Cacheable fields to DiscoverResult (#1022)
This PR add the Cacheable fields to the DiscoverResult, as it was added later (modelcontextprotocol/modelcontextprotocol@8e4c232)
1 parent 7f4aa4a commit a817f61

7 files changed

Lines changed: 17 additions & 19 deletions

File tree

docs/protocol.md

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -77,19 +77,13 @@ it is the client's responsibility to end the session.
7777
func Example_lifecycle() {
7878
ctx := context.Background()
7979

80-
// Create a client and server.
81-
// Wait for the client to initialize the session.
80+
// Create a client and server. Under protocol version 2026-07-28, there
81+
// is no dedicated initialize/initialized handshake: the session is
82+
// implicitly live the moment the client issues its first request.
8283
client := mcp.NewClient(&mcp.Implementation{Name: "client", Version: "v0.0.1"}, nil)
83-
server := mcp.NewServer(&mcp.Implementation{Name: "server", Version: "v0.0.1"}, &mcp.ServerOptions{
84-
InitializedHandler: func(context.Context, *mcp.InitializedRequest) {
85-
fmt.Println("initialized!")
86-
},
87-
})
84+
server := mcp.NewServer(&mcp.Implementation{Name: "server", Version: "v0.0.1"}, nil)
8885

8986
// Connect the server and client using in-memory transports.
90-
//
91-
// Connect the server first so that it's ready to receive initialization
92-
// messages from the client.
9387
t1, t2 := mcp.NewInMemoryTransports()
9488
serverSession, err := server.Connect(ctx, t1, nil)
9589
if err != nil {
@@ -108,7 +102,7 @@ func Example_lifecycle() {
108102
if err := serverSession.Wait(); err != nil {
109103
log.Fatal(err)
110104
}
111-
// Output: initialized!
105+
// Output:
112106
}
113107
```
114108

@@ -213,7 +207,7 @@ func ExampleStreamableHTTPHandler() {
213207
defer httpServer.Close()
214208

215209
// The SDK is currently permissive of some missing keys in "params".
216-
resp := mustPostMessage(`{"jsonrpc": "2.0", "id": 1, "method":"initialize", "params": {}}`, httpServer.URL)
210+
resp := mustPostMessage(`{"jsonrpc": "2.0", "id": 1, "method":"initialize", "params": {"protocolVersion":"2025-11-25"}}`, httpServer.URL)
217211
fmt.Println(resp)
218212
// Output:
219213
// {"jsonrpc":"2.0","id":1,"result":{"capabilities":{"logging":{}},"protocolVersion":"2025-11-25","serverInfo":{"name":"server","version":"v0.1.0"}}}

docs/server.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -531,7 +531,7 @@ func Example_mrtr() {
531531
// uses it to fulfil any input request the tool handler returns.
532532
c := mcp.NewClient(&mcp.Implementation{Name: "client", Version: "v0.0.1"}, &mcp.ClientOptions{
533533
ElicitationHandler: func(_ context.Context, _ *mcp.ElicitRequest) (*mcp.ElicitResult, error) {
534-
return &mcp.ElicitResult{Action: "accept", Content: map[string]any{"name": "Ada"}}, nil
534+
return &mcp.ElicitResult{Action: "accept", Content: map[string]any{"name": "MCP Go"}}, nil
535535
},
536536
})
537537

docs/troubleshooting.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,8 @@ func ExampleLoggingTransport() {
5050
}
5151

5252
// Output:
53-
// read: {"jsonrpc":"2.0","id":1,"result":{"capabilities":{"logging":{}},"protocolVersion":"2025-11-25","serverInfo":{"name":"server","version":"v0.0.1"}}}
54-
// write: {"jsonrpc":"2.0","id":1,"method":"initialize","params":{"clientInfo":{"name":"client","version":"v0.0.1"},"protocolVersion":"2025-11-25","capabilities":{"roots":{"listChanged":true}}}}
55-
// write: {"jsonrpc":"2.0","method":"notifications/initialized","params":{}}
53+
// read: {"jsonrpc":"2.0","id":1,"result":{"ttlMs":0,"cacheScope":"public","supportedVersions":["2026-07-28","2025-11-25","2025-06-18","2025-03-26","2024-11-05"],"capabilities":{"logging":{}},"serverInfo":{"name":"server","version":"v0.0.1"}}}
54+
// write: {"jsonrpc":"2.0","id":1,"method":"server/discover","params":{"_meta":{"io.modelcontextprotocol/clientCapabilities":{"roots":{"listChanged":true}},"io.modelcontextprotocol/clientInfo":{"name":"client","version":"v0.0.1"},"io.modelcontextprotocol/protocolVersion":"2026-07-28"}}}
5655
}
5756
```
5857

mcp/protocol.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1129,6 +1129,7 @@ func (x *DiscoverParams) SetProgressToken(t any) { setProgressToken(x, t) }
11291129

11301130
type DiscoverResult struct {
11311131
Meta `json:"_meta,omitempty"`
1132+
Cacheable
11321133
// The versions of the Model Context Protocol that the server supports.
11331134
SupportedVersions []string `json:"supportedVersions"`
11341135
// The server's capabilities.

mcp/server.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -869,12 +869,14 @@ func (s *Server) discover(_ context.Context, req *ServerRequest[*DiscoverParams]
869869
ClientInfo: req.ClientInfo(),
870870
}
871871
})
872-
return &DiscoverResult{
872+
res := &DiscoverResult{
873873
SupportedVersions: versions,
874874
Capabilities: s.capabilities(),
875875
ServerInfo: s.impl,
876876
Instructions: s.opts.Instructions,
877-
}, nil
877+
}
878+
res.setDefaultCacheableValues()
879+
return res, nil
878880
}
879881

880882
// filterSupportedVersions returns the subset of [supportedProtocolVersions]

mcp/testdata/conformance/server/discover.txtar

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ supports, its capabilities, and its identity.
2121
"jsonrpc": "2.0",
2222
"id": 1,
2323
"result": {
24+
"ttlMs": 0,
25+
"cacheScope": "public",
2426
"supportedVersions": [
2527
"2026-07-28",
2628
"2025-11-25",

mcp/transport_example_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ func ExampleLoggingTransport() {
4242
}
4343

4444
// Output:
45-
// read: {"jsonrpc":"2.0","id":1,"result":{"supportedVersions":["2026-07-28","2025-11-25","2025-06-18","2025-03-26","2024-11-05"],"capabilities":{"logging":{}},"serverInfo":{"name":"server","version":"v0.0.1"}}}
45+
// read: {"jsonrpc":"2.0","id":1,"result":{"ttlMs":0,"cacheScope":"public","supportedVersions":["2026-07-28","2025-11-25","2025-06-18","2025-03-26","2024-11-05"],"capabilities":{"logging":{}},"serverInfo":{"name":"server","version":"v0.0.1"}}}
4646
// write: {"jsonrpc":"2.0","id":1,"method":"server/discover","params":{"_meta":{"io.modelcontextprotocol/clientCapabilities":{"roots":{"listChanged":true}},"io.modelcontextprotocol/clientInfo":{"name":"client","version":"v0.0.1"},"io.modelcontextprotocol/protocolVersion":"2026-07-28"}}}
4747
}
4848

0 commit comments

Comments
 (0)