Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

MCP tools

Castellan exposes a progressive-disclosure MCP surface: meta-tools for discovery, compact listings in tools/list, and full schemas on demand via castellan_describe_tool.

Registry: crates/castellan-runtime/src/mcp/registry.rs
Stdio server: castellan mcp
Live episodes: castellan run --mcpCastellanEngine::call_mcp_tool

Discovery flow

flowchart LR
    A[Agent starts] --> B[discover / search tools]
    B --> C[describe_tool]
    C --> D[Invoke tool]
    D --> E[Governance + trace]

    classDef runtime stroke:#0969da,stroke-width:2px
    classDef substrate stroke:#8250df,stroke-width:2px
    classDef gate stroke:#1a7f37,stroke-width:2px

    class A,B runtime
    class C,D substrate
    class E gate
  1. Discovercastellan_discover_tools returns domain-indexed tool cards (no full schemas).
  2. Searchcastellan_search_tools with query (and optional domain) narrows by intent. Results are BM25-ranked over tool name, summary, description, and domain; when no whole term matches (partial words), substring matching kicks in. The response reports which via "ranking": "bm25" | "substring".
  3. Describecastellan_describe_tool with name returns full schema, preconditions, side effects, examples.
  4. Invoketools/call or live mcp_tools observation payload.

Meta-tools are always listed with full schemas. Operational tools in tools/list use compact cards (call castellan_describe_tool for parameters).

Error responses

Discovery tools return "ok": false with stable error codes. Stdio server maps to JSON-RPC -32601 (not found) / -32602 (invalid params). Search queries are capped at 256 characters.

Meta tools

ToolDomainPurpose
castellan_discover_toolsmetaBrowse domains and tool names
castellan_search_toolsmetaBM25-ranked search over catalog
castellan_describe_toolmetaFull ToolSpec for one tool

Operational tools

ToolDomainSummaryLive (--mcp)Governance
castellan_deposit_signalsubstrateDeposit pheromone into zoneYespre/post hooks
castellan_read_signalsubstrateRead signal strengthYesread-only
castellan_read_blackboardsubstrateRead blackboard slotYesread-only
castellan_topology_snapshotsubstrateHarness topology JSONYesread-only
castellan_metricssubstrateSession countersYesread-only
castellan_multiplexer_statusmultiplexerDashboard statusline snapshotYesread-only
castellan_propose_mutationevolvePreview harness mutation (diff + drift); does not applyYespreview-only
castellan_resolve_mutationevolveAccept or reject a persisted proposalYeshigh-impact gate
castellan_read_resourcesubstrateResolve typed URI (episode://, genome://, pane://, blackboard://)Yesread-only
castellan_recallmemoryRecall durable memory by keyYesread-only
castellan_remembermemoryStore durable memory entryYespre/post hooks
castellan_query_field_historysubstrateQuery pressure-field historyYesread-only

All operational tools are in LIVE_TOOL_NAMES for castellan run --mcp.

Start the server

castellan mcp

Wire your MCP client to stdin/stdout JSON-RPC. Cursor config example in Cursor setup.

Example: discovery sequence

{"name": "castellan_search_tools", "arguments": {"query": "deposit", "domain": "substrate"}}
{"name": "castellan_describe_tool", "arguments": {"name": "castellan_deposit_signal"}}
{"name": "castellan_deposit_signal", "arguments": {"zone": "grid", "signal": "coordination", "amount": 2.0}}

Example: live episode

Observation payload for castellan run --goal "..." --plugin gridworld --mcp:

{
  "mcp_tools": [
    {
      "tool": "castellan_deposit_signal",
      "args": { "zone": "grid", "signal": "coordination", "amount": 2.0 }
    }
  ]
}

Trace JSONL emits mcp_discovery for meta-tools and mcp_tool for operational calls. Governance pre/post hooks apply on the hot path.

Design principles

PrincipleImplementation
Progressive discoveryMeta-tools before full schemas
Context efficiencyCompact tools/list for operational tools
Live paritySame registry for castellan mcp and castellan run --mcp
Description qualitySummary + preconditions + side effects per tool

Adding a tool

  1. Add ToolSpec in registry.rs and register in all_tool_specs().
  2. Add handler in handlers.rs and route in call_tool_with_registry.
  3. Add name to LIVE_TOOL_NAMES if live episodes should expose it.
  4. Update this page and run cargo test -p castellan-runtime.

See also MCP overview and Agent guide.