Skip to main content
← MCP Tools

get_snippets

Return tailored code snippets for one or more symbols by name, without opening files. Use it after any graph-navigation tool (get_context, get_callers, search_symbol) to read the actual implementation of the symbols those tools surfaced.

Extraction is kind-aware in the default auto mode:

  • Functions / methods up to 40 lines.
  • Classes / structs / impls up to 15 lines (header and fields only).
  • Interfaces / traits / enums up to 60 lines.
  • An overflowing definition falls back to a condensed structural outline (skeleton) instead of a truncated body.

Leading docblocks are stripped, and symbols are included in request order until the token budget is reached (the first symbol is always included, even if it alone exceeds the budget).

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

Input schema​

{
"type": "object",
"properties": {
"symbols": {
"type": "string",
"description": "Newline- or comma-separated list of symbol names (e.g. 'PaymentService.charge\\nMAX_RETRIES'). Partial matches accepted, the closest matching non-file symbol is used for each name."
},
"token_budget": {
"type": "integer",
"description": "Hard token cap across all returned snippets. Default: 2000. Higher values return more symbols."
},
"mode": {
"type": "string",
"enum": ["auto", "full", "skeleton"],
"description": "Representation per symbol. 'auto' (default): raw body if within the kind line-cap, else a condensed structural outline. 'full': complete definition, no line cap. 'skeleton': structural outline only (signatures, no bodies)."
},
"path": {
"type": "string",
"description": "Optional path hint to scope an overloaded bare name to a file or directory: a filename, a relative path, a directory prefix, or a path fragment (e.g. rerank.rs, src/rerank.rs, crates/travsr-mcp, retrieval). Applies to bare-name symbols; names already pinned by full header or path:line are unaffected."
},
"repo": {
"type": "string",
"description": "Restrict to a specific registered repo by name (global / multi-repo mode only)."
}
},
"required": ["symbols"],
"additionalProperties": false
}

Output format​

Plain text (wrapped in a <travsr-data> envelope), not JSON. One block per resolved symbol, in request order, separated by a blank line. Each block starts with a header line: the label with its kind prefix (fn:, method:, ...), the kind spelled out in parentheses, an em-dash separator (U+2014), the file path, and a [package: name] tag (empty, [package: ], when the node has no package), with a staleness marker appended if the source file has changed since the graph was last indexed. Then comes a separator line of box-drawing characters (───), then the extracted code. Because the response is sanitised, < and > in the code come back HTML-escaped as &lt; and &gt;, so unescape them before treating the body as source. A symbol that could not be read from disk gets the header line only, with no separator or body. The response ends with a summary footer: [N symbols, M with snippets, ~T tokens].

A name that resolved to nothing no longer vanishes silently: each one gets a [note: no symbol matched '<name>'] line, once per name even if you repeated it. A request that names the same definition twice renders one block, so the footer count stays honest.

With path, a single bare name is hard-scoped to the hint. If nothing matches under it, the note says no symbol matched '<name>' under path hint '<hint>'; it exists outside that path, so a stale hint is not read as a missing symbol. With several names the hint is a per-name filter: a name absent under the hint keeps its matches from elsewhere and the result notes that the hint was skipped for it.

A few inputs return a single plain-text line instead of the block format above: No symbols matching the provided names found in the graph. when none of the requested names resolve, and Token budget too small to include any symbols. when even the first (always-included) symbol's header does not fit.

Example​

Request:

{ "symbols": "wrap_envelope" }

Response (from the Travsr repository):

fn:wrap_envelope (function) — crates/travsr-mcp/src/sanitize.rs [package: ]
───
pub(crate) fn wrap_envelope(content: &str) -&gt; String {
if content.is_empty() {
"&lt;travsr-data&gt;&lt;/travsr-data&gt;".to_string()
} else {
format!("&lt;travsr-data&gt;\n{content}\n&lt;/travsr-data&gt;")
}
}

[1 symbols, 1 with snippets, ~73 tokens]

When to use​

  • Read implementations cheaply: after get_context or get_callers returns symbol names, fetch their code in one call instead of multiple file reads.
  • Stay inside a token budget: the budget cap keeps the payload bounded so it is safe to pass straight into LLM context.

Notes​

  • Each requested name resolves to the closest matching non-file symbol.
  • If the index predates snippet support (no repo_root recorded), the tool returns a one-line hint to run travsr init instead of a snippet body.