mcp: HTTP Header Standardization for x-mcp-header (#915)

## Description

Implements
[SEP-2243](https://modelcontextprotocol.io/seps/2243-http-standardization)
(HTTP Header Standardization) for x-mcp-param custom header.

Fixes https://github.com/modelcontextprotocol/go-sdk/issues/905

---------

Co-authored-by: Maciej Kisiel <mkisiel@google.com>
This commit is contained in:
Guglielmo Colombo 2026-05-08 12:39:18 +02:00 • committed by GitHub
commit 909372d8d1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -280,6 +280,9 @@ func (s *Server) AddTool(t *Tool, h ToolHandler) {
}
}
}
if err := validateParamHeaderAnnotations(t); err != nil {
panic(fmt.Errorf("AddTool %q: invalid parameter header annotations: %v", t.Name, err))
}
st := &serverTool{tool: t, handler: h}
// Assume there was a change, since add replaces existing tools.
// (It's possible a tool was replaced with an identical one, but not worth checking.)
@ -753,10 +756,15 @@ func (s *Server) listTools(_ context.Context, req *ListToolsRequest) (*ListTools
})
}
func (s *Server) callTool(ctx context.Context, req *CallToolRequest) (*CallToolResult, error) {
// getServerTool looks up a server tool by name.
func (s *Server) getServerTool(name string) (*serverTool, bool) {
s.mu.Lock()
st, ok := s.tools.get(req.Params.Name)
s.mu.Unlock()
defer s.mu.Unlock()
return s.tools.get(name)
}
func (s *Server) callTool(ctx context.Context, req *CallToolRequest) (*CallToolResult, error) {
st, ok := s.getServerTool(req.Params.Name)
if !ok {
return nil, &jsonrpc.Error{
Code: jsonrpc.CodeInvalidParams,