newHeaderRecordingServer creates a streamable HTTP MCP server with a single "ping" tool. Every request's headers are appended to the returned slice so tests can assert which headers were forwarded.
(t *testing.T)
| 24 | // single "ping" tool. Every request's headers are appended to the |
| 25 | // returned slice so tests can assert which headers were forwarded. |
| 26 | func newHeaderRecordingServer(t *testing.T) (*httptest.Server, *sync.Mutex, *[]http.Header) { |
| 27 | t.Helper() |
| 28 | var ( |
| 29 | mu sync.Mutex |
| 30 | headers []http.Header |
| 31 | ) |
| 32 | srv := mcpserver.NewMCPServer("hdr-server", "1.0.0") |
| 33 | srv.AddTools(mcpserver.ServerTool{ |
| 34 | Tool: mcp.NewTool("ping", mcp.WithDescription("records the request headers")), |
| 35 | Handler: func(_ context.Context, req mcp.CallToolRequest) (*mcp.CallToolResult, error) { |
| 36 | mu.Lock() |
| 37 | headers = append(headers, req.Header.Clone()) |
| 38 | mu.Unlock() |
| 39 | return mcp.NewToolResultText("ok"), nil |
| 40 | }, |
| 41 | }) |
| 42 | httpSrv := mcpserver.NewStreamableHTTPServer(srv) |
| 43 | ts := httptest.NewServer(httpSrv) |
| 44 | t.Cleanup(ts.Close) |
| 45 | return ts, &mu, &headers |
| 46 | } |
| 47 | |
| 48 | // TestConnectAll_ForwardCoderHeaders_DefaultOff is a regression guard |
| 49 | // that the Coder identity headers are NOT sent when the option is |
no test coverage detected