codescope MCP tool reference

May 28, 2026 · View on GitHub

codescope serve --mcp speaks the Model Context Protocol over stdio as newline-delimited JSON-RPC 2.0 (ADR-0010). Logs go to stderr only; stdout carries protocol messages exclusively (ADR-0013).

Lifecycle

codescope serve --mcp -p /abs/path/to/repo

Supported JSON-RPC methods:

MethodPurpose
initializeHandshake. Returns protocolVersion (2024-11-05), capabilities.tools, and serverInfo {name, version}.
tools/listLists the nine cs_* tools with their JSON input schemas.
tools/callInvokes a tool by name with arguments.
pingReturns {}.

Notifications (messages without an id, e.g. notifications/initialized) receive no response.

The graph is loaded from <repo>/.codescope/index.redb once and cached for the life of the process, so every query after the first pays only the in-process cost (sub-millisecond for graph queries). Call cs_index first if the index is stale or absent.

Common conventions

  • Every query tool accepts an optional max_tokens integer (default 4000). Results are token-budgeted: when the budget is hit, output is truncated and a truncated: true flag is set instead of returning the whole graph (ADR-0011).
  • cs_callers / cs_callees accept an optional depth integer (default 3) bounding transitive traversal.
  • Tool results are returned as MCP content — a single text block whose body is compact JSON with symbol, kind, file, line_start/line_end, edge lists, and a truncated flag.

Tools

ToolRequired argsOptional argsReturns
cs_index——Index stats: files_indexed, files_skipped, files_removed, symbols, edges, elapsed_ms.
cs_callerssymboldepth, max_tokensSymbols that transitively call symbol.
cs_calleessymboldepth, max_tokensSymbols symbol transitively calls.
cs_blast_radiustargetmax_tokensEverything downstream-affected if target (symbol name or file path) changes.
cs_definitionsymbolmax_tokensWhere symbol is defined.
cs_referencessymbolmax_tokensAll references to symbol.
cs_dependency_graph—max_tokensFile/module import graph with cycle detection.
cs_structural_searchquerymax_tokensStructural matches (see query syntax below).
cs_repo_summary—max_tokensToken-bounded architectural overview to read before editing.

Space-separated terms. key:value are filters; bare words match the symbol name/signature.

  • kind:function|method|struct|enum|trait|interface|class|module|type|constant|field
  • lang:rust|typescript|javascript|python|go
  • file:<substr> · name:<substr> · calls:<callee> · returns:<type-substr>

Example: kind:method lang:rust calls:spawn returns:Result

Examples

Handshake:

{"jsonrpc":"2.0","id":1,"method":"initialize","params":{}}

List tools:

{"jsonrpc":"2.0","id":2,"method":"tools/list"}

Build the index:

{"jsonrpc":"2.0","id":3,"method":"tools/call","params":{"name":"cs_index","arguments":{}}}

Who calls build_index, two levels deep:

{"jsonrpc":"2.0","id":4,"method":"tools/call",
 "params":{"name":"cs_callers","arguments":{"symbol":"build_index","depth":2}}}

Blast radius of a file under a tight token budget:

{"jsonrpc":"2.0","id":5,"method":"tools/call",
 "params":{"name":"cs_blast_radius","arguments":{"target":"src/store.rs","max_tokens":1500}}}

Error responses

Errors use standard JSON-RPC error objects:

CodeMeaning
-32601Method not found.
-32602Invalid params (missing tool name, missing required argument, or unknown tool).
-32000Server error (e.g. index not loaded — run cs_index first).