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);
    }
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