This directory contains practical, real-world examples demonstrating how to use the GitHub MCP API Client for common automation tasks.
Demonstrates fundamental operations with the GitHub API client:
- Fetch repository information
- List open issues
- List pull requests
- List branches
- List recent commits
- Get authenticated user info
Usage:
GITHUB_TOKEN=your_token npm run example:basicOptional Environment Variables:
GITHUB_TOKEN=your_token \
REPO_OWNER=octocat \
REPO_NAME=Hello-World \
npm run example:basicAutomates the complete setup of a new GitHub repository with best practices:
- Creates a new repository with proper configuration
- Adds repository topics for discoverability
- Creates an initial issue for tracking setup tasks
- Enables security features (Dependabot alerts & automated fixes)
- Creates custom labels for issue management
- Demonstrates proper error handling
Usage:
GITHUB_TOKEN=your_token npm run example:setup-repoWhat it does:
- Creates a new public repository with MIT license and Node gitignore
- Configures repository settings (issues, projects, wiki)
- Adds relevant topics for searchability
- Creates a setup tracking issue
- Enables Dependabot security features
- Creates priority and workflow labels
-
GitHub Personal Access Token
- Create at: https://github.com/settings/tokens
- Required scopes depend on operations:
repo- Full repository accessworkflow- Manage GitHub Actionsadmin:repo_hook- Manage webhooksadmin:org- For organization operations
-
Build the project
npm install npm run build
-
Set environment variables
export GITHUB_TOKEN=your_token_here export REPO_OWNER=your_username export REPO_NAME=your_repo
Available scripts in package.json:
{
"scripts": {
"example:basic": "node dist/examples/basic-usage.js",
"example:setup-repo": "node dist/examples/setup-new-repo.js"
}
}-
Never commit tokens
- Use environment variables
- Add
.envto.gitignore
-
Use minimal token scopes
- Only request permissions you need
- Rotate tokens regularly
GitHub has API rate limits:
- Authenticated: 5,000 requests/hour
- Unauthenticated: 60 requests/hour
Tips:
- Use conditional requests with ETags
- Cache responses when possible
- Implement exponential backoff on errors
All examples include comprehensive error handling:
- HTTP status codes are checked
- Errors are logged with context
- Graceful degradation where possible
Each example can be customized for your needs:
- Modify criteria - Change auto-approval rules, label matching, etc.
- Add notifications - Integrate with Slack, Discord, email
- Store metrics - Save insights to a database
- Extend functionality - Add more GitHub operations as needed
For issues or questions:
- Check the main README for API documentation
- Review GitHub's API documentation: https://docs.github.com/en/rest
- Open an issue in the repository
These examples are part of the GitHub MCP API Client package and follow the same MIT license.