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

@ -440,6 +440,80 @@ func TestClientCapabilities(t *testing.T) {
}
}
func TestToolCache(t *testing.T) {
tool1 := &Tool{Name: "tool1", Description: "first"}
tool2 := &Tool{Name: "tool2", Description: "second"}
tool1Updated := &Tool{Name: "tool1", Description: "updated"}
testCases := []struct {
name string
cacheBatches [][]*Tool
lookup string
want *Tool
}{
{
name: "empty cache",
lookup: "tool1",
want: nil,
},
{
name: "single tool found",
cacheBatches: [][]*Tool{{tool1}},
lookup: "tool1",
want: tool1,
},
{
name: "unknown tool",
cacheBatches: [][]*Tool{{tool1}},
lookup: "nonexistent",
want: nil,
},
{
name: "multiple tools single batch",
cacheBatches: [][]*Tool{{tool1, tool2}},
lookup: "tool2",
want: tool2,
},
{
name: "replace clears old entries",
cacheBatches: [][]*Tool{{tool1}, {tool2}},
lookup: "tool1",
want: nil,
},
{
name: "replace keeps new entries",
cacheBatches: [][]*Tool{{tool1}, {tool2}},
lookup: "tool2",
want: tool2,
},
{
name: "overwrite existing entry",
cacheBatches: [][]*Tool{{tool1}, {tool1Updated}},
lookup: "tool1",
want: tool1Updated,
},
{
name: "empty batch no-op",
cacheBatches: [][]*Tool{{}},
lookup: "tool1",
want: nil,
},
}
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
cs := &ClientSession{}
for _, batch := range tc.cacheBatches {
cs.cacheTools(batch)
}
got := cs.getCachedTool(tc.lookup)
if diff := cmp.Diff(tc.want, got); diff != "" {
t.Errorf("getCachedTool(%q) mismatch (-want +got):\n%s", tc.lookup, diff)
}
})
}
}
func TestClientCapabilitiesOverWire(t *testing.T) {
testCases := []struct {
name string