Skip to main content
Glama
ARQAWA

code_nav MCP

by ARQAWA

code_nav.find_file

Read-only

Locate repo-relative files by query, using fff or git-visible fallback, with optional scope and limit constraints.

Instructions

Find repo-relative files with fff or git-visible fallback.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
queryYes
scopeNo
limitNo

Implementation Reference

  • The main handler function for 'code_nav.find_file'. Gets the repo root, loads config, lists candidate files, clamps the limit, and delegates to fffFindFiles which uses the fff-node library for fuzzy file finding with a fallback.
    export async function findFile(input: FindFileInput, cwd = process.cwd()) {
      const repo = await getRepoRoot(cwd);
      const loaded = await loadConfig(repo.repoRoot);
      const listed = await listCandidateFiles(repo.repoRoot, repo.isGitRepo, loaded.config);
      const limit = clampLimit(input.limit, 20, 200);
      const result = await fffFindFiles(
        repo.repoRoot,
        listed.files,
        input.query,
        input.scope,
        limit,
      );
      return result.results;
    }
  • Core fuzzy file finding logic using fff-node library. Attempts to use the FFF finder for fast fuzzy matching; falls back to a simple path-based fuzzy scoring algorithm if FFF is unavailable or fails.
    export async function fffFindFiles(
      repoRoot: string,
      files: CandidateFile[],
      query: string,
      scope: string[] | undefined,
      limit: number,
    ): Promise<{ results: FindFileResult[]; mode: "fff" | "fallback"; warning?: string }> {
      const state = await ensureFinder(repoRoot);
      const allowed = new Set(applyScope(files, scope).map((file) => file.path));
      if (state.finder) {
        const result = state.finder.fileSearch(query, { pageSize: Math.max(limit * 5, 50) });
        if (result.ok) {
          const results: FindFileResult[] = [];
          result.value.items.forEach((item: any, index: number) => {
            if (!allowed.has(item.relativePath)) return;
            const score = result.value.scores[index]?.total ?? 0;
            results.push({
              path: item.relativePath,
              score: normalizeScore(score),
              source: "fff",
              why_matched: [`path fuzzy matched ${query}`],
            });
          });
          return { results: results.slice(0, limit), mode: "fff" };
        }
        state.warning = result.error;
        state.mode = "degraded";
      }
      return {
        results: fallbackFindFiles(files, query, scope, limit),
        mode: "fallback",
        warning: state.warning ?? undefined,
      };
    }
  • Input type definition for the findFile handler: query (string), optional scope (string array), optional limit (number).
    export interface FindFileInput {
      query: string;
      scope?: string[];
      limit?: number;
    }
  • src/mcp.ts:30-42 (registration)
    Registration of the 'code_nav.find_file' tool in the MCP server with its schema, description, and handler binding.
    server.registerTool(
      "code_nav.find_file",
      {
        description: "Find repo-relative files with fff or git-visible fallback.",
        inputSchema: {
          query: z.string(),
          scope: z.array(z.string()).optional(),
          limit: z.number().int().positive().optional(),
        },
        annotations: { readOnlyHint: true, openWorldHint: false },
      },
      async (input) => mcpJson(await findFile(input)),
    );
  • Fallback file finding logic that tokenizes the query and scores each file path using fuzzy matching (substring, subsequence, etc.) when the FFF library is unavailable.
    export function fallbackFindFiles(
      files: CandidateFile[],
      query: string,
      scope: string[] | undefined,
      limit: number,
    ): FindFileResult[] {
      const terms = tokenize(query);
      return applyScope(files, scope)
        .map((file) => ({ file, score: fuzzyPathScore(file.path, terms) }))
        .filter((item) => item.score > 0)
        .sort((a, b) => b.score - a.score || a.file.path.localeCompare(b.file.path))
        .slice(0, limit)
        .map(({ file, score }) => ({
          path: file.path,
          score,
          source: "fallback",
          why_matched: [`path fuzzy matched ${terms.join(" ") || query}`],
        }));
    }
    
    async function ensureFinder(repoRoot: string): Promise<FinderState> {
      const cached = finderCache.get(repoRoot);
      if (cached) return cached;
      try {
        const created = FileFinder.create({
          basePath: repoRoot,
          aiMode: true,
          disableWatch: true,
          cacheBudgetMaxFileSize: 2 * 1024 * 1024,
        });
        if (!created.ok) {
          const state = { finder: null, mode: "degraded" as const, warning: created.error };
          finderCache.set(repoRoot, state);
          return state;
        }
        const waited = await created.value.waitForScan(5000);
        const warning = waited.ok && waited.value ? null : "fff scan did not complete in 5s";
        const state = { finder: created.value, mode: "node" as const, warning };
        finderCache.set(repoRoot, state);
        return state;
      } catch (error) {
        const message = error instanceof Error ? error.message : String(error);
        const state = { finder: null, mode: "degraded" as const, warning: message };
        finderCache.set(repoRoot, state);
        return state;
      }
    }
    
    function tokenize(query: string): string[] {
      return query
        .toLowerCase()
        .split(/[^a-z0-9_.-]+/i)
        .filter(Boolean);
    }
    
    function fuzzyPathScore(path: string, terms: string[]): number {
      const lower = path.toLowerCase();
      if (terms.length === 0) return 0;
      let score = 0;
      for (const term of terms) {
        if (lower.includes(term)) score += 0.3;
        if (lower.split("/").some((part) => part.includes(term))) score += 0.2;
        if (path.toLowerCase().endsWith(term)) score += 0.2;
        if (isSubsequence(term, lower)) score += 0.1;
      }
      return Math.min(1, score);
    }
    
    function isSubsequence(needle: string, haystack: string): boolean {
      let j = 0;
      for (const ch of haystack) {
        if (ch === needle[j]) j += 1;
        if (j === needle.length) return true;
      }
      return false;
    }
    
    function normalizeScore(score: number): number {
      if (!Number.isFinite(score)) return 0;
      if (score <= 1) return Math.max(0, score);
      return Math.min(1, score / 1000);
    }
Behavior4/5

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

Annotations already declare readOnlyHint=true. The description adds behavioral context by mentioning the fallback mechanism (fff or git-visible), which goes beyond the annotations. However, it does not detail side effects, authorization needs, or output 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 a single 8-word sentence that is front-loaded with the verb and resource, with no wasted words.

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

Completeness2/5

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

Despite having three parameters and no output schema, the description is very short and omits key details: return values, query format, scope usage, and limit behavior. It only hints at the search method, leaving significant gaps for the agent.

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

Parameters1/5

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

Schema description coverage is 0%, and the description adds no information about the three parameters (query, scope, limit). The agent receives no guidance on what kinds of queries are valid or how scope/limit work.

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 clearly states the verb 'Find' and the resource 'repo-relative files', and distinguishes from sibling tools like exact_search and structural_search by specifying the use of 'fff or git-visible fallback'.

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

Usage Guidelines3/5

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

The description implies usage for finding repo-relative files via its verb and resource, but does not explicitly state when to use this tool over siblings, nor does it provide exclusions 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