mcp

package
v0.182.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 17, 2026 License: Apache-2.0 Imports: 19 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

View Source
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

View Source
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

func Redact(s string) string

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".

func RuntimeBase

func RuntimeBase(dataDir func() (string, error)) func() (string, error)

RuntimeBase is the daemon's origin from <data_dir>/runtime.json: always the loopback address, whatever else the daemon listens on.

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.

func (*Server) Serve

func (s *Server) Serve(ctx context.Context, in io.Reader, out io.Writer) error

Serve reads requests from in and writes responses to out until in ends or ctx is done. Requests are answered one at a time, in order; a notification (no id) is never answered.

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.

func Tools

func Tools(c *Client, cwd string) []Tool

Tools is what `caprock mcp` offers. cwd is the directory the agent started the server in: the repository a tool means when it is not given one.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL