MCPcopy
hub / github.com/googleapis/mcp-toolbox / TestInvalidProtocolVersionHeader

Function TestInvalidProtocolVersionHeader

internal/server/mcp_test.go:1245–1291  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

1243}
1244
1245func TestInvalidProtocolVersionHeader(t *testing.T) {
1246 mockTools := []testutils.MockTool{testutils.MockTool1, testutils.MockTool2, testutils.MockTool3, testutils.MockTool4, testutils.MockTool5}
1247 mockPrompts := []testutils.MockPrompt{testutils.MockPrompt1}
1248 toolsMap, toolsets, promptsMap, promptsets := testutils.SetUpResources(t, mockTools, mockPrompts)
1249 r, shutdown := setUpServer(t, "mcp", toolsMap, toolsets, promptsMap, promptsets)
1250 defer shutdown()
1251 ts := runServer(r, false)
1252 defer ts.Close()
1253
1254 reqBody := jsonrpc.JSONRPCRequest{
1255 Jsonrpc: jsonrpcVersion,
1256 Id: "tools-list",
1257 Request: jsonrpc.Request{
1258 Method: "tools/list",
1259 },
1260 }
1261 reqMarshal, err := json.Marshal(reqBody)
1262 if err != nil {
1263 t.Fatalf("unexpected error during marshaling of body")
1264 }
1265 header := map[string]string{}
1266 header["MCP-Protocol-Version"] = "foo"
1267
1268 resp, body, err := runRequest(ts, http.MethodPost, "/", bytes.NewBuffer(reqMarshal), header)
1269 if resp.Status != "400 Bad Request" {
1270 t.Fatalf("unexpected status: %s; %s", resp.Status, body)
1271 }
1272 var got map[string]any
1273 if err := json.Unmarshal(body, &got); err != nil {
1274 t.Fatalf("unexpected error unmarshalling body: %s", err)
1275 }
1276 errMap, ok := got["error"].(map[string]any)
1277 if !ok {
1278 t.Fatalf("expected 'error' field to be a map, got %T", got["error"])
1279 }
1280 msg, ok := errMap["message"].(string)
1281 if !ok {
1282 t.Fatalf("expected 'message' field to be a string, got %T", errMap["message"])
1283 }
1284 want := "unsupported protocol version"
1285 if msg != want {
1286 t.Fatalf("unexpected error message: got %s, want %s", got["error"], want)
1287 }
1288 if err != nil {
1289 t.Fatalf("unexpected error during request: %s", err)
1290 }
1291}
1292
1293func TestDeleteEndpoint(t *testing.T) {
1294 r, shutdown := setUpServer(t, "mcp", nil, nil, nil, nil)

Callers

nothing calls this directly

Calls 6

SetUpResourcesFunction · 0.92
setUpServerFunction · 0.85
runServerFunction · 0.85
runRequestFunction · 0.85
UnmarshalMethod · 0.80
CloseMethod · 0.45

Tested by

no test coverage detected