Documentation
¶
Overview ¶
Package mcp is `caprock mcp`: a 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, plus the one write of the neighbours (ADR-123): a short message left for another live session in the same checkout, and reading one's own — and the answer is trimmed and passed through Redact before it reaches the agent. Nothing it exposes can start or stop a session or change a setting, and nothing types into a process Caprock did not start: a neighbour's message reaches a session at its own hooks, and is typed in only at the prompt of one Caprock started, through the message queue the chat field uses (rule 7).
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 ContractVersion = 1
ContractVersion is the version of Caprock's own contract on top of MCP: the tool names, arguments and answer keys in testdata/contract.json (ADR-116). It is sent as serverInfo.contract_version. It goes up only when a deprecated tool, argument or key is finally removed, never for an addition, so a consumer that checks it learns about a removal before it reads a key that is gone.
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 ¶
func Redact ¶
Redact replaces credentials and payment details in s with a placeholder naming each ("[redacted: api key]"). A session's prose or a memory can quote one (an agent echoing a key it was handed), and an MCP answer lands in another agent's context — possibly another vendor's model — so these never leave in a tool result. The shapes are internal/redact's, the same filter Second Brain runs before it saves a memory; the honest promise is "keys that look like keys".
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. GET is offered for every path; the one write is post, which reaches only the neighbours' two routes (postPaths, ADR-123): a tool cannot reach any other 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
// Writes marks the one kind of tool that changes anything: a message
// left for another live session (ADR-123). It is announced as not
// read-only and not idempotent.
Writes 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.