Labsco
AstroMined logo

PyGithub MCP Server

โ˜… 1

from AstroMined

Interact with the GitHub API using PyGithub to manage repositories, issues, and pull requests.

๐Ÿ”ฅ๐Ÿ”ฅ๐Ÿ”ฅโœ“ VerifiedFreeQuick setup

PyGithub MCP Server

A Model Context Protocol server that provides tools for interacting with the GitHub API through PyGithub. This server enables AI assistants to perform GitHub operations like managing issues, repositories, and pull requests.

Features

  • Modular Tool Architecture:

    • Configurable tool groups that can be enabled/disabled
    • Domain-specific organization (issues, repositories, etc.)
    • Flexible configuration via file or environment variables
    • Clear separation of concerns with modular design
    • Easy extension with consistent patterns
  • Complete GitHub Issue Management:

    • Create and update issues
    • Get issue details and list repository issues
    • Add, list, update, and delete comments
    • Manage issue labels
    • Handle assignees and milestones
  • Smart Parameter Handling:

    • Dynamic kwargs building for optional parameters
    • Proper type conversion for GitHub objects
    • Validation for all input parameters
    • Clear error messages for invalid inputs
  • Robust Implementation:

    • Object-oriented GitHub API interactions via PyGithub
    • Centralized GitHub client management
    • Proper error handling and rate limiting
    • Clean API abstraction through MCP tools
    • Comprehensive pagination support
    • Detailed logging for debugging

Documentation

Comprehensive guides are available in the docs/guides directory:

  • error-handling.md: Error types, handling patterns, and best practices
  • security.md: Authentication, access control, and content security
  • tool-reference.md: Detailed tool documentation with examples

See these guides for detailed information about using the PyGithub MCP Server.

Development

Testing

The project includes a comprehensive test suite:

Copy & paste โ€” that's it
# Run all tests
pytest

# Run tests with coverage report
pytest --cov

# Run specific test file
pytest tests/test_operations/test_issues.py

# Run tests matching a pattern
pytest -k "test_create_issue"

Note: Many tests are currently failing and under investigation. This is a known issue being actively worked on.

Testing with MCP Inspector

Test MCP tools during development using the MCP Inspector:

Copy & paste โ€” that's it
source .venv/bin/activate  # Ensure venv is activated
npx @modelcontextprotocol/inspector -e GITHUB_PERSONAL_ACCESS_TOKEN=your-token-here uv run pygithub-mcp-server

Use the MCP Inspector's Web UI to:

  • Experiment with available tools
  • Test with real GitHub repositories
  • Verify success and error cases
  • Document working payloads

Project Structure

Copy & paste โ€” that's it
tests/
โ”œโ”€โ”€ unit/                # Fast tests without external dependencies
โ”‚   โ”œโ”€โ”€ config/          # Configuration tests
โ”‚   โ”œโ”€โ”€ tools/           # Tool registration tests
โ”‚   โ””โ”€โ”€ ...              # Other unit tests
โ””โ”€โ”€ integration/         # Tests with real GitHub API
    โ”œโ”€โ”€ issues/          # Issue tools tests
    โ””โ”€โ”€ ...              # Other integration tests
Copy & paste โ€” that's it
src/
โ””โ”€โ”€ pygithub_mcp_server/
    โ”œโ”€โ”€ __init__.py
    โ”œโ”€โ”€ __main__.py
    โ”œโ”€โ”€ server.py        # Server factory (create_server)
    โ”œโ”€โ”€ version.py
    โ”œโ”€โ”€ config/          # Configuration system
    โ”‚   โ”œโ”€โ”€ __init__.py
    โ”‚   โ””โ”€โ”€ settings.py  # Configuration management
    โ”œโ”€โ”€ tools/           # Modular tool system
    โ”‚   โ”œโ”€โ”€ __init__.py  # Tool registration framework
    โ”‚   โ””โ”€โ”€ issues/      # Issue tools
    โ”‚       โ”œโ”€โ”€ __init__.py
    โ”‚       โ””โ”€โ”€ tools.py # Issue tool implementations
    โ”œโ”€โ”€ client/          # GitHub client functionality
    โ”‚   โ”œโ”€โ”€ __init__.py
    โ”‚   โ”œโ”€โ”€ client.py    # Core GitHub client
    โ”‚   โ””โ”€โ”€ rate_limit.py # Rate limit handling
    โ”œโ”€โ”€ converters/      # Data transformation
    โ”‚   โ”œโ”€โ”€ __init__.py
    โ”‚   โ”œโ”€โ”€ parameters.py # Parameter formatting
    โ”‚   โ”œโ”€โ”€ responses.py # Response formatting
    โ”‚   โ”œโ”€โ”€ common/      # Common converters
    โ”‚   โ”œโ”€โ”€ issues/      # Issue-related converters
    โ”‚   โ”œโ”€โ”€ repositories/ # Repository converters
    โ”‚   โ””โ”€โ”€ users/       # User-related converters
    โ”œโ”€โ”€ errors/          # Error handling
    โ”‚   โ”œโ”€โ”€ __init__.py
    โ”‚   โ””โ”€โ”€ exceptions.py # Custom exceptions
    โ”œโ”€โ”€ operations/      # GitHub operations
    โ”‚   โ”œโ”€โ”€ __init__.py
    โ”‚   โ””โ”€โ”€ issues.py
    โ”œโ”€โ”€ schemas/         # Data models
    โ”‚   โ”œโ”€โ”€ __init__.py
    โ”‚   โ”œโ”€โ”€ base.py
    โ”‚   โ”œโ”€โ”€ issues.py
    โ”‚   โ””โ”€โ”€ ...
    โ””โ”€โ”€ utils/           # General utilities
        โ”œโ”€โ”€ __init__.py
        โ””โ”€โ”€ environment.py # Environment utilities

Troubleshooting

  1. Server fails to start:

    • Verify venv Python path in MCP settings
    • Ensure all requirements are installed in venv
    • Check GITHUB_PERSONAL_ACCESS_TOKEN is set and valid
  2. Build errors:

    • Use --no-build-isolation flag with uv build
    • Ensure Python 3.10+ is being used
    • Verify all dependencies are installed
  3. GitHub API errors:

    • Check token permissions and validity
    • Review pygithub_mcp_server.log for detailed error traces
    • Verify rate limits haven't been exceeded

Dependencies

  • Python 3.10+
  • MCP Python SDK
  • Pydantic
  • PyGithub
  • UV package manager

License

MIT