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

Function TestStreamableStateless

mcp/streamable_test.go:1624–1740  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

1622}
1623
1624func TestStreamableStateless(t *testing.T) {
1625 initReq := req(1, methodInitialize, &InitializeParams{})
1626 initResp := resp(1, &InitializeResult{
1627 Capabilities: &ServerCapabilities{
1628 Logging: &LoggingCapabilities{},
1629 Tools: &ToolCapabilities{ListChanged: true},
1630 },
1631 ProtocolVersion: latestProtocolVersion,
1632 ServerInfo: &Implementation{Name: "test", Version: "v1.0.0"},
1633 }, nil)
1634 // This version of sayHi expects
1635 // that request from our client).
1636 sayHi := func(ctx context.Context, req *CallToolRequest, args hiParams) (*CallToolResult, any, error) {
1637 if err := req.Session.Ping(ctx, nil); err == nil {
1638 // ping should fail, but not break the connection
1639 t.Errorf("ping succeeded unexpectedly")
1640 }
1641 return &CallToolResult{Content: []Content{&TextContent{Text: "hi " + args.Name}}}, nil, nil
1642 }
1643
1644 requests := []streamableRequest{
1645 {
1646 method: "POST",
1647 messages: []jsonrpc.Message{initReq},
1648 wantStatusCode: http.StatusOK,
1649 wantMessages: []jsonrpc.Message{initResp},
1650 wantSessionID: false, // sessionless
1651 },
1652 {
1653 method: "POST",
1654 wantStatusCode: http.StatusOK,
1655 messages: []jsonrpc.Message{req(1, "tools/list", struct{}{})},
1656 wantBodyContaining: "greet",
1657 },
1658 {
1659 method: "GET",
1660 wantStatusCode: http.StatusMethodNotAllowed,
1661 },
1662 {
1663 method: "POST",
1664 wantStatusCode: http.StatusOK,
1665 messages: []jsonrpc.Message{
1666 req(2, "tools/call", &CallToolParams{Name: "greet", Arguments: hiParams{Name: "World"}}),
1667 },
1668 wantMessages: []jsonrpc.Message{
1669 resp(2, &CallToolResult{
1670 Content: []Content{&TextContent{Text: "hi World"}},
1671 }, nil),
1672 },
1673 },
1674 {
1675 method: "POST",
1676 wantStatusCode: http.StatusOK,
1677 messages: []jsonrpc.Message{
1678 req(2, "tools/call", &CallToolParams{Name: "greet", Arguments: hiParams{Name: "foo"}}),
1679 },
1680 wantMessages: []jsonrpc.Message{
1681 resp(2, &CallToolResult{

Callers

nothing calls this directly

Calls 14

reqFunction · 0.85
respFunction · 0.85
mustNotPanicFunction · 0.85
NewClientFunction · 0.85
textContentFunction · 0.85
NewStreamableHTTPHandlerFunction · 0.85
NewServerFunction · 0.85
AddToolFunction · 0.85
testStreamableHandlerFunction · 0.85
CallToolMethod · 0.80
RunMethod · 0.80
PingMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…