CARLOS rastrillo docs

🤖 mcp

amadan.net/rastrillo/rastrillo/mcp

An app's operations as MCP tools, behind the JSON API's gate. MCP is the guide: mounting, connecting a client, and writing descriptors by hand.

New and Config

func New(config Config, descriptors ...op.Descriptor) (http.Handler, error)

type Config struct {
	Gate          api.Gate
	Ctx           func(*http.Request) *rastrillo.Ctx
	Authorize     func(ctx context.Context, actor rastrillo.Actor, operation rastrillo.Operation) error
	Guard         op.ResponseGuard
	Guarded       bool
	Name, Version string
	Instructions  string
	MaxResult     int
}

New builds the MCP endpoint, with one tool per descriptor. Mount it at /api/v1/mcp.

Gate is the API tree's, from api.Config.Gate(). Ctx builds the app's Ctx for a request, and MCP sets Actor and Authorize on a copy of it. Authorize is required: pass op.DefaultPolicy to keep the default. Guard checks what an answer discloses as it goes out, and Guarded requires one. Name and Version are the server's in the MCP handshake. Instructions follows the framework's own instructions to the agent. MaxResult caps one tool result in bytes; zero or less means 2 MiB.

New returns an error when:

The handler runs every request behind Gate.Wrap, so a missing or bad token gets the API's 401 or 503, and every answer has Cache-Control: no-store. Then:

New raises Gate.MaxResponse, when it is lower, to three times MaxResult plus 64 KiB. A result goes out twice, as structuredContent and as the text block, and escaping can make the text longer.

ToolName

func ToolName(id string) string

The tool an operation is served as: bookmarks.create is bookmarks_create.

Read this page as markdown — exact, unstyled, and cheap for an agent to fetch.