Skip to main content
MCP Tools

get_context

The most powerful Travsr tool. Given a natural language query, returns the optimal subgraph for answering it: using Personalized PageRank (PPR) for relevance scoring and 0-1 Knapsack for token-budget optimisation.

Input schema

{
"type": "object",
"required": ["query"],
"properties": {
"query": {
"type": "string",
"description": "Natural language description of what context is needed."
},
"token_budget": {
"type": "integer",
"default": 4000,
"minimum": 500,
"maximum": 32000,
"description": "Maximum tokens to return. The knapsack solver maximises relevance within this budget."
},
"seed_files": {
"type": "array",
"items": { "type": "string" },
"description": "Optional list of files to seed the PPR walk from. If omitted, seeds are inferred from the query via symbol search."
},
"seed_symbols": {
"type": "array",
"items": { "type": "string" },
"description": "Optional list of symbols to seed the PPR walk from."
},
"repo": { "type": "string" }
}
}

Output schema

{
"type": "object",
"properties": {
"query": { "type": "string" },
"nodes": {
"type": "array",
"items": {
"type": "object",
"properties": {
"path": { "type": "string" },
"symbol": { "type": "string" },
"kind": { "type": "string" },
"ppr_score": { "type": "number" },
"tokens": { "type": "integer" },
"snippet": { "type": "string" }
}
}
},
"tokens_used": { "type": "integer" },
"token_budget": { "type": "integer" },
"seed_nodes": { "type": "array", "items": { "type": "string" } }
}
}

Example

Request:

{
"query": "How does the authentication flow work from login to session creation?",
"token_budget": 3000
}

Response:

{
"query": "How does the authentication flow work from login to session creation?",
"tokens_used": 2847,
"token_budget": 3000,
"seed_nodes": ["src/routes/auth.ts#login", "src/services/SessionService.ts"],
"nodes": [
{
"path": "src/routes/auth.ts",
"symbol": "login",
"kind": "function",
"ppr_score": 0.94,
"tokens": 312,
"snippet": "export async function login(req: Request, res: Response) {\n const { email, password } = req.body;\n ..."
},
{
"path": "src/controllers/AuthController.ts",
"symbol": "AuthController.login",
"kind": "method",
"ppr_score": 0.88,
"tokens": 445,
"snippet": "async login(credentials: Credentials): Promise<Session> {\n const user = await this.userService.findByEmail(...);\n ..."
}
]
}

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. Symbol search: extract probable symbol names from the expanded query and call search_symbol.
  3. PPR seeding: use the matched symbols + seed_files / seed_symbols as PPR restart nodes.
  4. PPR walk: run Personalized PageRank on the full graph to score all nodes by relevance.
  5. PCST extraction: extract the minimum connected subgraph of high-scored nodes.
  6. Knapsack: select the subset of extracted nodes that maximises total PPR score within token_budget.