MCPcopy
hub / github.com/docker/docker-agent / TestRemoteClientHeadersWithStreamable

Function TestRemoteClientHeadersWithStreamable

pkg/tools/mcp/remote_test.go:102–145  ·  view source on GitHub ↗

TestRemoteClientHeadersWithStreamable verifies that custom headers work with streamable transport

(t *testing.T)

Source from the content-addressed store, hash-verified

100
101// TestRemoteClientHeadersWithStreamable verifies that custom headers work with streamable transport
102func TestRemoteClientHeadersWithStreamable(t *testing.T) {
103 t.Parallel()
104
105 var capturedRequest *http.Request
106 requestCaptured := make(chan bool, 1)
107
108 // Create a test server for streamable transport
109 server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
110 capturedRequest = r
111
112 // Send a minimal response
113 w.Header().Set("Content-Type", "application/json")
114 w.WriteHeader(http.StatusOK)
115 fmt.Fprintf(w, `{"jsonrpc":"2.0","result":{"protocolVersion":"1.0.0","capabilities":{},"serverInfo":{"name":"test","version":"1.0.0"}},"id":1}`)
116
117 select {
118 case requestCaptured <- true:
119 default:
120 }
121 }))
122 defer server.Close()
123
124 // Create remote client WITH custom headers using streamable transport
125 expectedHeaders := map[string]string{
126 "X-Custom-Auth": "custom-auth-value",
127 }
128
129 client := newRemoteClient(server.URL, "streamable", expectedHeaders, NewInMemoryTokenStore(), nil, false)
130
131 // Try to initialize
132 _, _ = client.Initialize(t.Context(), nil)
133
134 // Wait for the request to be captured
135 select {
136 case <-requestCaptured:
137 // Verify that custom headers were applied
138 actualValue := capturedRequest.Header.Get("X-Custom-Auth")
139 assert.Equal(t, "custom-auth-value", actualValue,
140 "Expected header X-Custom-Auth to have value %q, but got %q",
141 "custom-auth-value", actualValue)
142 case <-time.After(100 * time.Millisecond):
143 t.Fatal("Server did not receive request within timeout")
144 }
145}
146
147// TestRemoteClientNoHeaders verifies that the client works correctly even with no headers
148func TestRemoteClientNoHeaders(t *testing.T) {

Callers

nothing calls this directly

Calls 7

newRemoteClientFunction · 0.85
NewInMemoryTokenStoreFunction · 0.85
ContextMethod · 0.80
CloseMethod · 0.65
InitializeMethod · 0.65
GetMethod · 0.65
SetMethod · 0.45

Tested by

no test coverage detected