github-ruleset-mcp
An MCP server that lets Claude (or any MCP client) manage GitHub branch protection rulesets programmatically.
README
github-ruleset-mcp
Branch protection as code. 4 templates, 5 tools, 2-minute setup.
An MCP server that lets Claude (or any MCP client) manage GitHub branch protection rulesets programmatically.
Why?
Setting up branch protection manually is tedious. This MCP server lets you say:
Protect myorg/api with standard rules
And Claude handles the rest—validating, previewing, and applying the ruleset via GitHub's API.
Installation
Prerequisites
- Node.js 18.0.0 or higher
- npm or yarn
- GitHub Personal Access Token with appropriate scopes
1. Clone and Build
git clone https://github.com/wilsonhj/github-ruleset-mcp.git
cd github-ruleset-mcp
npm install
npm run build
2. Configure GitHub Token
Choose one of these secure methods:
Option A: Environment Variable (Recommended)
Add to your shell profile (~/.zshrc, ~/.bashrc, etc.):
export GITHUB_TOKEN="ghp_your_token_here"
Then reload: source ~/.zshrc
Option B: macOS Keychain (Most Secure)
# Store token in Keychain
security add-generic-password -a "$USER" -s "github_personal_access_token" -w "ghp_your_token_here"
# Add to ~/.zshrc
echo 'export GITHUB_TOKEN=$(security find-generic-password -a "$USER" -s "github_personal_access_token" -w 2>/dev/null)' >> ~/.zshrc
source ~/.zshrc
3. Add to Claude Desktop
Edit your Claude Desktop config:
- macOS:
~/Library/Application Support/Claude/claude_desktop_config.json - Linux:
~/.config/claude/claude_desktop_config.json
{
"mcpServers": {
"github-ruleset": {
"command": "node",
"args": ["/absolute/path/to/github-ruleset-mcp/dist/index.js"],
"env": {
"GITHUB_TOKEN": "${GITHUB_TOKEN}"
}
}
}
}
Important: Replace /absolute/path/to/github-ruleset-mcp with the actual path.
4. Restart Claude Desktop
Close and reopen Claude Desktop to load the MCP server.
5. Verify Installation
Ask Claude: "List available GitHub ruleset templates"
If you see 4 templates (standard, strict, relaxed, controlled), it's working! ✅
Testing (Optional)
Test the server before adding to Claude Desktop:
# Install MCP Inspector
npx @modelcontextprotocol/inspector node dist/index.js
This opens a web UI where you can interactively test all 5 tools.
Templates
| Template | When to Use | What It Does |
|---|---|---|
standard |
Most repos | 1 approval, CI required, no force push |
strict |
Production | 2 approvals, signed commits, code scanning |
relaxed |
Dev branches | PR required, no approval needed |
controlled |
Releases | Team-gated, staging deploy required |
Tools
| Tool | Description |
|---|---|
apply_ruleset |
Apply branch protection (dry-run by default) |
check_protection |
Verify a branch is protected |
list_rulesets |
Show all rulesets in a repo |
delete_ruleset |
Remove a ruleset (requires confirmation) |
list_templates |
Show available templates |
Examples
Protect a new repo:
Apply standard branch protection to myorg/new-service
Pre-deployment check:
Verify myorg/api has branch protection before I deploy
Custom ruleset:
Protect myorg/api main branch requiring 3 approvals and signed commits
Token Scopes
Creating a Fine-Grained Token (Recommended)
- Go to https://github.com/settings/tokens?type=beta
- Click "Generate new token"
- Configure:
- Token name:
github-ruleset-mcp - Expiration: 90 days (or custom)
- Repository access: "Only select repositories" or "All repositories"
- Token name:
- Set Repository permissions:
- Administration: Read and write ✅
- Contents: Read-only ✅
- Generate and copy the token immediately
Classic Token (Alternative)
If using classic tokens, you need:
repo— Full repository accessadmin:org_hook— Organization ruleset access (if managing org-level rulesets)
Troubleshooting
"GITHUB_TOKEN environment variable is required"
The token isn't set in your environment. Verify:
echo $GITHUB_TOKEN
If empty, check that:
- You added the token to your shell profile (
~/.zshrc) - You ran
source ~/.zshrcto reload - Claude Desktop was restarted after setting the token
"GraphQL: Could not resolve to a Repository"
Check that:
- Repository owner/name are correct
- Your token has access to the repository
- The repository exists
MCP Server Not Showing in Claude Desktop
- Verify the config file path is correct
- Check the
argspath points to the compileddist/index.js - Restart Claude Desktop completely (quit and reopen)
- Check Claude Desktop logs for errors
Tools Execute But Nothing Happens
If using apply_ruleset, remember it defaults to dry-run mode. Set dry_run: false to actually apply changes.
Advanced
See docs/ADVANCED.md for:
- Custom ruleset JSON
- Multi-agent integration
- CI/CD pipeline integration
Contributing
PRs welcome! Please open an issue first for major changes.
License
MIT
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。