Skip to main content
← MCP Tools

get_context

The most powerful Travsr tool. Given a symbol name or a natural-language query, returns the most relevant context within a token budget: using Personalized PageRank (PPR) for relevance scoring and a 0-1 knapsack solver for token-budget optimisation. Natural-language queries are translated to search terms deterministically, no model or API key required.

Availability: single-repo stdio (travsr mcp) and global stdio (travsr mcp --global). Not served over SSE.

Input schema​

{
"type": "object",
"required": ["query"],
"properties": {
"query": {
"type": "string",
"description": "Symbol name or natural-language query (1-200 chars)"
},
"token_budget": {
"type": "integer",
"description": "Hard token budget (100-32000). Defaults to 4096 if omitted."
},
"include_snippets": {
"type": "boolean",
"description": "When true, appends the actual source body of each selected symbol (kind-aware, docblock-stripped). Defaults to false."
},
"snippet_budget": {
"type": "integer",
"description": "Optional separate token budget for the appended snippets. When omitted, snippets share the main token_budget."
},
"repo": {
"type": "string",
"description": "Repo name (run repos_list to discover). Only present in global (multi-repo) sessions. Always supply to avoid cross-repo noise; omit only for cross-repo queries."
}
},
"additionalProperties": false
}

There is no seed_files or seed_symbols parameter. Seeding is entirely automatic, from the query text.

Output format​

Plain text (wrapped in a <travsr-data> envelope), not JSON. It opens with two header lines: index freshness plus embedding status ([index commit: ..., embeddings: on|off|warming|degraded|disabled]), then a retrieval-quality line ([retrieval: <tier> | coverage N/M | confidence: <label>]), where the tier names the seed legs that fired (for example exact+lexical+semantic) and the confidence is exact, strong, weak, or none. Below that, one line per selected node: the label with its kind prefix, the kind spelled out in parentheses, an em-dash separator (U+2014), path:line, an optional [via: ...] tag naming how a non-seed node was reached (for example [via: caller of fn:wrap_envelope]), and [score: 0.NN]. Once the result is large enough to bucket, the lines are grouped under section headings, in this order:

  • ## exact matches, literal symbol / text (not relevance-ranked)
  • ## related, ranked by relevance
  • ## docs (documentation prose: claims about the code, verify behaviour against the code itself) (only when documentation results are enabled and match)
  • ## tests, test entry points & fixtures
  • ## relevant, graph-adjacent context

It closes with a footer ([N nodes, ~T tokens]) and, when include_snippets is true, each node's source body appended below its metadata line.

When more nodes scored above the cutoff than the budget could hold, the footer is followed by a [N more node(s) matched (score ≥ X), budget exhausted. ...] line and an indented list of the overflow nodes (label, score, path), so nothing is dropped silently. Below that, zero or more bracketed [note: ...] lines may follow, one per active condition: results cut for budget, too many seed candidates, a weak-match warning, a multi-concept cluster note, semantic embeddings still warming/disabled/degraded, or the semantic call-edge index not yet built for this repo. None of these appear when the answer is fully grounded and complete.

Example​

Request:

{
"query": "wrap_envelope",
"token_budget": 400
}

Response (from the Travsr repository, trimmed):

[index commit: 8d6d3ffa, embeddings: on]
[retrieval: exact+lexical+semantic | coverage 1/1 | confidence: strong ]
## exact matches, literal symbol / text (not relevance-ranked)
fn:wrap_envelope (function) — crates/travsr-mcp/src/sanitize.rs:138 [score: 1.00]
## related, ranked by relevance
fn:wrap (function) — crates/travsr-cli/src/faq.rs:354 [score: 0.05]
## tests, test entry points & fixtures
fn:sanitize_wraps_in_envelope_always (function) — crates/travsr-mcp/src/sanitize.rs:812 [score: 0.97]
## relevant, graph-adjacent context
fn:sanitize_for_mcp (function) — crates/travsr-mcp/src/sanitize.rs:49 [via: caller of fn:wrap_envelope] [score: 0.65]
fn:get_architecture_brief (function) — crates/travsr-mcp/src/tools.rs:3878 [via: caller of fn:wrap_envelope] [score: 0.29]
fn:truncate_to_byte_limit (function) — crates/travsr-mcp/src/sanitize.rs:96 [via: context] [score: 0.17]

[26 nodes, ~400 tokens]
[24 more node(s) matched (score ≥ 0.06), budget exhausted. Use a specific symbol name for deeper coverage, or call get_blast_radius / get_callers / get_dependencies for complete results.]
method:SqliteStore.get_meta score: 0.07 crates/travsr-store/src/lib.rs
fn:make_store score: 0.06 crates/travsr-mcp/src/tools.rs
[note: query matched more seed candidates than the cap, consider narrowing the query or calling get_context once per concept]

With include_snippets: true, each line above is followed by a separator and the node's source body.

When to use​

get_context is the tool to use when you want Travsr to decide what context is relevant. Use it:

  • At the start of a complex task when you don't know exactly which files are involved.
  • When the task touches multiple subsystems and you need a breadth-first view.
  • When you have a token budget constraint and need to maximise information density.

Use the more targeted tools (get_callers, get_dependencies, get_execution_path) when you know exactly what structural information you need.

Synonym expansion​

If synonyms are configured for the repo (via travsr synonym add or the Synonyms panel), the query text is expanded before symbol search. For example, if payment → billing, invoice is set, a query for "billing flow" will also match nodes tagged payment and invoice.

Pipeline details​

  1. Synonym expansion: expand query terms using per-repo synonym pairs.
  2. Seed selection: resolve probable symbol names from the query (exact-name, semantic/embedding, and lexical matches, fused by rank), falling back to lexical-only when embeddings are off or still warming.
  3. PPR walk: run Personalized PageRank on the full graph, restarted from the resolved seeds, to score every node by relevance.
  4. Knapsack: select the subset of scored nodes that maximises total relevance within token_budget, reporting anything cut for budget rather than silently dropping it.
  5. Snippets (optional): when include_snippets is true, append each selected node's source body up to snippet_budget.