Skip to main content
Glama
ARQAWA

code_nav MCP

by ARQAWA

code_nav.extract_context

Read-only

Extract compact code context from repository files by specifying targets and optional queries, using probe or fallback range methods.

Instructions

Extract compact code context with Probe or fallback ranges.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
targetsYes
queryNo
max_tokensNo

Implementation Reference

  • Handler function for code_nav.extract_context tool. Orchestrates extraction by getting repo root and calling extractContext from probe-adapter.
    export async function extractContextTool(
      input: ExtractContextInput,
      cwd = process.cwd(),
    ) {
      const repo = await getRepoRoot(cwd);
      const extracted = await extractContext(
        repo.repoRoot,
        input.targets,
        input.query,
        clampLimit(input.max_tokens, DEFAULT_CONTEXT_TOKENS, 50_000),
      );
      return extracted.blocks;
    }
  • Core extraction logic that tries Probe first, then falls back to file read for each target, with token limiting.
    export async function extractContext(
      repoRoot: string,
      targets: string[],
      query: string | undefined,
      maxTokens: number,
    ): Promise<{ blocks: ContextBlock[]; warnings: string[] }> {
      const warnings: string[] = [];
      const blocks: ContextBlock[] = [];
      const hasProbe = await commandExists("probe");
      for (const target of targets) {
        if (approxTokens(blocks.map((block) => block.content).join("\n")) >= maxTokens) break;
        const parsed = parseTarget(target);
        if (!parsed) {
          warnings.push(`invalid target: ${target}`);
          continue;
        }
        if (hasProbe) {
          const probeBlock = await tryProbe(repoRoot, parsed, query);
          if (probeBlock) {
            blocks.push(probeBlock);
            continue;
          }
          warnings.push(`probe failed for ${target}; used fallback`);
        }
        blocks.push(await fallbackExtract(repoRoot, parsed));
      }
      return { blocks: trimBlocks(blocks, maxTokens), warnings };
    }
  • TypeScript interface for the tool's input schema: targets (required), query (optional), max_tokens (optional).
    export interface ExtractContextInput {
      targets: string[];
      query?: string;
      max_tokens?: number;
    }
  • src/mcp.ts:77-89 (registration)
    Registration of code_nav.extract_context tool on the MCP server with inputSchema and handler binding.
    server.registerTool(
      "code_nav.extract_context",
      {
        description: "Extract compact code context with Probe or fallback ranges.",
        inputSchema: {
          targets: z.array(z.string()).min(1),
          query: z.string().optional(),
          max_tokens: z.number().int().positive().optional(),
        },
        annotations: { readOnlyHint: true, openWorldHint: false },
      },
      async (input) => mcpJson(await extractContextTool(input)),
    );
  • Helper function trimBlocks that enforces max_tokens limit on extracted blocks.
    function trimBlocks(blocks: ContextBlock[], maxTokens: number): ContextBlock[] {
      const kept: ContextBlock[] = [];
      let used = 0;
      for (const block of blocks) {
        const tokens = approxTokens(block.content);
        if (used + tokens > maxTokens && kept.length > 0) break;
        kept.push(block);
        used += tokens;
      }
      return kept;
    }
Behavior2/5

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

Annotations already declare readOnlyHint=true, so the description adds limited behavioral context. It mentions 'Probe or fallback ranges' but does not explain their implications or any other behavioral traits beyond annotations.

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 a single, succinct sentence with no wasted words. It is appropriately front-loaded with the core action.

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

Completeness1/5

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

Given no output schema, no parameter explanations, and no usage guidance, the description leaves the agent without critical information about return values, parameter roles, or how 'Probe or fallback ranges' behave. It is severely incomplete.

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

Parameters2/5

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

Schema description coverage is 0%, and the description does not explain the meaning or usage of any of the three parameters (targets, query, max_tokens). The description adds no value over the bare schema.

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

Purpose4/5

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

The description states a specific verb ('Extract') and resource ('compact code context'), and distinguishes from sibling tools like search or find_file. However, it introduces jargon ('Probe or fallback ranges') without explanation, slightly reducing clarity.

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

Usage Guidelines2/5

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

No guidance on when to use this tool versus siblings such as code_nav.search or code_nav.structural_search. The description does not mention any conditions or alternatives.

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

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/ARQAWA/code-nav-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server