github-ruleset-mcp
Manage GitHub branch protection rulesets programmatically through an MCP server.
Apply branch protection rulesets to a repository using templates (standard, strict, relaxed, controlled) or custom JSON, with dry-run preview by default.
Check protection on a branch to verify it has rules applied.
List all rulesets configured for a repository.
Delete a ruleset by its ID.
List available templates with descriptions.
Integrate with Claude Desktop or any MCP client for natural-language automation.
Allows managing GitHub branch protection rulesets programmatically, including applying templates, checking protection, listing, deleting rulesets, and listing templates.
Click on "Deploy Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@github-ruleset-mcp Protect myorg/api with standard rules"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
github-ruleset-mcp
Author: Hirokazu J Wilson
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 rulesAnd Claude handles the rest—validating, previewing, and applying the ruleset via GitHub's API.
Related MCP server: GitHub MCP Server
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 build2. 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 ~/.zshrc3. Add to Claude Desktop
Edit your Claude Desktop config:
macOS:
~/Library/Application Support/Claude/claude_desktop_config.jsonLinux:
~/.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.jsThis opens a web UI where you can interactively test all 5 tools.
Templates
Template | When to Use | What It Does |
| Most repos | 1 approval, CI required, no force push |
| Production | 2 approvals, signed commits, code scanning |
| Dev branches | PR required, no approval needed |
| Releases | Team-gated, staging deploy required |
Tools
Tool | Description |
| Apply branch protection (dry-run by default) |
| Verify a branch is protected |
| Show all rulesets in a repo |
| Remove a ruleset (requires confirmation) |
| Show available templates |
Examples
Protect a new repo:
Apply standard branch protection to myorg/new-servicePre-deployment check:
Verify myorg/api has branch protection before I deployCustom ruleset:
Protect myorg/api main branch requiring 3 approvals and signed commitsToken Scopes
Creating a Fine-Grained Token (Recommended)
Click "Generate new token"
Configure:
Token name:
github-ruleset-mcpExpiration: 90 days (or custom)
Repository access: "Only select repositories" or "All repositories"
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_TOKENIf empty, check that:
You added the token to your shell profile (
~/.zshrc)You ran
source ~/.zshrcto reloadClaude 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.jsRestart 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
Available Tools
5 toolsapply_rulesetA
Apply a branch protection ruleset to a GitHub repository. Use dry_run=true (default) to preview changes.
Inputs: repo (required), owner (required), dry_run, template, +1 more.
check_protectionB
Check if a branch has protection rules applied
Inputs: repo (required), owner (required), branch.
delete_rulesetA
Delete a ruleset from a repository by its ID
Inputs: repo (required), owner (required), ruleset_id (required).
list_rulesetsA
List all rulesets configured for a repository
Inputs: repo (required), owner (required).
list_templatesA
List available branch protection templates with descriptions
Inputs: no named parameters.
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 5 tools
Each tool targets a distinct operation: applying a ruleset, checking protection status, listing rulesets, deleting a ruleset, and listing templates. The purposes are clearly separated and descriptions reinforce the differences. No two tools appear to perform the same function.
All tool names follow a consistent verb_noun snake_case pattern (apply_ruleset, check_protection, list_rulesets, delete_ruleset, list_templates). The verbs clearly indicate the action, and there are no stylistic deviations or mixed conventions.
With exactly 5 tools, the server is well-scoped for managing GitHub rulesets and branch protection. Each tool serves a distinct purpose without redundancy, and the count is neither too small nor too large for the domain.
The tool set covers the full lifecycle: apply (create/update), check (read status), list (read all), delete (remove), and list_templates (discover available templates). There are no obvious missing operations for the stated purpose, and agents can accomplish all core ruleset management tasks.
Maintenance
Related MCP Connectors
An MCP server that provides an API to LLMs to manage their JumpCloud resources.
An MCP server that gives your AI access to the source code and docs of all public github repos
A comprehensive Model Context Protocol (MCP) server that enables AI assistants to interact with yo…
Create, deploy, and operate MCP servers directly from your GitHub repositories.
Related MCP Servers
- AlicenseBqualityDmaintenanceAn MCP server that enables Claude and other compatible LLMs to interact with the GitHub API, supporting features like creating issues, retrieving repository information, listing issues, and searching repositories.4ISC
- AlicenseBqualityDmaintenanceAn MCP server that allows Claude and other MCP-compatible LLMs to interact with the GitHub API, supporting features like creating issues, getting repository information, listing issues, and searching repositories.4ISC
- AlicenseAqualityDmaintenancePython MCP server for GitHub operations, providing native tool integration with Claude Code and other MCP clients. It enables managing issues, pull requests, CI status, milestones, and batch operations via natural language.15MIT
- AlicenseNot gradedqualityCmaintenanceA self-hosted MCP server that gives Claude access to your GitHub account — read files, browse repos, commit changes, and manage issues and pull requests, all from a conversation.497 npmISC