TestStreamableMcpHeaderVersionGating verifies that header validation is skipped for protocol versions older than minVersionForStandardHeaders.
(t *testing.T)
| 2120 | // TestStreamableMcpHeaderVersionGating verifies that header validation |
| 2121 | // is skipped for protocol versions older than minVersionForStandardHeaders. |
| 2122 | func TestStreamableMcpHeaderVersionGating(t *testing.T) { |
| 2123 | server := NewServer(&Implementation{Name: "testServer", Version: "v1.0.0"}, nil) |
| 2124 | server.AddTool( |
| 2125 | &Tool{Name: "my-tool", InputSchema: &jsonschema.Schema{Type: "object"}}, |
| 2126 | func(ctx context.Context, req *CallToolRequest) (*CallToolResult, error) { |
| 2127 | return &CallToolResult{}, nil |
| 2128 | }) |
| 2129 | |
| 2130 | handler := NewStreamableHTTPHandler(func(req *http.Request) *Server { return server }, nil) |
| 2131 | defer handler.closeAll() |
| 2132 | |
| 2133 | initReq := req(1, methodInitialize, &InitializeParams{ProtocolVersion: protocolVersion20251125}) |
| 2134 | initResp := resp(1, &InitializeResult{ |
| 2135 | Capabilities: &ServerCapabilities{ |
| 2136 | Logging: &LoggingCapabilities{}, |
| 2137 | Tools: &ToolCapabilities{ListChanged: true}, |
| 2138 | }, |
| 2139 | ProtocolVersion: protocolVersion20251125, |
| 2140 | ServerInfo: &Implementation{Name: "testServer", Version: "v1.0.0"}, |
| 2141 | }, nil) |
| 2142 | |
| 2143 | testStreamableHandler(t, handler, []streamableRequest{ |
| 2144 | { |
| 2145 | method: "POST", |
| 2146 | messages: []jsonrpc.Message{initReq}, |
| 2147 | wantStatusCode: http.StatusOK, |
| 2148 | wantMessages: []jsonrpc.Message{initResp}, |
| 2149 | wantSessionID: true, |
| 2150 | }, |
| 2151 | { |
| 2152 | method: "POST", |
| 2153 | headers: http.Header{protocolVersionHeader: {protocolVersion20251125}}, |
| 2154 | messages: []jsonrpc.Message{req(0, notificationInitialized, &InitializedParams{})}, |
| 2155 | wantStatusCode: http.StatusAccepted, |
| 2156 | }, |
| 2157 | // Requests with deliberately wrong MCP headers should still succeed |
| 2158 | // because the protocol version is too old for validation. |
| 2159 | { |
| 2160 | method: "POST", |
| 2161 | headers: http.Header{ |
| 2162 | protocolVersionHeader: {protocolVersion20251125}, |
| 2163 | methodHeader: {"wrong-method"}, |
| 2164 | nameHeader: {"wrong-name"}, |
| 2165 | }, |
| 2166 | messages: []jsonrpc.Message{req(2, "tools/call", &CallToolParams{Name: "my-tool"})}, |
| 2167 | wantStatusCode: http.StatusOK, |
| 2168 | wantMessages: []jsonrpc.Message{resp(2, &CallToolResult{Content: []Content{}}, nil)}, |
| 2169 | }, |
| 2170 | }) |
| 2171 | } |
| 2172 | |
| 2173 | // TestStreamable405AllowHeader verifies RFC 9110 §15.5.6 compliance: |
| 2174 | // 405 Method Not Allowed responses MUST include an Allow header. |
nothing calls this directly
no test coverage detected
searching dependent graphs…