mcp: update return meta in DiscoverResult (SEP-2575) (#1097)

This PR implements the latest changes introduced by
https://github.com/modelcontextprotocol/modelcontextprotocol/pull/3002
This commit is contained in:
Guglielmo Colombo 2026-07-16 16:10:12 +02:00 • committed by GitHub
commit 5cb8339210
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -443,11 +443,15 @@ func (c *Client) discover(ctx context.Context, cs *ClientSession) (*InitializeRe
}
}
var serverInfo *Implementation
if v, ok := decodeMetaValue[*Implementation](res.GetMeta(), MetaKeyServerInfo); ok {
serverInfo = v
}
return &InitializeResult{
Capabilities: res.Capabilities,
Instructions: res.Instructions,
ProtocolVersion: negotiated,
ServerInfo: res.ServerInfo,
ServerInfo: serverInfo,
}, nil
}
@ -509,9 +513,12 @@ func (cs *ClientSession) usesNewProtocol() bool {
return res != nil && res.ProtocolVersion >= protocolVersion20260728
}
// injectRequestMeta populates the SEP-2575 per-request `_meta` triple
// (protocolVersion, clientInfo, clientCapabilities) on the given outgoing
// request params. Keys already present in params.Meta are not overwritten.
// injectRequestMeta populates the SEP-2575 per-request `_meta` fields
// (protocolVersion, optional clientInfo, clientCapabilities) on the given
// outgoing request params. Keys already present in params.Meta are not
// overwritten. Per PR modelcontextprotocol/modelcontextprotocol#3002
// clientInfo is SHOULD (not MUST), and is omitted when the client has no
// [Implementation] configured.
func injectRequestMeta[T any, P interface {
*T
Params
@ -527,7 +534,7 @@ func injectRequestMeta[T any, P interface {
if _, ok := m[MetaKeyProtocolVersion]; !ok {
m[MetaKeyProtocolVersion] = res.ProtocolVersion
}
if _, ok := m[MetaKeyClientInfo]; !ok {
if _, ok := m[MetaKeyClientInfo]; !ok && cs.client.impl != nil {
m[MetaKeyClientInfo] = cs.client.impl
}
if _, ok := m[MetaKeyClientCapabilities]; !ok {