Documentation
¶
Overview ¶
Package mcp exposes Spaniel's observability data to MCP (Model Context Protocol) clients such as Claude Code and Claude Desktop. It runs in-process on the main HTTP server (mounted at /mcp) over the streamable-HTTP transport and reads directly from storage — no second process, so it never contends with the server for DuckDB's single writer lock.
This file is the foundation: server construction, the telemetry middleware, and a single read-only get_server_info tool. Subsequent tools live in sibling files in this package and are registered from NewHandler.
Index ¶
- func NewHandler(store *storage.DB, opts Options) http.Handler
- type ActivateSessionInput
- type CreateSessionInput
- type CreateSessionOutput
- type DiffSessionsInput
- type DiffSessionsOutput
- type DiffSideOut
- type DiffSpanOut
- type DiffSummaryOut
- type GetMetricSeriesInput
- type GetMetricSeriesOutput
- type GetMetricsInput
- type GetMetricsOutput
- type GetServiceMapInput
- type GetSpanInput
- type GetSpanOutput
- type GetStatsInput
- type GetTraceInput
- type GetTraceOutput
- type IssueOut
- type LintOut
- type LintWarningOut
- type ListIssuesInput
- type ListIssuesOutput
- type ListLintInput
- type ListLintOutput
- type ListServicesOutput
- type ListSessionsOutput
- type ListSlowSpansInput
- type ListSlowSpansOutput
- type ListTracesInput
- type ListTracesOutput
- type LogOut
- type MetricCatalogOut
- type MetricPointOut
- type OKOutput
- type Options
- type PruneDataInput
- type PruneDataOutput
- type QueryLogsInput
- type QueryLogsOutput
- type QuerySQLInput
- type QuerySQLOutput
- type SearchHit
- type SearchInput
- type SearchOutput
- type ServerInfo
- type ServiceEdgeOut
- type ServiceMapOutput
- type ServiceNodeOut
- type SessionOut
- type SetBaselineInput
- type SlowSpanOut
- type SpanEventOut
- type SpanLinkOut
- type StatsOutput
- type TraceIssueOut
- type TraceLogOut
- type TraceSpanOut
- type TraceSummary
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type ActivateSessionInput ¶
type ActivateSessionInput struct {
SessionID string `json:"session_id" jsonschema:"id of the session to activate"`
}
type CreateSessionInput ¶
type CreateSessionInput struct {
Label string `json:"label,omitempty" jsonschema:"human-readable label; defaults to a timestamp"`
Baseline bool `json:"baseline,omitempty" jsonschema:"mark the new session as a baseline"`
Activate bool `json:"activate,omitempty" jsonschema:"make this the active session so new telemetry records into it"`
}
type CreateSessionOutput ¶
type DiffSessionsInput ¶
type DiffSessionsOutput ¶
type DiffSessionsOutput struct {
Baseline DiffSideOut `json:"baseline"`
Compare DiffSideOut `json:"compare"`
Summary DiffSummaryOut `json:"summary"`
Spans []DiffSpanOut `json:"spans"`
}
type DiffSideOut ¶
type DiffSpanOut ¶
type DiffSummaryOut ¶
type GetMetricSeriesInput ¶
type GetMetricSeriesInput struct {
Name string `json:"name" jsonschema:"metric name (from get_metrics)"`
Service string `json:"service,omitempty" jsonschema:"narrow to one service"`
SessionID string `json:"session_id,omitempty" jsonschema:"session to query; defaults to the active session"`
FromNs int64 `json:"from_ns,omitempty" jsonschema:"inclusive lower bound (unix ns); 0 = no bound"`
ToNs int64 `json:"to_ns,omitempty" jsonschema:"inclusive upper bound (unix ns); 0 = no bound"`
Limit int `json:"limit,omitempty" jsonschema:"max points to return (default 500)"`
}
type GetMetricSeriesOutput ¶
type GetMetricSeriesOutput struct {
SessionID string `json:"session_id"`
Name string `json:"name"`
Count int `json:"count"`
Points []MetricPointOut `json:"points"`
}
type GetMetricsInput ¶
type GetMetricsInput struct {
SessionID string `json:"session_id,omitempty" jsonschema:"session to query; defaults to the active session"`
}
type GetMetricsOutput ¶
type GetMetricsOutput struct {
SessionID string `json:"session_id"`
Count int `json:"count"`
Metrics []MetricCatalogOut `json:"metrics"`
}
type GetServiceMapInput ¶
type GetServiceMapInput struct {
SessionID string `json:"session_id,omitempty" jsonschema:"session to query; defaults to the active session"`
}
type GetSpanInput ¶
type GetSpanInput struct {
SpanID string `json:"span_id" jsonschema:"the span id to fetch"`
}
type GetSpanOutput ¶
type GetSpanOutput struct {
SpanID string `json:"span_id"`
TraceID string `json:"trace_id"`
ParentSpanID string `json:"parent_span_id"`
Service string `json:"service"`
Name string `json:"name"`
Kind string `json:"kind"`
Status string `json:"status"`
StatusMessage string `json:"status_message,omitempty"`
DurationMs float64 `json:"duration_ms"`
StartUnixNs int64 `json:"start_unix_ns"`
Attributes map[string]string `json:"attributes"`
Resource map[string]string `json:"resource"`
Events []SpanEventOut `json:"events"`
Links []SpanLinkOut `json:"links"`
}
type GetStatsInput ¶
type GetStatsInput struct {
SessionID string `json:"session_id,omitempty" jsonschema:"session to query; defaults to the active session"`
}
type GetTraceInput ¶
type GetTraceOutput ¶
type GetTraceOutput struct {
TraceID string `json:"trace_id"`
SessionID string `json:"session_id"`
SpanCount int `json:"span_count"`
DurationMs float64 `json:"duration_ms"`
Waterfall string `json:"waterfall"`
Spans []TraceSpanOut `json:"spans"`
Issues []TraceIssueOut `json:"issues"`
Logs []TraceLogOut `json:"logs"`
Lint []LintOut `json:"lint"`
}
type IssueOut ¶
type IssueOut struct {
Kind string `json:"kind"`
TraceID string `json:"trace_id"`
Count int `json:"count"`
WastedMs float64 `json:"wasted_ms"`
Fingerprint string `json:"fingerprint,omitempty"`
ParentSpanID string `json:"parent_span_id,omitempty"`
ExampleSpanID string `json:"example_span_id,omitempty"`
}
type LintWarningOut ¶
type ListIssuesInput ¶
type ListIssuesOutput ¶
type ListLintInput ¶
type ListLintInput struct {
SessionID string `json:"session_id,omitempty" jsonschema:"session to query; defaults to the active session"`
TraceID string `json:"trace_id,omitempty" jsonschema:"filter to a single trace"`
Limit int `json:"limit,omitempty" jsonschema:"max warnings to return (default 200, max 500)"`
}
type ListLintOutput ¶
type ListLintOutput struct {
SessionID string `json:"session_id"`
Count int `json:"count"`
Warnings []LintWarningOut `json:"warnings"`
}
type ListServicesOutput ¶
type ListSessionsOutput ¶
type ListSessionsOutput struct {
ActiveSessionID string `json:"active_session_id"`
Count int `json:"count"`
Sessions []SessionOut `json:"sessions"`
}
type ListSlowSpansInput ¶
type ListSlowSpansOutput ¶
type ListSlowSpansOutput struct {
SessionID string `json:"session_id"`
Count int `json:"count"`
Spans []SlowSpanOut `json:"spans"`
}
type ListTracesInput ¶
type ListTracesInput struct {
SessionID string `json:"session_id,omitempty" jsonschema:"session to query; defaults to the active session"`
Service string `json:"service,omitempty" jsonschema:"filter to traces whose root span has this service.name"`
Limit int `json:"limit,omitempty" jsonschema:"max traces to return (default 50, max 200)"`
Page int `json:"page,omitempty" jsonschema:"1-based page number (default 1)"`
}
type ListTracesOutput ¶
type ListTracesOutput struct {
SessionID string `json:"session_id"`
Count int `json:"count"`
Traces []TraceSummary `json:"traces"`
}
type MetricCatalogOut ¶
type MetricPointOut ¶
type Options ¶
type Options struct {
// Version is the spaniel build version, reported in the MCP handshake and by
// get_server_info.
Version string
// AllowWrites gates registration of the mutating tools (create/activate
// session, set baseline, prune). When false, those tools are not registered
// at all — they do not appear in tools/list and cannot be called.
AllowWrites bool
}
Options configures the MCP server.
type PruneDataInput ¶
type PruneDataInput struct {
RetentionDays int `json:"retention_days,omitempty" jsonschema:"delete sessions older than N days (0 = no age limit)"`
MaxSessions int `json:"max_sessions,omitempty" jsonschema:"keep at most N sessions (0 = unlimited)"`
MaxDBSizeMB int `json:"max_db_size_mb,omitempty" jsonschema:"shrink to at most N MB on disk (0 = unlimited)"`
}
type PruneDataOutput ¶
type QueryLogsInput ¶
type QueryLogsInput struct {
SessionID string `json:"session_id,omitempty" jsonschema:"session to query; defaults to the active session"`
TraceID string `json:"trace_id,omitempty" jsonschema:"only logs correlated with this trace"`
SpanID string `json:"span_id,omitempty" jsonschema:"only logs correlated with this span"`
Service string `json:"service,omitempty" jsonschema:"only logs from this service.name"`
MinSeverity string `json:"min_severity,omitempty" jsonschema:"minimum severity: TRACE, DEBUG, INFO, WARN, ERROR, or FATAL"`
Limit int `json:"limit,omitempty" jsonschema:"max log records to return (default 100, max 1000)"`
Page int `json:"page,omitempty" jsonschema:"1-based page (ignored when service/min_severity is set)"`
}
type QueryLogsOutput ¶
type QuerySQLInput ¶
type QuerySQLOutput ¶
type SearchInput ¶
type SearchInput struct {
Query string `json:"query" jsonschema:"search text; also supports lint:<rule> and n+1 filters"`
SessionID string `json:"session_id,omitempty" jsonschema:"scope to a session; leave empty to search all sessions"`
Limit int `json:"limit,omitempty" jsonschema:"max results (default 20, max 50)"`
}
type SearchOutput ¶
type ServerInfo ¶
type ServerInfo struct {
Version string `json:"version" jsonschema:"spaniel build version"`
ActiveSessionID string `json:"active_session_id" jsonschema:"id of the session new telemetry is written to"`
ActiveSessionLabel string `json:"active_session_label" jsonschema:"human-readable label of the active session"`
WritesEnabled bool `json:"writes_enabled" jsonschema:"whether mutating tools are available (server started with --mcp-allow-writes)"`
SpanCount int `json:"span_count"`
TraceCount int `json:"trace_count"`
LogCount int `json:"log_count"`
SessionCount int `json:"session_count"`
DBSizeBytes int64 `json:"db_size_bytes"`
}
ServerInfo is the output of get_server_info.
type ServiceEdgeOut ¶
type ServiceMapOutput ¶
type ServiceMapOutput struct {
SessionID string `json:"session_id"`
Nodes []ServiceNodeOut `json:"nodes"`
Edges []ServiceEdgeOut `json:"edges"`
}
type ServiceNodeOut ¶
type SessionOut ¶
type SessionOut struct {
ID string `json:"id"`
Label string `json:"label"`
IsActive bool `json:"is_active"`
IsBaseline bool `json:"is_baseline"`
IsImported bool `json:"is_imported"`
SpanCount int `json:"span_count"`
TraceCount int `json:"trace_count"`
ErrorCount int `json:"error_count"`
N1Count int `json:"n1_count"`
P95Ms float64 `json:"p95_ms"`
CreatedAt int64 `json:"created_at"`
Note string `json:"note,omitempty"`
}
type SetBaselineInput ¶
type SlowSpanOut ¶
type SpanEventOut ¶
type SpanLinkOut ¶
type StatsOutput ¶
type StatsOutput struct {
SessionID string `json:"session_id"`
SpanCount int `json:"span_count"`
TraceCount int `json:"trace_count"`
LogCount int `json:"log_count"`
SessionCount int `json:"session_count"`
DBSizeBytes int64 `json:"db_size_bytes"`
DroppedSpans int64 `json:"dropped_spans"`
DroppedLogs int64 `json:"dropped_logs"`
DroppedMetricPoints int64 `json:"dropped_metric_points"`
}
type TraceIssueOut ¶
type TraceLogOut ¶
type TraceSpanOut ¶
type TraceSpanOut struct {
SpanID string `json:"span_id"`
ParentSpanID string `json:"parent_span_id"`
Service string `json:"service"`
Name string `json:"name"`
Kind string `json:"kind"`
Status string `json:"status"`
StatusMessage string `json:"status_message,omitempty"`
DurationMs float64 `json:"duration_ms"`
StartUnixNs int64 `json:"start_unix_ns"`
Attributes map[string]string `json:"attributes,omitempty"`
}
type TraceSummary ¶
type TraceSummary struct {
TraceID string `json:"trace_id"`
Service string `json:"service"`
RootName string `json:"root_name"`
Status string `json:"status"`
DurationMs float64 `json:"duration_ms"`
SpanCount int `json:"span_count"`
HasN1 bool `json:"has_n1"`
IssueKinds []string `json:"issue_kinds"`
StartUnixNs int64 `json:"start_unix_ns"`
}
Click to show internal directories.
Click to hide internal directories.