mcp: fix potential nil-pointer dereference on message send (#1115)
This commit is contained in:
parent
cc4db25347
commit
bc72835f62
1 changed files with 12 additions and 7 deletions
|
|
@ -2403,13 +2403,12 @@ func (c *streamableClientConn) setMCPHeaders(req *http.Request, msg jsonrpc.Mess
|
|||
}
|
||||
}
|
||||
}
|
||||
switch {
|
||||
case protocolVersionFromMessage(msg) != "":
|
||||
req.Header.Set(protocolVersionHeader, protocolVersionFromMessage(msg))
|
||||
case c.initializedResult != nil:
|
||||
if pv := protocolVersionFromMessage(msg); pv != "" {
|
||||
req.Header.Set(protocolVersionHeader, pv)
|
||||
} else if pv := protocolVersionFromContext(req.Context()); pv != "" {
|
||||
req.Header.Set(protocolVersionHeader, pv)
|
||||
} else if c.initializedResult != nil {
|
||||
req.Header.Set(protocolVersionHeader, c.initializedResult.ProtocolVersion)
|
||||
case protocolVersionFromContext(req.Context()) != "":
|
||||
req.Header.Set(protocolVersionHeader, protocolVersionFromContext(req.Context()))
|
||||
}
|
||||
if c.sessionID != "" {
|
||||
req.Header.Set(sessionIDHeader, c.sessionID)
|
||||
|
|
@ -2424,7 +2423,7 @@ func (c *streamableClientConn) setMCPHeaders(req *http.Request, msg jsonrpc.Mess
|
|||
// nil msg.
|
||||
func protocolVersionFromMessage(msg jsonrpc.Message) string {
|
||||
req, ok := msg.(*jsonrpc.Request)
|
||||
if !ok {
|
||||
if !ok || req == nil {
|
||||
return ""
|
||||
}
|
||||
meta := extractRequestMeta(req.Params)
|
||||
|
|
|
|||
Loading…
Reference in a new issue