GitHub MCP Server

GitHub MCP Server

Enables AI assistants to interact with GitHub through the GitHub REST API, supporting repository, file, issue, pull request, branch, commit, search, and label operations with explicit confirmation for write operations.

Category
访问服务器

README

GitHub MCP Server

An AI-powered GitHub integration built from scratch using the Model Context Protocol (MCP).

This project exposes GitHub operations as structured MCP tools that an AI assistant can discover and invoke based on natural-language requests. It integrates the GitHub REST API with an MCP server and a Groq-powered AI assistant, while requiring explicit confirmation before executing write operations.


Overview

Large language models can reason about information available to them, but they cannot directly access private systems such as authenticated GitHub accounts.

This project demonstrates how MCP can act as a secure interface between an AI assistant and GitHub.

For example, instead of manually interacting with GitHub, a user can ask:

"What is the default branch of microsoft/vscode?"

or:

"Show me the open issues in microsoft/vscode."

The AI assistant determines which MCP tool is appropriate, invokes the tool through the MCP protocol, and the server communicates with GitHub's REST API.

For write operations, the assistant asks for explicit user confirmation before modifying GitHub data.


Architecture

                         User
                           |
                           v
                 +-------------------+
                 |   AI Assistant    |
                 |    Groq LLM       |
                 +---------+---------+
                           |
                           | MCP
                           v
                 +-------------------+
                 |  GitHub MCP       |
                 |     Server        |
                 +---------+---------+
                           |
                 +---------+---------+
                 |                   |
                 v                   v
          Read Operations       Write Operations
                 |                   |
                 |             Confirmation
                 |                   |
                 |                   v
                 |             User Approval
                 |                   |
                 +---------+---------+
                           |
                           v
                 +-------------------+
                 |   GitHubClient    |
                 |      HTTPX        |
                 +---------+---------+
                           |
                           | HTTPS
                           v
                 +-------------------+
                 |   GitHub REST API |
                 +-------------------+

Request Flow

  1. User enters a natural-language request.
  2. Groq determines which GitHub MCP tool is appropriate.
  3. The AI assistant sends the tool request through MCP.
  4. The MCP server validates the tool arguments.
  5. For read operations, the request executes immediately.
  6. For write operations, the assistant requests user confirmation.
  7. GitHubClient communicates with the GitHub REST API using HTTPX.
  8. The result is returned through MCP to the AI assistant.
  9. The assistant presents the result to the user.

Features

Repository Tools

  • get_repository
  • search_repositories

Retrieve repository metadata and search GitHub repositories.

File Tools

  • get_file_contents
  • list_directory
  • create_or_update_file

Read repository files and perform controlled file creation/update operations.

Issue Tools

  • list_issues
  • get_issue
  • create_issue

Retrieve issues and create new GitHub issues.

Pull Request Tools

  • list_pull_requests
  • get_pull_request
  • create_pull_request

Inspect pull requests and create new pull requests.

Branch Tools

  • list_branches
  • get_branch
  • create_branch

Inspect branches and create new branches.

Commit Tools

  • list_commits
  • get_commit

Retrieve branch commit history and individual commit information.

Search Tools

  • search_code
  • search_issues
  • search_pull_requests

Search GitHub using GitHub's search capabilities.

Label Tools

  • list_labels
  • add_labels_to_issue

Inspect available repository labels and attach existing labels to issues.


Tool Categories

The tools are intentionally separated by GitHub functionality.

Category Tools
Repository get_repository, search_repositories
Files get_file_contents, list_directory, create_or_update_file
Issues list_issues, get_issue, create_issue
Pull Requests list_pull_requests, get_pull_request, create_pull_request
Branches list_branches, get_branch, create_branch
Commits list_commits, get_commit
Search search_code, search_issues, search_pull_requests
Labels list_labels, add_labels_to_issue

The tool descriptions are designed to give the LLM enough information to distinguish between similar operations.


Security and Confirmation

The project follows a safety-first design for GitHub write operations.

Read Operations

