How to Connect Claude to Your GitHub Repo Using the Model Context Protocol (MCP)

Claude to Github MCP howto.

AI can do more than generate text — it can collaborate with your tools. Anthropic’s Model Context Protocol (MCP) opens a channel between Claude and external data sources like GitHub, Jira, or Confluence. In this post, we’ll create a working MCP connection between Claude and GitHub, allowing the model to fetch repository details, read code, and even help write documentation based on live project data.

What You’ll Need

  • Claude 3.5 Sonnet or later
  • Anthropic Claude desktop app or API key
  • A GitHub personal access token (classic or fine-grained)
  • Node.js installed locally (v18+)
  • Basic comfort with JSON or JavaScript

What Is MCP?

MCP — the Model Context Protocol — is a lightweight specification that lets an AI model securely use “tools” defined on your system. Think of it as a translator: Claude asks the MCP server for structured data, and your local server handles the actual API requests, ensuring credentials never leave your machine.

Step 1 – Create the MCP Project

Open your terminal and spin up a folder for the project:

mkdir claude-github-mcp && cd claude-github-mcp
npm init -y
npm install @modelcontextprotocol/sdk node-fetch

This installs the MCP SDK plus node-fetch for making API calls.

Step 2 – Add an mcp.json Config

Claude looks for this file to register your local servers.

{
  "mcpServers": {
    "github": {
      "command": "node",
      "args": ["./github-mcp.js"]
    }
  }
}

It tells Claude that when it needs GitHub data, it should run github-mcp.js.

Step 3 – Write the MCP Server Script

Create github-mcp.js:

// github-mcp.js
import { Server } from "@modelcontextprotocol/sdk";
import fetch from "node-fetch";

const server = new Server({ name: "GitHub MCP", version: "1.0.0" });

server.tool("getRepoInfo", {
  description: "Fetch GitHub repository metadata",
  parameters: {
    type: "object",
    properties: { repo: { type: "string" } },
    required: ["repo"]
  },
  async handler({ repo }) {
    const res = await fetch(`https://api.github.com/repos/${repo}`, {
      headers: { Authorization: `Bearer ${process.env.GITHUB_TOKEN}` }
    });
    if (!res.ok) throw new Error(`GitHub API error: ${res.status}`);
    return await res.json();
  }
});

server.start();

You’ve just built a tiny local API translator. Claude will call getRepoInfo, and your server will hit GitHub’s REST API using your token.

Step 4 – Add Your GitHub Token

Generate a personal access token in GitHub → Settings → Developer Settings → Tokens. Then expose it to your shell session:

export GITHUB_TOKEN=ghp_your_token_here

For Windows PowerShell, use:

setx GITHUB_TOKEN "ghp_your_token_here"

Step 5 – Connect Claude

  1. Open the Claude Desktop app.
  2. Go to Settings → Integrations → Add MCP Server.
  3. Point to the directory containing mcp.json.
  4. Restart Claude.

Now test the connection by typing:

Use the GitHub MCP to get repo info for your-username/your-repo.

Claude should reply with structured JSON containing your repository’s details — name, description, stars, issues, and more.

Step 6 – Real-World Uses

Once connected, Claude can:

  • Write or update your README from code comments.
  • Summarize pull requests or commit history.
  • Draft release notes automatically.
  • Scan directories for TODOs or stale files.
  • Generate documentation directly from your repo context.

You can extend the MCP server with new tools like getOpenPRs, listContributors, or summarizeCommits — each defined in just a few lines of JavaScript.

Next Steps

Now that you’ve bridged Claude and GitHub, the possibilities multiply. Next, connect Claude’s MCP to Confluence or your local codebase to maintain internal docs or generate changelogs directly from commit diffs. The real power isn’t automation for its own sake — it’s contextual intelligence. Claude can now see the same world your code lives in.

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *