Skip to main content
Glama

map-github-repo

Visualize and analyze the structure of any GitHub repository by entering its URL. Retrieve summary information to understand repository organization and content efficiently.

Instructions

Map a GitHub repository structure and provide summary information

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
repoUrlYesURL of the GitHub repository (e.g., https://github.com/username/repo)

Implementation Reference

  • src/index.ts:43-55 (registration)
    Registration of the 'map-github-repo' tool in the ListToolsRequestSchema handler, including name, description, and input schema.
    name: "map-github-repo", description: "Map a GitHub repository structure and provide summary information", inputSchema: { type: "object", properties: { repoUrl: { type: "string", description: "URL of the GitHub repository (e.g., https://github.com/username/repo)", }, }, required: ["repoUrl"], }, },
  • Main handler logic for executing the 'map-github-repo' tool within the CallToolRequestSchema handler. Parses URL, fetches repo info and structure using helpers, formats, and returns text content.
    } else if (name === "map-github-repo") { if (!githubToken || !octokit) { throw new Error("GitHub token not set. Please use the set-github-token tool first."); } const { repoUrl } = args as { repoUrl: string }; try { const { owner, repo } = parseGitHubUrl(repoUrl); const repoInfo = await getRepoInfo(owner, repo); const repoStructure = await getRepoStructure(owner, repo); const formattedOutput = formatOutput(repoInfo, repoStructure); return { content: [ { type: "text", text: formattedOutput, }, ], }; } catch (error: unknown) { console.error("Error mapping repository:", error); const errorMessage = error instanceof Error ? error.message : 'An unknown error occurred'; return { content: [ { type: "text", text: `Error mapping repository: ${errorMessage}`, }, ], }; }
  • Helper function to parse GitHub repository URL into owner and repository name.
    function parseGitHubUrl(url: string): { owner: string; repo: string } { const match = url.match(/github\.com\/([^\/]+)\/([^\/]+)/); if (!match) { throw new Error("Invalid GitHub URL format"); } return { owner: match[1], repo: match[2] }; }
  • Helper function to fetch repository metadata (name, description, stars, etc.) using Octokit.
    async function getRepoInfo(owner: string, repo: string) { if (!octokit) { throw new Error("GitHub client not initialized"); } const { data } = await octokit.repos.get({ owner, repo }); return { name: data.name, description: data.description, stars: data.stargazers_count, forks: data.forks_count, language: data.language, createdAt: data.created_at, updatedAt: data.updated_at, }; }
  • Recursive helper function to build the full directory structure tree of the repository by fetching contents recursively.
    async function getRepoStructure(owner: string, repo: string, path = "") { if (!octokit) { throw new Error("GitHub client not initialized"); } const { data } = await octokit.repos.getContent({ owner, repo, path }); if (!Array.isArray(data)) { throw new Error("Unable to retrieve repository structure"); } const structure: { [key: string]: any } = {}; for (const item of data) { if (item.type === "file") { structure[item.name] = null; } else if (item.type === "dir") { structure[item.name] = await getRepoStructure(owner, repo, item.path); } } return structure; }

Other Tools

Related 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/dazeb/MCP-Github-Mapper'

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