Documentation
¶
Overview ¶
Package mcp is a minimal Model Context Protocol server over the stdio transport (newline-delimited JSON-RPC 2.0) — enough to expose RunLore tools to MCP clients such as HolmesGPT, kagent, or Claude Desktop. It implements initialize, tools/list, tools/call, and ping; tool handlers return plain text. Deliberately dependency-free (no SDK) to keep the single static binary.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func SanitizeName ¶ added in v0.3.0
SanitizeName makes a server/tool name safe for the model-facing tool name: lowercase, non-alphanumeric runs collapsed to a single underscore, trimmed.
Types ¶
type Adapter ¶ added in v0.3.0
type Adapter struct {
// contains filtered or unexported fields
}
Adapter adapts a remote MCP tool to the investigate.Tool contract (satisfied structurally — this package does not import internal/investigate).
func NewTool ¶ added in v0.3.0
func NewTool(c *Client, rt RemoteTool) *Adapter
NewTool builds an adapter for one discovered remote tool, namespaced by server. The returned *Adapter satisfies the investigate.Tool contract structurally.
func (*Adapter) Description ¶ added in v0.3.0
Description returns the bounded, sanitized description with a provenance prefix.
type Client ¶ added in v0.3.0
type Client struct {
// contains filtered or unexported fields
}
Client is a minimal streamable-HTTP MCP client. It speaks JSON-RPC 2.0 over a single POST endpoint, handling both a JSON and an SSE response, and carries the server's session id (if any) across requests. All HTTP goes through httpx.SecureClient so the SSRF guard and cross-host key-stripping apply.
func NewClient ¶ added in v0.3.0
NewClient builds an MCP client for a server. A nil logger discards logs.
func (*Client) CallTool ¶ added in v0.3.0
CallTool invokes a remote tool and returns its concatenated text content. An MCP tool error (isError) or a JSON-RPC error becomes a Go error.
tools/call is NOT retried (attempts=1): remote MCP tools may have side effects, and retrying a side-effecting call on a transient 5xx could double-invoke it. A 5xx here becomes an error that the investigation loop surfaces as a tool error; the model may choose to call again explicitly.
func (*Client) Initialize ¶ added in v0.3.0
Initialize performs the MCP handshake: initialize (capturing any session id) then the notifications/initialized notification. Retries up to 3 times on transient failures.
type RemoteTool ¶ added in v0.3.0
type RemoteTool struct {
Name string `json:"name"`
Description string `json:"description"`
InputSchema json.RawMessage `json:"inputSchema"`
}
RemoteTool is a tool advertised by an MCP server's tools/list.
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server is a minimal MCP server. Construct with NewServer, AddTool, then Serve.
func NewServer ¶
NewServer creates a server advertising name/version. A nil logger discards logs (logs MUST NOT go to the stdout MCP channel — pass a stderr logger).
func (*Server) AddTool ¶
AddTool registers (or replaces) a tool, preserving first-seen order for tools/list.
func (*Server) Serve ¶
Serve reads newline-delimited JSON-RPC requests from in and writes one response line per request to out, until in is exhausted or ctx is cancelled. Notifications (no id) get no response. json.Encoder writes compact, single-line JSON + a newline — exactly the stdio framing MCP expects.
type Tool ¶
type Tool struct {
Name string
Description string
InputSchema json.RawMessage
Handler func(ctx context.Context, args json.RawMessage) (string, error)
}
Tool is an MCP tool: a name, a description, a JSON-Schema for its arguments, and a handler returning text (an error is surfaced to the client as an MCP tool error).