MCPcopy Index your code
hub / github.com/coder/coder / newHeaderRecordingServer

Function newHeaderRecordingServer

coderd/x/chatd/mcpclient/coder_headers_test.go:26–46  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

24// single "ping" tool. Every request's headers are appended to the
25// returned slice so tests can assert which headers were forwarded.
26func 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

Calls 5

HelperMethod · 0.65
CleanupMethod · 0.65
LockMethod · 0.45
CloneMethod · 0.45
UnlockMethod · 0.45

Tested by

no test coverage detected