Skip to main content

MCP Tools Reference

All Batho MCP tools return dual output:

  • content — Compact markdown for the AI model (token-optimized)
  • structuredContent — Full JSON for programmatic consumers

All graph tools accept repo as an optional parameter. If omitted, the first registered repo is used. Use list_repos to see available repos.


list_repos​

List all registered repos with artifact status and entity counts.

Parameters​

None.

Example​

list_repos()

Output​

Markdown:

## Registered Repos

- **frontend** — /projects/frontend (✓ ready, 892 entities)
- **backend** — /projects/backend (✓ ready, 650 entities)

JSON:

{
"repos": [
{"name": "frontend", "path": "/projects/frontend", "has_artifact": true, "entity_count": 892},
{"name": "backend", "path": "/projects/backend", "has_artifact": true, "entity_count": 650}
],
"total": 2
}

add_repo​

Register a repository in the Batho MCP registry. The repo must have a .batho artifact (run batho build first).

Parameters​

ParameterTypeRequiredDefaultDescription
namestringYes—Repo name (unique identifier in registry)
pathstringYes—Absolute path to the repository root

Example​

add_repo(name="myapp", path="/projects/myapp")

Output​

Markdown:

## Repo Registered

- **myapp** — /projects/myapp
- Entities: 892
- Artifact: ✓ ready

JSON:

{"name": "myapp", "path": "/projects/myapp", "entity_count": 892, "has_artifact": true}

remove_repo​

Remove a repository from the Batho MCP registry.

Parameters​

ParameterTypeRequiredDefaultDescription
namestringYes—Repo name to remove

Example​

remove_repo(name="myapp")

Output​

Markdown:

## Repo Removed

- **myapp** — removed from registry

JSON:

{"name": "myapp", "removed": true}

graph_overview​

Get a high-level overview of the codebase: entity counts, relationship breakdown, file list, and community summaries.

Parameters​

ParameterTypeRequiredDefaultDescription
repostringNoRegistry defaultRepo name from registry
response_formatstringNo"summary"Output detail level: summary, concise, detailed
max_tokensintNo25000Token budget for markdown output

Example​

graph_overview(repo="myapp", response_format="summary")

Output​

Markdown (content):

# Codebase Overview

**Stats:** 1542 entities, 4823 relationships, 312 files
**Run:** abc-123 | commit: a1b2c3d | branch: main

## Entity Breakdown
- function: 892
- class: 124
- method: 387

## Communities
1. **UserService** — 45 entities across 8 files
2. **ApiClient** — 32 entities across 5 files

JSON (structuredContent):

{
"overview": {
"stats": {
"total_entities": 1542,
"total_relationships": 4823,
"total_files": 312,
"entity_breakdown": {"function": 892, "class": 124},
"relationship_breakdown": {"calls": 2100, "imports": 1800},
"run_id": "abc-123",
"git_commit": "a1b2c3d"
},
"communities": [...]
},
"meta": {
"artifact_generation": 3,
"tokens_used": 1840,
"token_budget": 25000,
"truncated": false
}
}

graph_query​

Query the code graph with optional filters. Returns paginated nodes and edges.

Parameters​

ParameterTypeRequiredDefaultDescription
repostringNoRegistry defaultRepo name from registry
file_pathstringNo—Filter entities by file path
entity_typeslist[string]No—Filter by entity type (e.g., ["function", "class"])
relation_typeslist[string]No—Filter relationships by type
name_patternstringNo—Regex pattern to match entity names
response_formatstringNo"concise"Output format: concise, detailed
limitintNo50Max entities to return
offsetintNo0Pagination offset
max_tokensintNo25000Token budget

Example​

graph_query(repo="myapp", file_path="src/auth/", entity_types=["function"], limit=20)

Output​

Returns nodes (entities) and edges (relationships) matching the filters, with pagination metadata in structuredContent.


get_entity​

Get detailed information about a single entity, including its relationships and optionally source code.

Parameters​

ParameterTypeRequiredDefaultDescription
entity_idstringYes—Entity ID from previous query results
repostringNoRegistry defaultRepo name from registry
include_sourceboolNofalseInclude source code snippet
response_formatstringNo"detailed"Output format

Example​

get_entity(entity_id="src/auth.py:AuthManager.validate_token", repo="myapp", include_source=true)

Output​

Returns the entity's metadata (name, type, file, line range), all relationships where it appears as source or target, and optionally the source code from storage_views.


trace_path​

