npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

ai-agent-github-mcp-server

v1.0.0

Published

MCP server for GitHub integration - review pull requests, read code for context

Readme

GitHub MCP Server

A Model Context Protocol (MCP) server for GitHub integration, enabling AI agents to review pull requests, read code for context, and interact with GitHub repositories.

Features

Pull Request Management

  • List Pull Requests: Get all PRs with filtering by state, sort order, and pagination
  • Get Pull Request Details: Retrieve comprehensive information about specific PRs
  • Get Changed Files: See what files were modified in a PR
  • Get PR Diff: Retrieve the unified diff for code review
  • Create Reviews: Submit PR reviews with approval, change requests, or comments
  • List Reviews: Get all reviews for a pull request

Repository Operations

  • Repository Info: Get detailed repository information
  • File Content: Read specific files from any branch or commit
  • Directory Listing: Browse repository contents
  • Code Search: Search for code across repositories with advanced queries
  • Branch Management: List and inspect repository branches
  • Commit Details: Get detailed information about specific commits

Issue Management

  • List Issues: Get repository issues with comprehensive filtering
  • Issue Details: Retrieve full information about specific issues
  • Create Comments: Add comments to issues and pull requests
  • List Comments: Get all comments on an issue

Installation

  1. Install dependencies:
npm install
  1. Build the server:
npm run build

Authentication

The server requires a GitHub Personal Access Token. You can create one at: https://github.com/settings/tokens

Required Scopes

For full functionality, your token should have these scopes:

  • repo - Full control of private repositories (includes read access to public repos)
  • read:user - Read user profile data
  • read:org - Read organization membership (if working with org repos)

For public repositories only:

  • public_repo - Access to public repositories

Environment Variables

Set your token as an environment variable:

# Option 1: GITHUB_TOKEN (recommended)
export GITHUB_TOKEN=ghp_xxxxxxxxxxxxxxxxxxxx

# Option 2: GITHUB_API_KEY (alternative)
export GITHUB_API_KEY=ghp_xxxxxxxxxxxxxxxxxxxx

Usage

Running the Server

# Development mode
npm run dev

# Production mode
npm start

Integration with AI Agent Platform

Add to your agent's agent.yaml:

mcpServers:
  - name: github
    url: node ./mcp-servers/github/dist/server.js
    env:
      GITHUB_TOKEN: ${GITHUB_TOKEN}
    required: false  # Set to true if GitHub access is essential

Available Tools

Pull Request Tools

  • github_list_pull_requests - List PRs for a repository
  • github_get_pull_request - Get detailed PR information
  • github_get_pull_request_files - Get files changed in a PR
  • github_get_pull_request_diff - Get the unified diff
  • github_create_pull_request_review - Create a PR review
  • github_list_pull_request_reviews - List PR reviews

Repository Tools

  • github_get_repository - Get repository information
  • github_get_file_content - Read file contents
  • github_list_repository_contents - List directory contents
  • github_search_code - Search code with queries
  • github_list_branches - List repository branches
  • github_get_commit - Get commit details

Issue Tools

  • github_list_issues - List repository issues
  • github_get_issue - Get issue details
  • github_create_issue_comment - Add comments to issues/PRs
  • github_list_issue_comments - List issue comments

Example Usage

Review a Pull Request

// List open PRs
await tools.github_list_pull_requests({
  owner: "octocat",
  repo: "Hello-World",
  state: "open"
});

// Get PR details
await tools.github_get_pull_request({
  owner: "octocat",
  repo: "Hello-World",
  pull_number: 42
});

// Get the diff for review
await tools.github_get_pull_request_diff({
  owner: "octocat",
  repo: "Hello-World",
  pull_number: 42
});

// Create a review
await tools.github_create_pull_request_review({
  owner: "octocat",
  repo: "Hello-World",
  pull_number: 42,
  body: "Looks good to me! Just a few minor suggestions.",
  event: "APPROVE",
  confirm: true
});

Read Code for Context

// Get repository structure
await tools.github_list_repository_contents({
  owner: "octocat",
  repo: "Hello-World",
  path: "src"
});

// Read a specific file
await tools.github_get_file_content({
  owner: "octocat",
  repo: "Hello-World",
  path: "src/main.js",
  ref: "main"
});

// Search for specific code patterns
await tools.github_search_code({
  q: "function handleError repo:octocat/Hello-World"
});

Work with Issues

// List open issues
await tools.github_list_issues({
  owner: "octocat",
  repo: "Hello-World",
  state: "open",
  labels: "bug,high-priority"
});

// Add a comment to an issue
await tools.github_create_issue_comment({
  owner: "octocat",
  repo: "Hello-World",
  issue_number: 123,
  body: "I can reproduce this issue. Working on a fix.",
  confirm: true
});

Rate Limits

GitHub API has the following rate limits:

  • Authenticated requests: 5,000 requests per hour
  • Search API: 30 requests per minute
  • Core API: 5,000 requests per hour

The server includes appropriate error handling for rate limit scenarios.

Error Handling

The server provides detailed error messages for common scenarios:

  • Authentication failures
  • Repository not found
  • Pull request/issue not found
  • Permission denied
  • Rate limit exceeded
  • Invalid parameters

Security Notes

  • Never commit your GitHub token to version control
  • Use environment variables or secure secret management
  • Consider using fine-grained personal access tokens for better security
  • Regularly rotate your access tokens
  • Review token permissions and limit to minimum required scopes

Development

Project Structure

src/
├── server.ts              # Main MCP server entry point
├── auth/
│   └── api-key-manager.ts # GitHub token management
├── handlers/
│   ├── pull-requests.ts   # PR operations
│   ├── repository.ts      # Repository operations
│   └── issues.ts          # Issue operations
└── types/
    └── index.ts           # TypeScript type definitions

Building

npm run build

Testing

# Test the server directly
echo '{"method": "tools/list"}' | npm run dev

# Test with authentication
GITHUB_TOKEN=your_token npm run dev

Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests if applicable
  5. Submit a pull request

License

MIT License - see LICENSE file for details.

Support

For issues and questions:

  1. Check the GitHub API documentation: https://docs.github.com/en/rest
  2. Review rate limits and authentication requirements
  3. Ensure your token has the necessary scopes
  4. Check server logs for detailed error messages