Comprehensive examples for all GitHub MCP Server tools.
- List Pull Requests
- Get Pull Request
- Create Pull Request
- Update Pull Request
- Add Comment
- Merge Pull Request
- Request Reviewers
- Add Labels
- Remove Labels
- Use Cases
{
"tool": "list_prs",
"arguments": {
"owner": "octocat",
"repo": "hello-world",
"state": "open"
}
}{
"tool": "list_prs",
"arguments": {
"owner": "octocat",
"repo": "hello-world",
"state": "closed",
"per_page": 50
}
}{
"tool": "list_prs",
"arguments": {
"owner": "octocat",
"repo": "hello-world",
"base": "main",
"head": "octocat:feature-branch"
}
}[
{
"number": 123,
"title": "Add new feature",
"state": "open",
"html_url": "https://github.com/octocat/hello-world/pull/123",
"user": {
"login": "developer",
"avatar_url": "https://github.com/avatars/developer"
},
"head": {
"ref": "feature-branch",
"sha": "abc123"
},
"base": {
"ref": "main",
"sha": "def456"
},
"draft": false,
"merged": false,
"mergeable": true
}
]{
"tool": "get_pr",
"arguments": {
"owner": "octocat",
"repo": "hello-world",
"pull_number": 123
}
}{
"number": 123,
"title": "Add new feature",
"body": "This PR adds feature X\n\n## Changes\n- Added X\n- Updated Y",
"state": "open",
"html_url": "https://github.com/octocat/hello-world/pull/123",
"user": {
"login": "developer",
"avatar_url": "https://github.com/avatars/developer"
},
"head": {
"ref": "feature-branch",
"sha": "abc123def456"
},
"base": {
"ref": "main",
"sha": "def456abc789"
},
"draft": false,
"merged": false,
"mergeable": true,
"mergeable_state": "clean",
"created_at": "2024-01-15T10:30:00Z",
"updated_at": "2024-01-15T14:20:00Z"
}{
"tool": "create_pr",
"arguments": {
"owner": "octocat",
"repo": "hello-world",
"title": "Add user authentication",
"body": "Implements JWT-based authentication",
"head": "feature/auth",
"base": "main"
}
}{
"tool": "create_pr",
"arguments": {
"owner": "octocat",
"repo": "hello-world",
"title": "WIP: New dashboard design",
"body": "Work in progress, not ready for review",
"head": "feature/dashboard",
"base": "develop",
"draft": true
}
}{
"tool": "create_pr",
"arguments": {
"owner": "octocat",
"repo": "hello-world",
"title": "Feature: User profiles",
"body": "# User Profiles Feature\n\n## Description\nAdds user profile pages with customization options.\n\n## Changes\n- Created profile model\n- Added profile routes\n- Implemented profile UI\n\n## Testing\n- [x] Unit tests\n- [x] Integration tests\n- [x] Manual testing\n\n## Screenshots\n\n\nFixes #42",
"head": "feature/profiles",
"base": "main"
}
}{
"tool": "update_pr",
"arguments": {
"owner": "octocat",
"repo": "hello-world",
"pull_number": 123,
"title": "Feature: Complete user authentication",
"body": "Updated implementation with OAuth support"
}
}{
"tool": "update_pr",
"arguments": {
"owner": "octocat",
"repo": "hello-world",
"pull_number": 123,
"state": "closed"
}
}{
"tool": "update_pr",
"arguments": {
"owner": "octocat",
"repo": "hello-world",
"pull_number": 123,
"base": "develop"
}
}{
"tool": "add_pr_comment",
"arguments": {
"owner": "octocat",
"repo": "hello-world",
"pull_number": 123,
"body": "LGTM! Great work on this feature."
}
}{
"tool": "add_pr_comment",
"arguments": {
"owner": "octocat",
"repo": "hello-world",
"pull_number": 123,
"body": "## Code Review\n\n### Strengths\n- Clean implementation\n- Good test coverage\n- Clear documentation\n\n### Suggestions\n- Consider adding error handling in auth.js line 45\n- Could extract helper function for token validation\n\n### Questions\n- Does this handle token expiration?\n- What about refresh tokens?\n\nOverall looks good! Just a few minor points to address."
}
}{
"tool": "add_pr_comment",
"arguments": {
"owner": "octocat",
"repo": "hello-world",
"pull_number": 123,
"body": "Consider using async/await instead:\n\n```javascript\nasync function fetchUser(id) {\n const user = await db.users.findById(id);\n return user;\n}\n```"
}
}{
"tool": "merge_pr",
"arguments": {
"owner": "octocat",
"repo": "hello-world",
"pull_number": 123
}
}{
"tool": "merge_pr",
"arguments": {
"owner": "octocat",
"repo": "hello-world",
"pull_number": 123,
"merge_method": "squash",
"commit_title": "feat: add user authentication",
"commit_message": "Implements JWT-based authentication with OAuth support\n\nCloses #42"
}
}{
"tool": "merge_pr",
"arguments": {
"owner": "octocat",
"repo": "hello-world",
"pull_number": 123,
"merge_method": "rebase"
}
}{
"tool": "request_pr_reviewers",
"arguments": {
"owner": "octocat",
"repo": "hello-world",
"pull_number": 123,
"reviewers": ["alice", "bob"]
}
}{
"tool": "request_pr_reviewers",
"arguments": {
"owner": "octocat",
"repo": "hello-world",
"pull_number": 123,
"team_reviewers": ["frontend-team", "security-team"]
}
}{
"tool": "request_pr_reviewers",
"arguments": {
"owner": "octocat",
"repo": "hello-world",
"pull_number": 123,
"reviewers": ["alice"],
"team_reviewers": ["backend-team"]
}
}{
"tool": "add_pr_labels",
"arguments": {
"owner": "octocat",
"repo": "hello-world",
"pull_number": 123,
"labels": ["bug"]
}
}{
"tool": "add_pr_labels",
"arguments": {
"owner": "octocat",
"repo": "hello-world",
"pull_number": 123,
"labels": ["enhancement", "high-priority", "needs-review"]
}
}[
{
"name": "enhancement",
"color": "a2eeef",
"description": "New feature or request"
},
{
"name": "high-priority",
"color": "d93f0b",
"description": "High priority issue"
}
]{
"tool": "remove_pr_labels",
"arguments": {
"owner": "octocat",
"repo": "hello-world",
"pull_number": 123,
"labels": ["needs-review"]
}
}{
"tool": "remove_pr_labels",
"arguments": {
"owner": "octocat",
"repo": "hello-world",
"pull_number": 123,
"labels": ["wip", "needs-changes"]
}
}- List all open PRs
- For each PR, get details
- If PR is ready (not draft, checks passed):
- Request reviewers
- Add "ready-for-review" label
- List all open PRs
- For each PR:
- Get details
- Check merge status
- Display: title, author, status, reviewers
- Get PR details
- Check if:
- All checks passed
- Approved by 2+ reviewers
- No merge conflicts
- If all conditions met:
- Add "approved" label
- Merge with squash method
- Add comment: "Auto-merged by bot"
- List all merged PRs since last release
- For each PR:
- Extract changes from body
- Group by label (feature, bug, enhancement)
- Generate changelog
- Create release PR
- List all open PRs without labels
- For each PR:
- Analyze title and description
- Add appropriate labels (bug, feature, docs)
- Request team reviewers based on files changed
- List all open PRs
- For each PR older than 30 days:
- Add comment: "This PR is stale, please update or close"
- Add "stale" label
- For PRs older than 60 days:
- Close with comment
- Add "auto-closed" label
"List all open PRs in myorg/myrepo that haven't been updated in the last week"
"Add reviewers alice and bob to PR #123, and add labels 'ready-for-review' and 'high-priority'"
"Create a PR from feature/new-ui to main with title 'New UI Design' and include a description with changes made"
"Merge PR #45 using squash method with commit message 'feat: add dark mode'"
"Close all draft PRs older than 2 weeks with a comment explaining they're stale"
"For all open PRs in myrepo, check if they have reviewers assigned. If not, request reviews from the core team."
"Find all PRs labeled 'needs-changes', check if they've been updated in the last 3 days, and comment with a reminder if not."
"Create a daily summary of all merged PRs from yesterday, grouped by type (feature, bugfix, docs)."
All tools include proper error handling. Common errors:
{
"error": "GitHub API error (404): Not Found",
"code": "INTERNAL_ERROR"
}{
"error": "Validation error",
"code": "INVALID_PARAMS",
"details": [
{
"path": ["pull_number"],
"message": "Pull request number must be positive"
}
]
}{
"error": "GitHub API error (403): Resource not accessible by integration",
"code": "INTERNAL_ERROR"
}- Use specific filters: When listing PRs, use
state,base, andheadfilters to reduce API calls - Handle pagination: For repos with many PRs, use
per_pageparameter - Check PR state: Before merging, always get PR details to verify it's mergeable
- Use draft PRs: Create PRs as drafts when they're not ready for review
- Add descriptive comments: Include context and reasoning in PR comments
- Label consistently: Use consistent labels across your organization
- Request appropriate reviewers: Request reviewers based on code ownership
GitHub API rate limits (authenticated):
- 5,000 requests per hour
- Check remaining:
curl -H "Authorization: token YOUR_TOKEN" https://api.github.com/rate_limit
Tips to stay under limits:
- Cache PR lists when possible
- Use specific filters to reduce list sizes
- Batch operations when updating multiple PRs
- Monitor your rate limit usage
- Never commit tokens to version control
- Use environment variables for authentication
- Rotate tokens regularly
- Use tokens with minimum required scopes
- Monitor token usage in GitHub settings