An interactive Model Context Protocol (MCP) server for GitHub REST API integration with TypeScript.
- Three GitHub tools: Search repositories, get repository issues, and search code
- SQLite caching: Reduces API calls with intelligent caching
- Rate limiting: Handles GitHub API rate limits gracefully
- No authentication required: Works with public repositories without tokens
- TypeScript: Full type safety and modern development experience
Search for repositories by username and query.
- Parameters:
username: GitHub username (default: environment variable GITHUB_USERNAME or "octocat")query: Search query (default: "language:javascript")
- Example: Search Python repositories for user "octocat"
Get open issues for a repository.
- Parameters:
repo: Repository in format "owner/repo" (required)state: Issue state - "open", "closed", or "all" (default: "open")
- Example: Get open issues from "microsoft/vscode"
Search code within a repository.
- Parameters:
repo: Repository in format "owner/repo" (required)query: Code search query (required)
- Example: Search for "TODO" comments in "facebook/react"
- Node.js 18+
- npm or yarn
-
Clone or create the project directory:
mkdir github-mcp-server cd github-mcp-server -
Install dependencies:
npm install
-
Set up environment variables (optional but recommended):
# Create .env file touch .env # Add your GitHub username and token (token increases rate limits) echo "GITHUB_USERNAME=your-github-username" >> .env echo "GITHUB_TOKEN=ghp_your_token_here" >> .env
- Go to GitHub Settings > Developer settings > Personal access tokens
- Generate new token (classic)
- Select scopes:
repo(if you want to access private repositories)public_repo(for public repositories only)search(for search functionality)
- Copy the token and add it to your
.envfile
Note: The server works without a token using public API (60 requests/hour limit). With a token, you get 5,000 requests/hour.
npm run dev# Build the project
npm run build
# Start the server
npm startGITHUB_USERNAME: Default GitHub username for searchesGITHUB_TOKEN: GitHub personal access token (optional)
// Search for Python repositories by a specific user
{
"tool": "search_repos",
"arguments": {
"username": "octocat",
"query": "language:python"
}
}
// Search for repositories with "mcp" in name
{
"tool": "search_repos",
"arguments": {
"query": "mcp in:name"
}
}// Get open issues from a popular repository
{
"tool": "get_repo_issues",
"arguments": {
"repo": "microsoft/vscode"
}
}
// Get all issues (open and closed) from a repository
{
"tool": "get_repo_issues",
"arguments": {
"repo": "facebook/react",
"state": "all"
}
}// Search for TODO comments in a repository
{
"tool": "search_code",
"arguments": {
"repo": "facebook/react",
"query": "TODO"
}
}
// Search for specific function definitions
{
"tool": "search_code",
"arguments": {
"repo": "microsoft/vscode",
"query": "function handleClick"
}
}
// Search for import statements
{
"tool": "search_code",
"arguments": {
"repo": "nodejs/node",
"query": "import express"
}
}The server includes intelligent rate limiting:
- Without token: 60 requests per hour
- With token: 5,000 requests per hour
- Automatic handling: Waits when rate limits are reached
- Cache-first approach: Uses SQLite cache to minimize API calls
- Warning system: Alerts when approaching rate limits
- Search endpoints: 10-minute cache
- Repository data: 10-minute cache
- Issues: 5-minute cache
- General data: 5-minute cache
The server uses SQLite for caching to reduce API calls:
- Automatic cleanup: Removes expired entries
- Smart TTL: Different cache times for different endpoints
- Cache invalidation: Automatic when data expires
- Default:
./cache.db - Can be customized in the CacheManager constructor
The server handles various error scenarios:
- Rate limit exceeded: Automatically waits and retries
- Network errors: Graceful degradation with informative messages
- Invalid parameters: Clear error messages
- API errors: Detailed GitHub API error responses
All operations are logged to stderr for debugging:
- Rate limit warnings
- Cache operations
- API request/response info
- Error details
src/
├── server.ts # Main MCP server
├── github-client.ts # GitHub API client with rate limiting
└── cache.ts # SQLite caching layer
npm run buildnpm run clean- "Cannot find module" errors: Run
npm installto install dependencies - Rate limit errors: Add a GitHub token or wait for reset
- Permission errors: Check if cache.db file has write permissions
- TypeScript errors: Ensure you have Node.js 18+ and TypeScript 5+
Set environment variable for verbose logging:
DEBUG=github-mcp-server npm run dev- Fork the repository
- Create a feature branch
- Add tests for new functionality
- Ensure all tests pass
- Submit a pull request
MIT License - see LICENSE file for details