summaryrefslogtreecommitdiff
path: root/internal/mcp/server_test.go
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2026-02-11 20:35:17 +0200
committerPaul Buetow <paul@buetow.org>2026-02-11 20:35:17 +0200
commit97b8887fb3448fd08524111d98425859bec8789f (patch)
tree8ad6235f64ed4a98f5475e32dd502872babc6bc3 /internal/mcp/server_test.go
parent0a218306f8b3381610d219deca10a21406aa08cf (diff)
Fix MCP protocol version negotiation and null prompts array
Two issues prevented Claude Code CLI from discovering MCP prompts: 1. Protocol version mismatch: Server always returned "2025-06-18" but Claude Code sends "2025-11-25". Per MCP spec, server must echo back the client's version if supported. Now supports all known versions (2024-11-05 through 2025-11-25). 2. Null prompts array: Go nil slices marshal as JSON null, but Claude Code expects an empty array []. Initialize prompts slice with make() to ensure [] in JSON output. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Diffstat (limited to 'internal/mcp/server_test.go')
-rw-r--r--internal/mcp/server_test.go22
1 files changed, 22 insertions, 0 deletions
diff --git a/internal/mcp/server_test.go b/internal/mcp/server_test.go
index 0c767f2..0944f35 100644
--- a/internal/mcp/server_test.go
+++ b/internal/mcp/server_test.go
@@ -500,6 +500,28 @@ func TestServer_ReadMessage(t *testing.T) {
})
}
+func TestNegotiateProtocolVersion(t *testing.T) {
+ tests := []struct {
+ name string
+ client string
+ expected string
+ }{
+ {"echoes supported version", "2025-11-25", "2025-11-25"},
+ {"echoes older version", "2025-06-18", "2025-06-18"},
+ {"echoes oldest version", "2024-11-05", "2024-11-05"},
+ {"returns latest for unknown", "9999-01-01", LatestProtocolVersion},
+ {"returns latest for empty", "", LatestProtocolVersion},
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ got := negotiateProtocolVersion(tt.client)
+ if got != tt.expected {
+ t.Errorf("negotiateProtocolVersion(%q) = %q, want %q", tt.client, got, tt.expected)
+ }
+ })
+ }
+}
+
func TestServer_HandleInitialized(t *testing.T) {
store := &mockPromptStore{prompts: make(map[string]*promptstore.Prompt)}
server, _, _ := createTestServer(t, store)