Skip to main content
Glama
UtakataKyosui

PR Review MCP Server

README.md
# PR Review MCP Server

[![CI/CD](https://github.com/UtakataKyosui/PR-Review-Resolve-MCP/actions/workflows/ci.yml/badge.svg)](https://github.com/UtakataKyosui/PR-Review-Resolve-MCP/actions/workflows/ci.yml)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)

GitHub PR レビューコメントを取得・応答・解決するためのMCPサーバーです。

## 機能

このMCPサーバーは以下の4つのツールを提供します:

1. **list_review_threads** - PRのレビュースレッド一覧を取得
2. **reply_to_review_thread** - レビュースレッドに返信
3. **resolve_review_thread** - レビュースレッドを解決
4. **reply_and_resolve** - 返信と解決を一度に実行

## 前提条件

- [GitHub CLI (gh)](https://cli.github.com/) がインストールされ、認証済みであること
  ```bash
  gh auth login
  ```
- [uv](https://github.com/astral-sh/uv) (Python 3.10以上)

## インストール

### uvを使用する方法(推奨)

```bash
# uvのインストール(まだの場合)
curl -LsSf https://astral.sh/uv/install.sh | sh

# プロジェクトディレクトリに移動
cd /path/to/CodeReviewResolvedMcp

# 依存関係のインストール
uv sync

# 開発用依存関係も含める場合
uv sync --dev
```

### 従来のpipを使用する方法

```bash
# プロジェクトディレクトリに移動
cd /path/to/CodeReviewResolvedMcp

# インストール
pip install -e .

# 開発用の依存関係も含める場合
pip install -e ".[dev]"
```

## MCPクライアントでの使用

### Claude Desktopの設定

#### uvを使用する場合(推奨)

`~/.config/Claude/claude_desktop_config.json` (Linux):

```json
{
  "mcpServers": {
    "pr-review": {
      "command": "uv",
      "args": ["run", "pr-review-mcp"],
      "cwd": "/path/to/CodeReviewResolvedMcp"
    }
  }
}
```

#### python3を使用する場合

```json
{
  "mcpServers": {
    "pr-review": {
      "command": "python3",
      "args": ["-m", "pr_review_mcp.server"],
      "cwd": "/path/to/CodeReviewResolvedMcp"
    }
  }
}
```

### 使用例

#### 1. レビュースレッド一覧の取得

```
未解決のレビューコメントを確認したいので、owner/repo の PR #123 のレビュースレッドを表示してください
```

#### 2. レビューコメントに返信

```
thread_id: PRRT_xxx のスレッドに "修正しました。ご確認ください。" と返信してください
```

#### 3. レビュースレッドの解決

```
thread_id: PRRT_xxx のスレッドを解決済みにしてください  
```

#### 4. 返信と解決を一度に実行

```
thread_id: PRRT_xxx のスレッドに "対応完了しました" と返信し、解決してください
```

## ツールの詳細

### list_review_threads

PRのレビュースレッド一覧を取得します。

**パラメータ:**
- `owner` (string, 必須): リポジトリオーナー
- `repo` (string, 必須): リポジトリ名
- `pull_number` (integer, 必須): PR番号
- `unresolved_only` (boolean, オプション): 未解決のみ取得 (デフォルト: true)

**出力例:**
```json
{
  "pull_request": "owner/repo#123",
  "thread_count": 2,
  "threads": [
    {
      "id": "PRRT_kwDOABC...",
      "is_resolved": false,
      "file": "src/main.py",
      "line": 42,
      "first_comment": {
        "author": "reviewer",
        "body": "このロジックを改善できますか?",
        "created_at": "2025-12-10T12:00:00Z"
      }
    }
  ]
}
```

### reply_to_review_thread

レビュースレッドに返信を追加します。

**パラメータ:**
- `owner` (string, 必須): リポジトリオーナー
- `repo` (string, 必須): リポジトリ名
- `pull_number` (integer, 必須): PR番号
- `thread_id` (string, 必須): スレッドID
- `body` (string, 必須): 返信内容(Markdownサポート)

### resolve_review_thread

レビュースレッドを解決済みとしてマークします。

**パラメータ:**
- `thread_id` (string, 必須): スレッドID

### reply_and_resolve

レビュースレッドに返信し、即座に解決します。

**パラメータ:**
- `owner` (string, 必須): リポジトリオーナー
- `repo` (string, 必須): リポジトリ名
- `pull_number` (integer, 必須): PR番号
- `thread_id` (string, 必須): スレッドID
- `body` (string, 必須): 返信内容(Markdownサポート)

## 技術詳細

このMCPサーバーは以下の技術を使用しています:

- **GitHub GraphQL API**: レビュースレッドの取得と操作
- **gh CLI**: GitHub APIへのアクセス(認証を含む)
- **MCP (Model Context Protocol)**: AIアシスタントとの統合

### GraphQL APIの使用

このサーバーは主に以下のGraphQL操作を使用します:

- クエリ: `repository.pullRequest.reviewThreads` - レビュースレッド取得
- ミューテーション: `addPullRequestReviewThreadReply` - 返信追加
- ミューテーション: `resolveReviewThread` - スレッド解決

## トラブルシューティング

### `gh command failed` エラー

gh CLIが正しくインストール・認証されているか確認してください:

```bash
gh auth status
```

認証されていない場合:

```bash
gh auth login
```

### `Pull request not found` エラー

- リポジトリ名、オーナー、PR番号が正しいか確認
- PRが実際に存在するか確認
- ghコマンドで該当リポジトリにアクセス権限があるか確認

### `GraphQL errors` エラー

- thread_idが正しいか確認(`list_review_threads`で取得したIDを使用)
- PR番号が正しいか確認
- リポジトリへの書き込み権限があるか確認

## ライセンス

このプロジェクトはMITライセンスの下で公開されています。

## 開発

### 依存関係の管理

```bash
# 依存関係の追加
uv add <package-name>

# 開発用依存関係の追加
uv add --dev <package-name>

# 依存関係の同期
uv sync
```

### コード品質チェック

```bash
# Ruffでリント
uv run ruff check .

# Ruffでフォーマット
uv run ruff format .

# 型チェック(追加予定)
# uv run mypy src/
```

### テストの実行

```bash
# すべてのテストを実行
uv run pytest

# 詳細表示で実行
uv run pytest -v

# 特定のテストファイルを実行
uv run pytest tests/test_gh_api.py

# カバレッジ付きで実行(pytest-covが必要)
# uv add --dev pytest-cov
# uv run pytest --cov=pr_review_mcp
```

## CI/CD

このプロジェクトはGitHub Actionsを使用した自動CI/CDパイプラインを備えています。

### ワークフロー

#### CI/CD(`.github/workflows/ci.yml`)

プッシュとプルリクエストで自動実行されます:

- **Lint**: Ruffによるコードのリント
- **Format Check**: Ruffによるフォーマットチェック
- **Test**: Python 3.10、3.11、3.12での自動テスト

```yaml
# 実行タイミング
- main ブランチへのプッシュ
- develop ブランチへのプッシュ  
- main/develop ブランチへのプルリクエスト
```

#### Release(`.github/workflows/release.yml`)

バージョンタグがプッシュされた時に自動実行されます:

```bash
# リリース方法
git tag v0.1.0
git push origin v0.1.0
```

このワークフローは:
1. パッケージをビルド
2. GitHub Releaseを作成
3. (オプション)PyPIに公開

#### Dependabot(`.github/dependabot.yml`)

依存関係の自動更新:
- GitHub Actionsの更新(週次)
- Python依存関係の更新(週次)

### ローカルでCI/CDと同じチェックを実行

```bash
# リント
uv run ruff check .

# フォーマットチェック
uv run ruff format --check .

# テスト
uv run pytest -v
```

TDQS

A3.6/5.0

Scored across 4 tools

Disambiguation5/5

Each tool targets a distinct action: listing threads, replying, resolving, and the combined reply-and-resolve. The combined tool is clearly a convenience wrapper with explicit behavior, so no ambiguity exists.

Naming Consistency5/5

All tool names follow a consistent verb_noun snake_case pattern (list_review_threads, reply_to_review_thread, resolve_review_thread, reply_and_resolve). The combined tool uses 'and' but adheres to the same style, maintaining high predictability.

Tool Count5/5

With 4 tools, the server is tightly scoped to the core review-thread workflow. Each tool is essential and the count is well-balanced for the stated purpose of managing PR review threads.

Completeness4/5

The surface covers the main lifecycle actions for review threads: list, reply, resolve, and a convenience composite. Missing operations like unresolving or fetching a single thread are minor and unlikely to cause agent failures given the typical workflow.

Maintenance

ActivityInactive
ResponsivenessNo issues