diff --git a/internal/mcp/connection_stderr_test.go b/internal/mcp/connection_stderr_test.go index 208532b79..3cc7cd913 100644 --- a/internal/mcp/connection_stderr_test.go +++ b/internal/mcp/connection_stderr_test.go @@ -16,13 +16,18 @@ import ( func TestConnection_SendRequest(t *testing.T) { var receivedMethod string - srv := newPlainJSONTestServer(t, func(w http.ResponseWriter, r *http.Request, method string, _ []byte) { + srv := newPlainJSONTestServer(t, func(w http.ResponseWriter, r *http.Request, method string, body []byte) { receivedMethod = method + var req map[string]interface{} + err := json.Unmarshal(body, &req) + require.NoError(t, err) + require.Contains(t, req, "id") + w.Header().Set("Content-Type", "application/json") json.NewEncoder(w).Encode(map[string]interface{}{ "jsonrpc": "2.0", - "id": 1, + "id": req["id"], "result": map[string]interface{}{ "tools": []interface{}{}, }, diff --git a/internal/mcp/sdk_method_dispatch_test.go b/internal/mcp/sdk_method_dispatch_test.go index dad463b4c..a90a5c08a 100644 --- a/internal/mcp/sdk_method_dispatch_test.go +++ b/internal/mcp/sdk_method_dispatch_test.go @@ -211,6 +211,12 @@ func newPlainJSONTestServer(t *testing.T, handler func(w http.ResponseWriter, r return } + // SDK sends notifications/initialized after initialize; acknowledge it. + if method == "notifications/initialized" { + w.WriteHeader(http.StatusAccepted) + return + } + handler(w, r, method, body) })) }