mcp: add Cacheable fields to DiscoverResult (#1022)
This PR add the Cacheable fields to the DiscoverResult, as it was added
later
(8e4c2322ca)
This commit is contained in:
parent
7f4aa4a0ce
commit
a817f61412
7 changed files with 17 additions and 19 deletions
|
|
@ -77,19 +77,13 @@ it is the client's responsibility to end the session.
|
||||||
func Example_lifecycle() {
|
func Example_lifecycle() {
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
|
|
||||||
// Create a client and server.
|
// Create a client and server. Under protocol version 2026-07-28, there
|
||||||
// Wait for the client to initialize the session.
|
// is no dedicated initialize/initialized handshake: the session is
|
||||||
|
// implicitly live the moment the client issues its first request.
|
||||||
client := mcp.NewClient(&mcp.Implementation{Name: "client", Version: "v0.0.1"}, nil)
|
client := mcp.NewClient(&mcp.Implementation{Name: "client", Version: "v0.0.1"}, nil)
|
||||||
server := mcp.NewServer(&mcp.Implementation{Name: "server", Version: "v0.0.1"}, &mcp.ServerOptions{
|
server := mcp.NewServer(&mcp.Implementation{Name: "server", Version: "v0.0.1"}, nil)
|
||||||
InitializedHandler: func(context.Context, *mcp.InitializedRequest) {
|
|
||||||
fmt.Println("initialized!")
|
|
||||||
},
|
|
||||||
})
|
|
||||||
|
|
||||||
// Connect the server and client using in-memory transports.
|
// Connect the server and client using in-memory transports.
|
||||||
//
|
|
||||||
// Connect the server first so that it's ready to receive initialization
|
|
||||||
// messages from the client.
|
|
||||||
t1, t2 := mcp.NewInMemoryTransports()
|
t1, t2 := mcp.NewInMemoryTransports()
|
||||||
serverSession, err := server.Connect(ctx, t1, nil)
|
serverSession, err := server.Connect(ctx, t1, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
@ -108,7 +102,7 @@ func Example_lifecycle() {
|
||||||
if err := serverSession.Wait(); err != nil {
|
if err := serverSession.Wait(); err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
// Output: initialized!
|
// Output:
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
@ -213,7 +207,7 @@ func ExampleStreamableHTTPHandler() {
|
||||||
defer httpServer.Close()
|
defer httpServer.Close()
|
||||||
|
|
||||||
// The SDK is currently permissive of some missing keys in "params".
|
// The SDK is currently permissive of some missing keys in "params".
|
||||||
resp := mustPostMessage(`{"jsonrpc": "2.0", "id": 1, "method":"initialize", "params": {}}`, httpServer.URL)
|
resp := mustPostMessage(`{"jsonrpc": "2.0", "id": 1, "method":"initialize", "params": {"protocolVersion":"2025-11-25"}}`, httpServer.URL)
|
||||||
fmt.Println(resp)
|
fmt.Println(resp)
|
||||||
// Output:
|
// Output:
|
||||||
// {"jsonrpc":"2.0","id":1,"result":{"capabilities":{"logging":{}},"protocolVersion":"2025-11-25","serverInfo":{"name":"server","version":"v0.1.0"}}}
|
// {"jsonrpc":"2.0","id":1,"result":{"capabilities":{"logging":{}},"protocolVersion":"2025-11-25","serverInfo":{"name":"server","version":"v0.1.0"}}}
|
||||||
|
|
|
||||||
|
|
@ -531,7 +531,7 @@ func Example_mrtr() {
|
||||||
// uses it to fulfil any input request the tool handler returns.
|
// uses it to fulfil any input request the tool handler returns.
|
||||||
c := mcp.NewClient(&mcp.Implementation{Name: "client", Version: "v0.0.1"}, &mcp.ClientOptions{
|
c := mcp.NewClient(&mcp.Implementation{Name: "client", Version: "v0.0.1"}, &mcp.ClientOptions{
|
||||||
ElicitationHandler: func(_ context.Context, _ *mcp.ElicitRequest) (*mcp.ElicitResult, error) {
|
ElicitationHandler: func(_ context.Context, _ *mcp.ElicitRequest) (*mcp.ElicitResult, error) {
|
||||||
return &mcp.ElicitResult{Action: "accept", Content: map[string]any{"name": "Ada"}}, nil
|
return &mcp.ElicitResult{Action: "accept", Content: map[string]any{"name": "MCP Go"}}, nil
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -50,9 +50,8 @@ func ExampleLoggingTransport() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Output:
|
// Output:
|
||||||
// read: {"jsonrpc":"2.0","id":1,"result":{"capabilities":{"logging":{}},"protocolVersion":"2025-11-25","serverInfo":{"name":"server","version":"v0.0.1"}}}
|
// 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"}}}
|
||||||
// write: {"jsonrpc":"2.0","id":1,"method":"initialize","params":{"clientInfo":{"name":"client","version":"v0.0.1"},"protocolVersion":"2025-11-25","capabilities":{"roots":{"listChanged":true}}}}
|
// 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"}}}
|
||||||
// write: {"jsonrpc":"2.0","method":"notifications/initialized","params":{}}
|
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1129,6 +1129,7 @@ func (x *DiscoverParams) SetProgressToken(t any) { setProgressToken(x, t) }
|
||||||
|
|
||||||
type DiscoverResult struct {
|
type DiscoverResult struct {
|
||||||
Meta `json:"_meta,omitempty"`
|
Meta `json:"_meta,omitempty"`
|
||||||
|
Cacheable
|
||||||
// The versions of the Model Context Protocol that the server supports.
|
// The versions of the Model Context Protocol that the server supports.
|
||||||
SupportedVersions []string `json:"supportedVersions"`
|
SupportedVersions []string `json:"supportedVersions"`
|
||||||
// The server's capabilities.
|
// The server's capabilities.
|
||||||
|
|
|
||||||
|
|
@ -869,12 +869,14 @@ func (s *Server) discover(_ context.Context, req *ServerRequest[*DiscoverParams]
|
||||||
ClientInfo: req.ClientInfo(),
|
ClientInfo: req.ClientInfo(),
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
return &DiscoverResult{
|
res := &DiscoverResult{
|
||||||
SupportedVersions: versions,
|
SupportedVersions: versions,
|
||||||
Capabilities: s.capabilities(),
|
Capabilities: s.capabilities(),
|
||||||
ServerInfo: s.impl,
|
ServerInfo: s.impl,
|
||||||
Instructions: s.opts.Instructions,
|
Instructions: s.opts.Instructions,
|
||||||
}, nil
|
}
|
||||||
|
res.setDefaultCacheableValues()
|
||||||
|
return res, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// filterSupportedVersions returns the subset of [supportedProtocolVersions]
|
// filterSupportedVersions returns the subset of [supportedProtocolVersions]
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,8 @@ supports, its capabilities, and its identity.
|
||||||
"jsonrpc": "2.0",
|
"jsonrpc": "2.0",
|
||||||
"id": 1,
|
"id": 1,
|
||||||
"result": {
|
"result": {
|
||||||
|
"ttlMs": 0,
|
||||||
|
"cacheScope": "public",
|
||||||
"supportedVersions": [
|
"supportedVersions": [
|
||||||
"2026-07-28",
|
"2026-07-28",
|
||||||
"2025-11-25",
|
"2025-11-25",
|
||||||
|
|
|
||||||
|
|
@ -42,7 +42,7 @@ func ExampleLoggingTransport() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Output:
|
// Output:
|
||||||
// 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"}}}
|
// 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"}}}
|
||||||
// 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"}}}
|
// 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"}}}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue