MCPcopy Create free account
hub / github.com/modelcontextprotocol/go-sdk / TestStreamableClientStrictness

Function TestStreamableClientStrictness

mcp/streamable_client_test.go:326–401  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

324}
325
326func TestStreamableClientStrictness(t *testing.T) {
327 ctx := context.Background()
328
329 tests := []struct {
330 label string
331 strict bool
332 initializedStatus int
333 getStatus int
334 wantConnectError bool
335 }{
336 {"conformant server", true, http.StatusAccepted, http.StatusMethodNotAllowed, false},
337 {"strict initialized", true, http.StatusOK, http.StatusMethodNotAllowed, true},
338 {"unstrict initialized", false, http.StatusOK, http.StatusMethodNotAllowed, false},
339 {"strict GET", true, http.StatusAccepted, http.StatusNotFound, true},
340 // The client error status code is not treated as an error in non-strict
341 // mode.
342 {"unstrict GET on StatusNotFound", false, http.StatusOK, http.StatusNotFound, false},
343 {"unstrict GET on StatusBadRequest", false, http.StatusOK, http.StatusBadRequest, false},
344 {"GET on InternlServerError", false, http.StatusOK, http.StatusInternalServerError, true},
345 }
346 for _, test := range tests {
347 t.Run(test.label, func(t *testing.T) {
348 fake := &fakeStreamableServer{
349 t: t,
350 responses: fakeResponses{
351 {"POST", "", methodInitialize, ""}: {
352 header: header{
353 "Content-Type": "application/json",
354 sessionIDHeader: "123",
355 },
356 body: jsonBody(t, initResp),
357 },
358 {"POST", "123", notificationInitialized, ""}: {
359 status: test.initializedStatus,
360 wantProtocolVersion: latestProtocolVersion,
361 },
362 {"GET", "123", "", ""}: {
363 header: header{
364 "Content-Type": "text/event-stream",
365 },
366 status: test.getStatus,
367 wantProtocolVersion: latestProtocolVersion,
368 },
369 {"POST", "123", methodListTools, ""}: {
370 header: header{
371 "Content-Type": "application/json",
372 sessionIDHeader: "123",
373 },
374 body: jsonBody(t, resp(2, &ListToolsResult{Tools: []*Tool{}}, nil)),
375 optional: true,
376 },
377 {"DELETE", "123", "", ""}: {optional: true},
378 },
379 }
380 httpServer := httptest.NewServer(fake)
381 defer httpServer.Close()
382
383 transport := &StreamableClientTransport{Endpoint: httpServer.URL, strict: test.strict}

Callers

nothing calls this directly

Calls 7

ConnectMethod · 0.95
jsonBodyFunction · 0.85
respFunction · 0.85
NewClientFunction · 0.85
RunMethod · 0.80
ListToolsMethod · 0.80
CloseMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…