Read-only operations execute directly. Examples:

  • Get repository information
  • Read a file
  • List issues
  • Get an issue
  • List branches
  • Search code
  • Get commit information

Write Operations

Operations that modify GitHub require explicit confirmation from the user. Examples:

  • Create or update a file
  • Create an issue
  • Create a pull request
  • Create a branch
  • Add labels to an issue

Example:

============================================================
CONFIRMATION REQUIRED
============================================================

The assistant wants to execute:
  Tool: create_issue

Arguments:
{
  "owner": "Yash-R09",
  "repo": "Book-Tracker",
  "title": "AI Assistant Confirmation Test"
}

This operation will modify your GitHub account.

Proceed? (yes/no):

The operation is executed only when the user explicitly approves it.

This prevents the LLM from silently making destructive or unintended changes to a GitHub account.


Authentication

The server uses a GitHub Personal Access Token for authenticated GitHub API access.

Environment variables are used so credentials are not hardcoded into the source code.

Example .env:

GITHUB_TOKEN=your_github_token
GROQ_API_KEY=your_groq_api_key

Never commit .env or API keys to GitHub.

A .env.example file should be included in the repository:

GITHUB_TOKEN=
GROQ_API_KEY=

Technology Stack

  • Python 3.12
  • Model Context Protocol (MCP) Python SDK
  • GitHub REST API
  • HTTPX
  • Groq API
  • Pydantic
  • Python asyncio
  • MCP Inspector

Project Structure

github-mcp-server/
│
├── app/
│   ├── __init__.py
│   ├── github_client.py
│   ├── server.py
│   │
│   └── tools/
│       ├── ...
│
├── client/
│   ├── __init__.py
│   ├── mcp_client.py
│   ├── assistant.py
│   └── test_client.py
│
├── evaluation/
│   ├── __init__.py
│   ├── evaluator.py
│   ├── test_cases.py
│   └── predictions.json
│
├── .env.example
├── .gitignore
├── README.md
└── requirements.txt

Running the MCP Server

Activate the virtual environment:

Windows PowerShell

.\.venv\Scripts\Activate.ps1

Run the MCP development server:

mcp dev app\server.py

The MCP Inspector can then be used to inspect the available tools and execute test calls.


Running the AI Assistant

The project includes a Groq-powered AI assistant that connects to the GitHub MCP server.

Run:

python -m client.assistant

Example:

Connected to GitHub MCP server.

============================================================
GitHub MCP AI Assistant
============================================================

Type 'exit' to quit.

You: What is the default branch of microsoft/vscode?

Assistant: The default branch of the microsoft/vscode repository is "main".

MCP Tool Discovery

The AI assistant dynamically discovers the tools exposed by the MCP server.

Example tools discovered by the client:

  • get_repository
  • search_repositories
  • get_file_contents
  • list_directory
  • create_or_update_file
  • list_issues
  • get_issue
  • create_issue
  • list_pull_requests
  • get_pull_request
  • create_pull_request
  • list_branches
  • get_branch
  • create_branch
  • list_commits
  • get_commit
  • search_code
  • search_issues
  • search_pull_requests
  • list_labels
  • add_labels_to_issue

This demonstrates an important MCP concept: the AI client does not need GitHub-specific logic hardcoded into it. The MCP server exposes capabilities as tools that the client can discover and invoke.


Evaluation

The project includes a 50-question tool-selection evaluation.

Each natural-language question has an expected MCP tool.

The evaluation measures three outcomes:

  • Correct Tool — the AI selected the expected tool.
  • Wrong Tool — the AI selected a valid MCP tool, but it was not the expected tool.
  • Tool Failed — the AI failed to produce a valid tool selection.

Evaluation Results

Baseline evaluation:

============================================================
GitHub MCP Server Tool Selection Evaluation
============================================================

Total test cases : 50
Evaluated        : 50
Correct          : 47
Wrong Tool       : 3
Tool Failed      : 0
Accuracy         : 94.00%

============================================================

Summary

Metric Result
Total Questions 50
Correct Tool 47
Wrong Tool 3
Tool Failed 0
Accuracy 94%

