fix(observability): include MCP session ID in access logs
Some checks failed
CI / build-and-test (push) Failing after -32m50s
Some checks failed
CI / build-and-test (push) Failing after -32m50s
* Add function to extract MCP session ID from request headers and query parameters * Update access log to include MCP session ID fix(cli): simplify project lookup logic * Refactor project retrieval to prefer GUID lookup when input is a valid UUID * Introduce separate functions for fetching projects by GUID and name
This commit is contained in:
@@ -113,4 +113,46 @@ func TestAccessLogIncludesMCPToolName(t *testing.T) {
|
||||
if !strings.Contains(buf.String(), "tool=list_projects") {
|
||||
t.Fatalf("log output = %q, want tool=list_projects", buf.String())
|
||||
}
|
||||
if !strings.Contains(buf.String(), "tool_call=list_projects") {
|
||||
t.Fatalf("log output = %q, want tool_call=list_projects", buf.String())
|
||||
}
|
||||
}
|
||||
|
||||
func TestAccessLogIncludesMCPSessionIDHeader(t *testing.T) {
|
||||
var buf bytes.Buffer
|
||||
logger := slog.New(slog.NewTextHandler(&buf, nil))
|
||||
handler := AccessLog(logger)(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
w.WriteHeader(http.StatusNoContent)
|
||||
}))
|
||||
|
||||
req := httptest.NewRequest(http.MethodGet, "/sse", nil)
|
||||
req.Header.Set("MCP-Session-Id", "sess-123")
|
||||
rec := httptest.NewRecorder()
|
||||
handler.ServeHTTP(rec, req)
|
||||
|
||||
if rec.Code != http.StatusNoContent {
|
||||
t.Fatalf("status = %d, want %d", rec.Code, http.StatusNoContent)
|
||||
}
|
||||
if !strings.Contains(buf.String(), "mcp_session_id=sess-123") {
|
||||
t.Fatalf("log output = %q, want mcp_session_id=sess-123", buf.String())
|
||||
}
|
||||
}
|
||||
|
||||
func TestAccessLogIncludesMCPSessionIDQueryParam(t *testing.T) {
|
||||
var buf bytes.Buffer
|
||||
logger := slog.New(slog.NewTextHandler(&buf, nil))
|
||||
handler := AccessLog(logger)(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
w.WriteHeader(http.StatusNoContent)
|
||||
}))
|
||||
|
||||
req := httptest.NewRequest(http.MethodGet, "/sse?session_id=sess-q-1", nil)
|
||||
rec := httptest.NewRecorder()
|
||||
handler.ServeHTTP(rec, req)
|
||||
|
||||
if rec.Code != http.StatusNoContent {
|
||||
t.Fatalf("status = %d, want %d", rec.Code, http.StatusNoContent)
|
||||
}
|
||||
if !strings.Contains(buf.String(), "mcp_session_id=sess-q-1") {
|
||||
t.Fatalf("log output = %q, want mcp_session_id=sess-q-1", buf.String())
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user