Skip to main content
Glama

extract_relevant_context

Extract and package only the code files most relevant to a given task or bug report using semantic ranking, within a token budget. Read-only operation with secret redaction, returns formatted Markdown.

Instructions

Performs semantic relevance ranking to extract and package code files pertinent to a specific user coding task or bug report within a token budget.

Behavior: Read-only operation. Zero file modifications, zero persistent side-effects, and zero network calls. Applies automatic secret redaction. Returns formatted Markdown.

When to use: Use this when given a specific feature request, issue, or debugging objective to gather only the essential source code.

When NOT to use: Do NOT use this for full-repository structural overviews (use get_codebase_map instead), or to inspect single file outlines (use read_file_outline instead).

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
queryYesNatural language task description, bug report, or feature prompt used for semantic and citation-based file scoring.
rootDirNoPath to repository root directory. Defaults to current working directory (".").
maxTokensNoMaximum token budget ceiling (1,000 to 128,000; default: 40000). Files with highest relevance scores are packed first until budget is exhausted.

Schema Changelog

Changes observed during successful MCP inspections.

  1. Changed3 schema fields changedv1.2.0
    • changedInput schema / properties / maxTokens / description
      Previous value: -"Token budget ceiling (default: 40000)"New value: +"Maximum token budget ceiling (1,000 to 128,000; default: 40000). Files with highest relevance scores are packed first until budget is exhausted."
    • changedInput schema / properties / query / description
      Previous value: -"Task description or coding prompt (e.g., \"Fix JWT authentication token expiration error\")"New value: +"Natural language task description, bug report, or feature prompt used for semantic and citation-based file scoring."
    • changedInput schema / properties / rootDir / description
      Previous value: -"Path to repository root directory"New value: +"Path to repository root directory. Defaults to current working directory (\".\")."
  2. First observedv0.1.0

TDQS

A4.7/5.0
Behavior5/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the full burden and does so thoroughly. It explicitly discloses read-only behavior, zero file modifications, zero persistent side-effects, zero network calls, automatic secret redaction, and Markdown return format.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is well-structured with clear Behavior, When to use, and When NOT to use sections. It is front-loaded with the core purpose, uses concise sentences, and every section adds actionable information without redundancy.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness5/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a moderately complex tool with no annotations and no output schema, the description covers operation, safety profile, return format, usage guidance, and exclusions. An agent has enough context to invoke the tool correctly and understand what to expect.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so the input schema already fully documents query, rootDir, and maxTokens. The description reinforces the token-budget concept but does not add substantial parameter-level meaning beyond what the schema provides, hence the baseline score.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description states a specific verb ('extracts and packages'), a clear resource (code files relevant to a user task or bug report), and a limiting constraint (token budget). It is clearly differentiated from siblings by focusing on semantic relevance rather than repository maps or file outlines.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines5/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The 'When to use' and 'When NOT to use' sections explicitly state appropriate scenarios and name the exact sibling tools to use instead, such as get_codebase_map and read_file_outline. This gives an agent unambiguous selection criteria.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.