The evaluation demonstrates that the AI assistant successfully selected the correct MCP tool for the majority of natural-language GitHub requests.

The three wrong-tool cases involved semantic overlap between tools, such as:

  • Branch information vs. commit information
  • Issue search vs. issue listing
  • Issue labels vs. file operations

These cases demonstrate why precise MCP tool descriptions are important for reliable tool selection.

Example Evaluation Cases

Question: "What is the default branch of microsoft/vscode?"

  • Expected: get_repository
  • Predicted: get_repository
  • Status: CORRECT

Another example:

Question: "What commit does the develop branch point to?"

  • Expected: get_branch
  • Predicted: get_commit
  • Status: WRONG_TOOL

This illustrates that tool-selection accuracy depends not only on the model, but also on how clearly tool capabilities are represented.

Running the Evaluation

Run:

python -m evaluation.evaluator

The evaluator loads the 50 test cases from evaluation/test_cases.py and stores the model predictions in evaluation/predictions.json.


MCP Concepts Demonstrated

This project demonstrates several important MCP concepts.

  • MCP Server — The server exposes GitHub functionality as structured tools.
  • MCP Client — The AI assistant connects to the MCP server and discovers available tools dynamically.
  • Tool Schema — Each tool exposes structured parameters that the model can use to construct tool calls.
  • Tool Selection — The LLM decides which tool best matches a user's natural-language request.
  • API Abstraction — GitHub API communication is isolated inside GitHubClient, keeping API logic separate from MCP tool definitions.
  • Authentication — GitHub authentication is handled using environment-based credentials.
  • Confirmation — Write operations require explicit user approval before execution.
  • Error Handling — GitHub API failures and invalid operations are handled and surfaced to the client.

Design Principles

The project follows these principles:

  1. Separation of concerns

    AI Assistant
          |
          v
    MCP Client
          |
          v
    MCP Server
          |
          v
    GitHubClient
          |
          v
    GitHub API
    

    Each layer has a specific responsibility.

  2. Least privilege — The server exposes only the GitHub operations required by the application.

  3. Explicit confirmation — The AI cannot silently modify GitHub data.

  4. Structured interfaces — Tools use structured inputs and outputs rather than relying on unstructured text.

  5. Testability — The tool-selection layer is evaluated independently using 50 natural-language test cases.


Why MCP?

Traditional LLM applications often hardcode API integrations directly into the application.

MCP provides a standardized interface between AI applications and external tools.

Instead of building GitHub-specific integration logic directly into every AI assistant, an MCP server exposes GitHub capabilities through standardized tools. This allows MCP-compatible AI clients to discover and use those capabilities.


Example Use Cases

The assistant can handle requests such as:

  • "What is the default branch of microsoft/vscode?"
  • "Read README.md from microsoft/vscode."
  • "Show me the open issues in microsoft/vscode."
  • "List branches in my repository."
  • "Show the latest commits on main."
  • "Search GitHub code for FastMCP."
  • "Find issues mentioning authentication."
  • "Create a new branch called feature-auth from main."

For modifying operations, the assistant asks for confirmation before execution.


Learning Outcomes

This project provides practical experience with:

  • Model Context Protocol
  • MCP server and client architecture
  • LLM tool selection
  • Tool schema design
  • GitHub REST API integration
  • HTTPX
  • API authentication
  • Structured tool inputs and outputs
  • LLM error handling
  • Confirmation workflows
  • Evaluation of tool selection
  • AI infrastructure design

Future Improvements

Potential improvements include:

  • OAuth-based GitHub authentication
  • More GitHub API operations
  • Better pagination support
  • Retry and backoff handling
  • Rate-limit awareness
  • More comprehensive evaluation datasets
  • Improved tool-selection accuracy
  • Audit logging
  • Fine-grained permission scopes
  • Support for additional MCP-compatible clients

Author

Built as an AI Engineering portfolio project to explore Model Context Protocol, LLM tool use, API integration, and AI infrastructure.

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选