Documentation
¶
Overview ¶
Package mcp is `caprock mcp`: a read-only Model Context Protocol server on stdio, so the user's own coding agents (Claude Code, Codex, any MCP client) can ask Caprock what it knows — Second Brain, recent sessions and the prose written in them, cost per repository and day, CI, loop alerts (ADR-078; contract in .ai/03-contracts.md § MCP server).
It opens no listener. Each tool call is answered from the local daemon's loopback HTTP API, read-only (GET) endpoints only, and the answer is trimmed and passed through Redact before it reaches the agent. Nothing it exposes can type into a session, start or stop one, or change a setting.
The protocol is JSON-RPC 2.0, one message per line (MCP's stdio transport): initialize, ping, tools/list and tools/call. The official Go SDK was not taken: four methods do not justify a dependency tree in a binary whose moat is being small (ADR-078).
Index ¶
Constants ¶
const DefaultMaxText = 48 << 10
DefaultMaxText is the cap on one tool result's text: enough for a page of sessions or memories, small enough not to flood an agent's context.
Variables ¶
var ErrNotRunning = errors.New("caprock is not running on this computer: start it with `caprock up`, or open the Caprock app, then ask again")
ErrNotRunning is every tool's answer while no daemon is up: the agent should tell the user, not retry.
Functions ¶
Types ¶
type Client ¶
type Client struct {
// Base returns the daemon's origin ("http://127.0.0.1:22776"). Read on
// every call, so a daemon started or restarted after the agent is found.
Base func() (string, error)
HTTP *http.Client
}
Client reads the local daemon's API. Only GET is offered: a tool cannot reach an endpoint that changes anything, whatever its arguments say.
type Server ¶
type Server struct {
Name string
Version string
// Instructions is the line a client may show its model about the server.
Instructions string
Tools []Tool
// MaxText bounds a tool result's text, in bytes; 0 is DefaultMaxText.
MaxText int
}
Server is an MCP server over one stream pair.
type Tool ¶
type Tool struct {
Name string
Title string
Description string
// Schema is the JSON Schema of its arguments (an object).
Schema map[string]any
// OpenWorld says the answer may involve a service outside this computer
// (GitHub, for CI), which the user switched on in Caprock.
OpenWorld bool
// Call answers it. A returned error is shown to the agent as the tool's
// failure (isError), not as a protocol error.
Call func(ctx context.Context, args json.RawMessage) (any, error)
}
Tool is one tool the server offers.