test(mcp): add regression test for nil ClientInfo panic#848
Open
manusa wants to merge 1 commit intocontainers:mainfrom
Open
test(mcp): add regression test for nil ClientInfo panic#848manusa wants to merge 1 commit intocontainers:mainfrom
manusa wants to merge 1 commit intocontainers:mainfrom
Conversation
Add a test that sends a raw initialize request without clientInfo to verify the server doesn't panic. The go-sdk client always sets clientInfo, so we bypass it with raw HTTP to reproduce the scenario from non-compliant clients. Ref: containers#842, containers#844 Signed-off-by: Marc Nuri <marc@marcnuri.com>
2 tasks
Member
Author
Note: overlap with #859PR #859 introduces If #859 merges first, this PR can be rebased and simplified by replacing the inline HTTP request construction with // Raw initialize (no clientInfo)
initResp := test.McpRawPost(s.T(), httpServer.URL+"/mcp", "",
`{"jsonrpc":"2.0","id":0,"method":"initialize","params":{"protocolVersion":"2025-03-26"}}`)
defer initResp.Body.Close()
_, _ = io.ReadAll(initResp.Body)
sessionID := initResp.Header.Get("Mcp-Session-Id")
// Raw tool call
toolResp := test.McpRawPost(s.T(), httpServer.URL+"/mcp", sessionID,
`{"jsonrpc":"2.0","id":1,"method":"tools/call","params":{"name":"pods_list","arguments":{}}}`)
defer toolResp.Body.Close()This eliminates the duplicated HTTP boilerplate (Content-Type, Accept headers, error handling) while keeping the custom |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds a regression test for the nil
ClientInfopanic fixed in #844 (originally reported in #842).The existing
TestFallsBackToServerPrefixWhenNoClientInfotest usesWithEmptyClientInfo()which setsClientInfoto an empty (but non-nil)*Implementation{}. This doesn't cover the actual panic scenario whereClientInfoisnil— which happens when a client omitsclientInfofrom the initialize request entirely.Since the go-sdk client always sets
clientInfoand panics if the implementation is nil, we can't reproduce this through the standard test client. Instead, the new test sends raw HTTP JSON-RPC requests with an initialize payload that omitsclientInfo, simulating a non-compliant client. This approach is inspired by theCallToolRawpattern used in podman-mcp-server for testing raw JSON-RPC interactions.The MCP spec mandates that
clientInfois sent during initialization, but some clients don't follow this, so we should handle it gracefully.