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:
@@ -78,9 +78,10 @@ func AccessLog(log *slog.Logger) func(http.Handler) http.Handler {
|
||||
slog.Int("status", recorder.status),
|
||||
slog.Duration("duration", time.Since(started)),
|
||||
slog.String("remote_addr", requestip.FromRequest(r)),
|
||||
slog.String("mcp_session_id", mcpSessionIDFromRequest(r)),
|
||||
}
|
||||
if tool, _ := r.Context().Value(mcpToolContextKey).(string); strings.TrimSpace(tool) != "" {
|
||||
attrs = append(attrs, slog.String("tool", tool))
|
||||
attrs = append(attrs, slog.String("tool", tool), slog.String("tool_call", tool))
|
||||
}
|
||||
log.Info("http request", attrs...)
|
||||
})
|
||||
@@ -150,6 +151,22 @@ func mcpToolFromRequest(r *http.Request) string {
|
||||
return msg.toolName()
|
||||
}
|
||||
|
||||
func mcpSessionIDFromRequest(r *http.Request) string {
|
||||
if r == nil {
|
||||
return ""
|
||||
}
|
||||
if v := strings.TrimSpace(r.Header.Get("MCP-Session-Id")); v != "" {
|
||||
return v
|
||||
}
|
||||
// Some clients/proxies may propagate the session in query params.
|
||||
for _, key := range []string{"session_id", "sessionId", "mcp_session_id"} {
|
||||
if v := strings.TrimSpace(r.URL.Query().Get(key)); v != "" {
|
||||
return v
|
||||
}
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
type rpcEnvelope struct {
|
||||
Method string `json:"method"`
|
||||
Params struct {
|
||||
|
||||
Reference in New Issue
Block a user