Find the shortest path between two entities in the code graph using BFS traversal.

Parameters​

ParameterTypeRequiredDefaultDescription
source_entity_idstringYes—Starting entity ID
target_entity_idstringYes—Target entity ID
repostringNoRegistry defaultRepo name from registry
max_depthintNo5Maximum BFS depth (hops)
relation_typeslist[string]No—Only traverse these relationship types
response_formatstringNo"concise"Output format

Example​

trace_path(
source_entity_id="api.routes.login.handle_login",
target_entity_id="auth.SessionHandler.create",
repo="myapp",
max_depth=10
)

Output​

Markdown:

## Path Trace
handle_login
→ [CALLS] AuthManager.validate_token
→ [CALLS] SessionHandler.create

Depth: 3 hops

JSON:

{
"path": [
{"entity_id": "api.routes.login.handle_login", "relation_type": "", "name": "handle_login"},
{"entity_id": "auth.AuthManager.validate_token", "relation_type": "CALLS", "name": "validate_token"},
{"entity_id": "auth.SessionHandler.create", "relation_type": "CALLS", "name": "create"}
],
"depth": 2,
"meta": {"artifact_generation": 3}
}

get_file_graph​

Get all entities and relationships within a single file. Optionally includes cross-file reference stubs.

Parameters​

ParameterTypeRequiredDefaultDescription
file_pathstringYes—File path relative to repo root
repostringNoRegistry defaultRepo name from registry
include_cross_file_refsboolNotrueInclude entities referenced from other files
response_formatstringNo"concise"Output format
max_tokensintNo25000Token budget

Example​

get_file_graph(file_path="src/auth/manager.py", repo="myapp", include_cross_file_refs=true)

Output​

Returns all entities defined in the file, all relationships within the file, and stub entities for cross-file references (when include_cross_file_refs is true).


search_entities​

Search for entities by name using substring or regex matching.

Parameters​

ParameterTypeRequiredDefaultDescription
querystringYes—Search query (substring or regex)
repostringNoRegistry defaultRepo name from registry
entity_typeslist[string]No—Filter by entity type
limitintNo25Max results to return
response_formatstringNo"concise"Output format

Example​

search_entities(query="validate", repo="myapp", entity_types=["function"], limit=10)

Output​

Markdown:

## Search Results (8 matches, showing 8)
- validate_token [function] src/auth/manager.py:L45-62
- validate_session [function] src/auth/session.py:L12-28
- validate_input [function] src/api/middleware.py:L8-20
...

get_delta​

Get incremental changes from the latest patch run (or a specific run). Shows added, removed, modified, and renamed nodes.

Parameters​

ParameterTypeRequiredDefaultDescription
repostringNoRegistry defaultRepo name from registry
run_idstringNoLatest patchSpecific run UUID
change_kindstringNoAllFilter: added, removed, modified, renamed
file_pathstringNoAllFilter changes by file path
limitintNo100Max changes to return
offsetintNo0Pagination offset
response_formatstringNo"concise"Output format

Example​

get_delta(repo="myapp", change_kind="added", limit=20)

Output​

Returns node-level changes (entity name, change kind, file path, line range), delta stats (nodes added/removed/modified/renamed), and run metadata (git commit, branch, duration).


Response Formats​

FormatToken EfficiencyUse Case
summaryMost compactCodebase orientation, architecture overview
conciseBalancedGeneral queries, search results, file graphs
detailedMost verboseDeep dives with source code, full metadata

Token Budgeting​

All tools accept max_tokens (default: 25,000). When output exceeds the budget:

  1. Markdown is truncated with a [truncated] marker
  2. structuredContent.meta.truncated is set to true
  3. Pagination hints are included for follow-up queries

Token estimation uses a len(text) / 4 heuristic (approximately 4 characters per token).

Error Handling​

Errors return a ToolResult with:

  • content: Error: <message> in plain text (plus an optional Hint: <hint> on a new line).
  • structuredContent: A JSON object containing:
    {
    "error": true,
    "error_type": "CLIENT_ERROR",
    "message": "Error details",
    "retryable": false,
    "hint": "Actionable hint"
    }

Common errors:

  • No Batho artifact found at <path>. Run 'batho build' first.
  • No repos registered. Use add_repo to register a repo.
  • Repo '<name>' not found in registry. Available repos: [...]
  • File not indexed: <path>
  • Entity not found: <entity_id>
  • No patch runs found. Run 'batho patch' first.