mcp-server

abhinandanmishra1/mcp-server

3.2

If you are the rightful owner of mcp-server and would like to certify it and/or have it hosted online, please leave a comment on the right or send an email to henry@mcphub.com.

The GitHub PR Comment Resolver is a production-grade local MCP server designed to automate the resolution of GitHub PR review comments using LLM-based code resolution.

GitHub PR Comment Resolver - MCP Server

A production-grade local MCP (Model Context Protocol) server that automates the resolution of GitHub PR review comments by fetching comments via GitHub API and generating structured prompts for LLM-based code resolution.

šŸŽÆ Features

  • FastAPI-based MCP Server with RESTful endpoints
  • GitHub API Integration to fetch PR comments and file content
  • Multi-format Prompt Generation (Cursor, JSON, Markdown)
  • Bot Filtering and user-specific comment processing
  • File Context Enhancement with diff hunks and code snippets
  • CLI Interface for command-line usage
  • Background Processing for automated change application
  • Production-ready with proper error handling, logging, and configuration

šŸš€ Quick Start

1. Installation

# Clone and setup
git clone <your-repo>
cd cursor-pr-fix

# Create virtual environment
python -m venv venv
source venv/bin/activate  # On Windows: venv\Scripts\activate

# Install dependencies
pip install -r requirements.txt

2. Configuration

# Copy environment template
cp .env.example .env

# Edit .env with your GitHub token
GITHUB_TOKEN=your_github_token_here

Get GitHub Token:

  1. Go to GitHub Settings > Developer settings > Personal access tokens
  2. Create new token with repo scope
  3. Copy token to .env file

3. Usage Options

Option A: CLI (Recommended for first use)
# Generate Cursor-compatible prompt
python cli.py generate-prompt https://github.com/owner/repo/pull/123

# With options
python cli.py generate-prompt https://github.com/owner/repo/pull/123 \
  --format-type cursor \
  --skip-bots \
  --dry-run

# Apply changes directly (placeholder implementation)
python cli.py apply-changes https://github.com/owner/repo/pull/123 --dry-run

# Check status
python cli.py status
Option B: MCP Server
# Start server
python cli.py start-server

# Or directly
python server.py

Server will run on http://127.0.0.1:8000 with API docs at /docs

Option C: API Calls
# Generate prompt via API
curl -X POST "http://127.0.0.1:8000/generate-cursor-task" \
  -H "Content-Type: application/json" \
  -d '{
    "pr_url": "https://github.com/owner/repo/pull/123",
    "format_type": "cursor",
    "skip_bots": true
  }'

šŸ“ Project Structure

cursor-pr-fix/
ā”œā”€ā”€ server.py              # FastAPI MCP server
ā”œā”€ā”€ cli.py                 # Command-line interface
ā”œā”€ā”€ requirements.txt       # Python dependencies
ā”œā”€ā”€ .env.example          # Environment variables template
ā”œā”€ā”€ handlers/
│   ā”œā”€ā”€ __init__.py
│   └── github.py         # GitHub API interactions
ā”œā”€ā”€ prompt/
│   ā”œā”€ā”€ __init__.py
│   └── generator.py      # Prompt generation logic
ā”œā”€ā”€ utils/
│   ā”œā”€ā”€ __init__.py
│   └── file_manager.py   # File operations and change application
└── pr_prompts/           # Generated prompt files (auto-created)

šŸ”§ Configuration

Environment Variables

VariableDescriptionDefault
GITHUB_TOKENGitHub personal access tokenRequired
SERVER_HOSTServer host address127.0.0.1
SERVER_PORTServer port8000
LOG_LEVELLogging levelINFO

API Endpoints

EndpointMethodDescription
/GETHealth check
/generate-cursor-taskPOSTGenerate structured prompts
/apply-changesPOSTApply suggestions to files
/statusGETServer status

šŸ“‹ Request/Response Format

Generate Prompt Request

{
  "pr_url": "https://github.com/owner/repo/pull/123",
  "dry_run": false,
  "only_user": "username",
  "skip_bots": true,
  "auto_apply": false,
  "format_type": "cursor"
}

Response

{
  "success": true,
  "message": "Generated prompt for 5 comments",
  "comments_found": 5,
  "prompt_file": "cursor_prompt_repo_123.txt",
  "changes_applied": [],
  "errors": []
}

šŸŽØ Output Formats

1. Cursor Format (Default)

Optimized for Cursor IDE with:

  • Structured markdown sections
  • Code context with syntax highlighting
  • Actionable suggestions
  • Best practices guidelines

2. JSON Format

Structured data for programmatic processing:

{
  "task": "resolve_pr_comments",
  "metadata": { ... },
  "comments": [ ... ]
}

3. Markdown Format

Clean markdown for documentation or review.

šŸ”„ Workflow Integration

With Cursor IDE

  1. Generate Prompt:

    python cli.py generate-prompt <PR_URL>
    
  2. Copy & Paste:

    • Open generated .txt file
    • Copy content to Cursor chat
    • Let LLM analyze and apply changes
  3. Review Changes:

    • LLM will explain reasoning
    • Apply suggested modifications
    • Review diffs before committing

Automated Workflow

# Generate and apply in one step (when implemented)
python cli.py generate-prompt <PR_URL> --auto-apply

šŸ› ļø Development

Adding Custom Handlers

  1. New Comment Processors:

    # In handlers/custom.py
    class CustomHandler:
        async def process_comment(self, comment: Dict) -> Dict:
            # Custom logic
            return processed_comment
    
  2. New Prompt Formats:

    # In prompt/generator.py
    async def _generate_custom_prompt(self, comments, pr_info):
        # Custom format implementation
        return formatted_prompt
    

Testing

# Test with dry run
python cli.py generate-prompt <PR_URL> --dry-run

# Check status
python cli.py status

# Test API
curl http://127.0.0.1:8000/status

šŸ” Security

  • GitHub tokens are stored in environment variables
  • No sensitive data in logs
  • Rate limiting respected for GitHub API
  • CORS configured for local development only

šŸ“Š Logging

Logs include:

  • API request/response details
  • GitHub API interactions
  • File operation results
  • Error details with context

Configure via LOG_LEVEL environment variable.

šŸ¤ Contributing

  1. Fork the repository
  2. Create feature branch
  3. Add tests for new functionality
  4. Submit pull request

šŸ“„ License

MIT License - see LICENSE file for details.

šŸ†˜ Troubleshooting

Common Issues

  1. GitHub Token Errors:

    • Verify token has repo scope
    • Check token hasn't expired
    • Ensure token is in .env file
  2. API Rate Limits:

    • GitHub API has rate limits
    • Server respects pagination
    • Consider GitHub Apps for higher limits
  3. File Not Found:

    • Ensure PR branch files exist locally
    • Check file paths in comments match local structure

Debug Mode

python cli.py --verbose generate-prompt <PR_URL>

For more help, check the /docs endpoint when server is running.