Documentation
¶
Overview ¶
Package mcp implements the HTTP Streamable MCP (Model Context Protocol) server over JSON-RPC 2.0 with SSE streaming, allowing any AI agent (Claude, GPT, Cursor, etc.) to discover and call OtelContext tools natively.
Index ¶
- Constants
- type ClientInfo
- type ContentItem
- type InitializeParams
- type InitializeResult
- type InputSchema
- type JSONRPCRequest
- type JSONRPCResponse
- type Property
- type RPCError
- type Resource
- type SSEEvent
- type Server
- func (s *Server) Handler() http.Handler
- func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request)
- func (s *Server) SetCacheTTL(d time.Duration)
- func (s *Server) SetCallLimit(maxConcurrent int)
- func (s *Server) SetCallTimeout(d time.Duration)
- func (s *Server) SetDefaultTenant(t string)
- func (s *Server) SetGraphRAG(g *graphrag.GraphRAG)
- func (s *Server) Stats() Stats
- type ServerInfo
- type Stats
- type Tool
- type ToolCallParams
- type ToolCallResult
- type ToolsListResult
Constants ¶
const ( // ErrServerOverloaded is the JSON-RPC error code we surface when the // server-wide concurrency cap is exceeded. JSON-RPC reserves -32000 // to -32099 for server errors; we pick a stable code in that band so // agent clients can detect-and-back-off deterministically. ErrServerOverloaded = -32000 // ErrCallTimeout is the JSON-RPC error code returned when a tool // invocation runs past defaultCallTimeout. ErrCallTimeout = -32001 )
const ( ErrParseError = -32700 ErrInvalidRequest = -32600 ErrMethodNotFound = -32601 ErrInvalidParams = -32602 ErrInternalError = -32603 )
Standard JSON-RPC error codes.
const MaxToolResponseBytes = 4 * 1024 * 1024
MaxToolResponseBytes caps the rendered length of any tool response. Without this, get_trace / get_graph_snapshot / correlated_signals can produce 100MB+ JSON on adversarial input, OOM the process, and stall every concurrent MCP call until MCP_CALL_TIMEOUT_MS fires.
The cap is intentionally set well above any legitimate row-capped tool response (search_logs at 200 rows is typically <1 MB) so it triggers only on pathological cases. Operators hitting it should narrow their query time range or use pagination.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ClientInfo ¶
type ContentItem ¶
type InitializeParams ¶
type InitializeParams struct {
ProtocolVersion string `json:"protocolVersion"`
Capabilities map[string]any `json:"capabilities"`
ClientInfo ClientInfo `json:"clientInfo"`
}
type InitializeResult ¶
type InitializeResult struct {
ProtocolVersion string `json:"protocolVersion"`
Capabilities map[string]any `json:"capabilities"`
ServerInfo ServerInfo `json:"serverInfo"`
}
type InputSchema ¶
type JSONRPCRequest ¶
type JSONRPCResponse ¶
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server is the HTTP Streamable MCP server. POST /mcp — JSON-RPC 2.0 request/response GET /mcp — SSE stream for real-time notifications OPTIONS /mcp — CORS preflight
func New ¶
func New( defaultTenant string, repo *storage.Repository, metrics *telemetry.Metrics, svcGraph *graph.Graph, vectorIdx *vectordb.Index, ) *Server
New creates a new MCP server. defaultTenant is the fallback tenant applied to header-less MCP requests; an empty string falls back to storage.DefaultTenantID. Required at construction time so production startup cannot accidentally drop cfg.DefaultTenant — a missing argument is a compile error rather than a silent regression.
func (*Server) Handler ¶
Handler returns an http.Handler for the MCP server with CORS applied. Works correctly when mounted with http.StripPrefix.
func (*Server) ServeHTTP ¶
func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request)
ServeHTTP dispatches by HTTP method — no path routing needed.
func (*Server) SetCacheTTL ¶
SetCacheTTL overrides the result-cache lifetime. <= 0 disables caching for the whitelisted GraphRAG tools.
func (*Server) SetCallLimit ¶
SetCallLimit configures the maximum number of concurrent tools/call invocations. <= 0 disables the cap (legacy behavior).
Startup-only: this swaps the underlying channel reference without quiescing in-flight callers. An already-running call will release into the OLD channel when it completes, leaving the NEW semaphore one slot short until process restart. Call exactly once during construction (main.go does); never from a request-handling goroutine.
func (*Server) SetCallTimeout ¶
SetCallTimeout overrides the per-invocation deadline. A zero or negative value disables the timeout (handlers run until they return on their own).
func (*Server) SetDefaultTenant ¶
SetDefaultTenant overrides the fallback tenant at runtime. Empty strings are ignored so callers can pass through optional config without clobbering the constructor-provided value.
func (*Server) SetGraphRAG ¶
SetGraphRAG wires the GraphRAG instance for advanced query tools.
type ServerInfo ¶
type Stats ¶
type Stats struct {
InFlight int64
CallsServiced int64
CacheHits int64
Overloaded int64
TimedOut int64
CacheSize int
}
Stats returns counters used by tests and observability.
type Tool ¶
type Tool struct {
Name string `json:"name"`
Description string `json:"description"`
InputSchema InputSchema `json:"inputSchema"`
}
type ToolCallParams ¶
type ToolCallResult ¶
type ToolCallResult struct {
Content []ContentItem `json:"content"`
IsError bool `json:"isError,omitempty"`
}
type ToolsListResult ¶
type ToolsListResult struct {
Tools []Tool `json:"tools"`
}