Skip to main content
Glama
canova

Searchfox MCP Server

by canova

get_file

Retrieve file contents from Mozilla repositories to access code directly within the Searchfox MCP Server environment.

Instructions

Get the contents of a specific file from specified repository.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
repoNoRepository namemozilla-central
pathYesFile path within the repository

Implementation Reference

  • The core handler function implementing the 'get_file' tool. It maps the repository name to a GitHub repository and branch, constructs the raw file URL, fetches the content, and returns it in MCP format. Handles fetch errors gracefully.
    private async getFile(repo: string, path: string) {
      try {
        // All Firefox repos now use the unified repository
        const firefoxGithubRepo = "mozilla/firefox";
    
        // Map Searchfox repo names to GitHub branches
        const branchMapping: Record<string, string> = {
          "mozilla-central": "main",
          autoland: "autoland",
          "mozilla-beta": "beta",
          "mozilla-release": "release",
          "mozilla-esr115": "esr115",
          "mozilla-esr128": "esr128",
          "mozilla-esr140": "esr140",
          // comm-central is still in mercurial, but there is an experimental
          // repository in https://github.com/mozilla/releases-comm-central/
          "comm-central": "main",
        };
    
        const branch = branchMapping[repo] || "main";
    
        // comm-central is still in mercurial, but there is an experimental
        // repository in https://github.com/mozilla/releases-comm-central/
        const repoToUse =
          repo === "comm-central"
            ? "mozilla/releases-comm-central"
            : firefoxGithubRepo;
    
        // Construct GitHub raw URL
        const githubRawUrl = `https://raw.githubusercontent.com/${repoToUse}/${branch}/${path}`;
    
        try {
          // Try to fetch from GitHub
          const response = await fetch(githubRawUrl);
    
          if (!response.ok) {
            throw new Error(`HTTP ${response.status}: ${response.statusText}`);
          }
    
          const content = await response.text();
    
          return {
            content: [
              {
                type: "text",
                text: JSON.stringify(
                  {
                    repo,
                    path,
                    content: content,
                    source: "github",
                    url: githubRawUrl,
                    searchfoxUrl: `${this.baseUrl}/${repo}/source/${path}`,
                  },
                  null,
                  2
                ),
              },
            ],
          };
        } catch (githubError) {
          console.error("GitHub fetch failed.", githubError);
    
          return {
            content: [
              {
                type: "text",
                text: JSON.stringify(
                  {
                    repo,
                    path,
                    content: "",
                    note: "Error: GitHub fetch failed",
                  },
                  null,
                  2
                ),
              },
            ],
          };
        }
      } catch (error) {
        throw new McpError(
          ErrorCode.InternalError,
          `Failed to fetch file: ${error instanceof Error ? error.message : String(error)}`
        );
      }
    }
  • src/index.ts:124-143 (registration)
    Tool registration in the ListTools response. Defines the tool name, description, and input schema (repo optional, path required).
    {
      name: "get_file",
      description:
        "Get the contents of a specific file from specified repository.",
      inputSchema: {
        type: "object",
        properties: {
          repo: {
            type: "string",
            description: "Repository name",
            default: "mozilla-central",
          },
          path: {
            type: "string",
            description: "File path within the repository",
          },
        },
        required: ["path"],
      },
    },
  • Input schema definition for the 'get_file' tool, specifying object with optional repo (default mozilla-central) and required path.
    inputSchema: {
      type: "object",
      properties: {
        repo: {
          type: "string",
          description: "Repository name",
          default: "mozilla-central",
        },
        path: {
          type: "string",
          description: "File path within the repository",
        },
      },
      required: ["path"],
    },
  • Dispatcher handler in CallToolRequestSchema that validates arguments and delegates to the getFile implementation.
    case "get_file": {
      const fileArgs = args as Record<string, unknown>;
      if (!fileArgs.path || typeof fileArgs.path !== "string") {
        throw new McpError(
          ErrorCode.InvalidParams,
          "Path parameter is required and must be a string"
        );
      }
    
      const repo =
        typeof fileArgs.repo === "string"
          ? fileArgs.repo
          : "mozilla-central";
      return await this.getFile(repo, fileArgs.path);
    }
Behavior2/5

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

No annotations are provided, so the description carries the full burden. It mentions 'Get the contents' but does not disclose behavioral traits such as authentication requirements, rate limits, error handling, or whether it returns raw text or metadata. This leaves significant gaps for a tool that likely interacts with a repository system.

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

Conciseness4/5

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

The description is a single, straightforward sentence that efficiently conveys the core purpose without unnecessary words. It is appropriately sized for a simple tool, though it could be slightly more structured by front-loading key details.

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?

Given the lack of annotations and output schema, the description is incomplete. It does not explain what the tool returns (e.g., file content format, error responses) or address potential complexities like large files or permissions, which are critical for effective use by an AI agent.

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%, with clear descriptions for 'repo' and 'path' parameters. The description adds minimal value beyond the schema, as it only reiterates that parameters specify the repository and file path without providing additional context or usage examples.

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 clearly states the verb ('Get') and resource ('contents of a specific file'), specifying the action and target. However, it does not explicitly differentiate from the sibling tool 'search_code', which likely searches for code patterns rather than retrieving a specific file's contents.

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 is provided on when to use this tool versus alternatives like 'search_code'. The description implies usage for retrieving file contents but lacks explicit context, prerequisites, or exclusions, leaving the agent to infer usage scenarios.

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/canova/searchfox-mcp'

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