GitHub PR Analyzer with Notion Integration

GitHub PR Analyzer with Notion Integration

Fetches GitHub pull request information including file changes, diffs, and metadata, then creates analysis summaries in Notion pages.

Category
访问服务器

README

GitHub PR Analyzer with Notion Integration

A Model Context Protocol (MCP) server that fetches GitHub pull request changes and creates analysis summaries in Notion.

Tutorial: Follow this step-by-step guide at DataCamp's MCP Tutorial

Features

  • 🔍 Fetch detailed GitHub pull request information including:
    • File changes (additions, deletions, modifications)
    • PR metadata (title, description, author, timestamps)
    • Diff patches for each changed file
  • 📝 Create Notion pages with PR analysis
  • 🔌 MCP server integration for seamless tool usage

Prerequisites

  • Python 3.8 or higher
  • GitHub Personal Access Token
  • Notion API Key and Page ID

Installation

  1. Clone the repository:
git clone <repository-url>
cd mcp-starter
  1. Create and activate a Python virtual environment:
# Create virtual environment
python -m venv venv

# Activate virtual environment
# On macOS/Linux:
source venv/bin/activate

# On Windows:
# venv\Scripts\activate
  1. Install dependencies:
pip install -r requirements.txt
  1. Create a .env file in the project root with your credentials:
GITHUB_TOKEN=your_github_token_here
NOTION_API_KEY=your_notion_api_key_here
NOTION_PAGE_ID=your_notion_page_id_here

Getting Your Credentials

GitHub Token:

  1. Go to GitHub Settings → Developer settings → Personal access tokens
  2. Generate a new token with repo scope
  3. Copy the token to your .env file

Notion API Key:

  1. Go to https://www.notion.so/my-integrations
  2. Create a new integration and copy the Internal Integration Token
  3. Share your Notion page with the integration

Notion Page ID:

  1. Open your Notion page in a browser
  2. Copy the page ID from the URL (the part after the last / and before the ?)

Usage

Running the MCP Server

First, ensure your virtual environment is activated:

# On macOS/Linux:
source venv/bin/activate

# On Windows:
# venv\Scripts\activate

Then run the server:

python pr_analyzer.py

The server exposes two MCP tools:

1. fetch_pr

Fetches pull request information from GitHub.

Parameters:

  • repo_owner (str): Repository owner username
  • repo_name (str): Repository name
  • pr_number (int): Pull request number

Returns:

  • PR metadata and detailed file changes

2. create_notion_page

Creates a Notion page with analysis content.

Parameters:

  • title (str): Page title
  • content (str): Page content

Returns:

  • Success or error message

Direct Usage (Development/Testing)

You can also use the github_integration.py module directly:

from github_integration import fetch_pr_changes

# Fetch PR changes
pr_data = fetch_pr_changes('owner', 'repo', 123)
print(pr_data)

Project Structure

mcp-starter/
├── github_integration.py  # GitHub API integration
├── pr_analyzer.py         # MCP server implementation
├── requirements.txt       # Project dependencies
├── .env                   # Environment variables (not in git)
└── README.md             # This file

Dependencies

Key dependencies include:

  • mcp - Model Context Protocol server
  • requests - GitHub API calls
  • notion-client - Notion API integration
  • python-dotenv - Environment variable management
  • pydantic - Data validation
  • httpx - Async HTTP client

See requirements.txt for the complete list.

Error Handling

The application includes comprehensive error handling:

  • API request failures are caught and logged
  • Missing credentials trigger appropriate error messages
  • Stack traces are printed to stderr for debugging

Development

To contribute or modify:

  1. Ensure your .env file is properly configured
  2. Test changes with the direct usage method before running the MCP server
  3. Check stderr output for debugging information

Security Notes

⚠️ Important: Never commit your .env file to version control. It contains sensitive credentials.

Add to your .gitignore:

.env
__pycache__/
*.pyc

License

MIT License

Copyright (c) 2024

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

-+--+-+-+-+-+

This project is released into the public domain under the Unlicense.

You are free to use, modify, distribute, and utilize this software for any purpose, commercial or non-commercial, without any restrictions or attribution requirements.

For more details, see the Unlicense.

Author

Kiet Tran (Leo Loves Coding)

Support

For issues or questions, please open an issue in the repository.

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选