Skip to content

Commit 6adcb1e

Browse files
feat: add standard MCP tool support (#212)
* feat(mcp): add Model Context Protocol server support Add MCP client and provider packages that allow integrating external MCP tool servers into the review loop. Includes config commands for managing MCP servers, stdio subprocess integration tests, and comprehensive test coverage. * refactor(mcp): rename loop variable in contentToText to avoid shadowing Client receiver * fix(mcp): use platform-specific shell for setup command The MCP server setup command was hardcoded to use `sh -c`, which fails on Windows. Extract a `shellCommand` helper behind build tags to use `cmd /c` on Windows and `sh -c` elsewhere. * docs(mcp): add MCP server documentation to all README locales
1 parent 8e04918 commit 6adcb1e

23 files changed

Lines changed: 1616 additions & 19 deletions

README.ja-JP.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -673,6 +673,11 @@ OCRは4層の優先度チェーンを使ってレビュールールを解決し
673673
| `llm.extra_headers` | string | カンマ区切りの `key=value` HTTPヘッダー |
674674
| `llm.model` | string | `claude-opus-4-6` |
675675
| `llm.use_anthropic` | boolean | `true` \| `false` |
676+
| `mcp_servers.<name>.command` | string | MCPサーバーを起動するコマンド |
677+
| `mcp_servers.<name>.args` | array | MCPサーバーのコマンドライン引数 |
678+
| `mcp_servers.<name>.env` | array | 環境変数(`KEY=VALUE`形式) |
679+
| `mcp_servers.<name>.tools` | array | 許可するツール名(空の場合はすべてのツール) |
680+
| `mcp_servers.<name>.setup` | string | サーバー起動前に実行するセットアップコマンド |
676681
| `language` | string | 任意の言語名、例:`English``Chinese`(デフォルト:`English`|
677682
| `telemetry.enabled` | boolean | `true` \| `false` |
678683
| `telemetry.exporter` | string | `console` \| `otlp` |
@@ -681,6 +686,43 @@ OCRは4層の優先度チェーンを使ってレビュールールを解決し
681686

682687
環境変数は設定ファイルより優先されます。
683688

689+
### MCPサーバー
690+
691+
Open Code Reviewは[Model Context Protocol (MCP)](https://modelcontextprotocol.io/)サーバーをサポートしており、レビューエージェントがstdioトランスポートを介してコードレビュー中に外部ツールを使用できます。
692+
693+
CLIからMCPサーバーを設定します:
694+
695+
```bash
696+
# MCPサーバーを追加
697+
ocr config set mcp_servers.<name>.command <command>
698+
ocr config set mcp_servers.<name>.args '["arg1","arg2"]'
699+
ocr config set mcp_servers.<name>.env '["KEY=VALUE"]'
700+
ocr config set mcp_servers.<name>.tools '["tool_name"]'
701+
ocr config set mcp_servers.<name>.setup '<setup command>'
702+
703+
# MCPサーバーを削除
704+
ocr config unset mcp_servers.<name>
705+
```
706+
707+
| フィールド | 必須 | 説明 |
708+
|-----------|------|------|
709+
| `command` | はい | MCPサーバーを起動する実行コマンド |
710+
| `args` | いいえ | サーバーに渡すコマンドライン引数 |
711+
| `env` | いいえ | 環境変数(`KEY=VALUE`形式) |
712+
| `tools` | いいえ | 許可するツール名。空の場合、サーバーのすべてのツールが利用可能 |
713+
| `setup` | いいえ | サーバー起動前に実行するシェルコマンド(例:インデックスの構築) |
714+
715+
> **注意:** MCPツールの名前が組み込みツールと競合する場合、そのツールは警告付きでスキップされます。`setup`コマンドのタイムアウトは5分です。
716+
717+
**例:[CodeGraph](https://github.com/nicholasgasior/codegraph)を追加してコード構造分析を強化**
718+
719+
```bash
720+
ocr config set mcp_servers.codegraph.command codegraph
721+
ocr config set mcp_servers.codegraph.args '["serve","--mcp"]'
722+
ocr config set mcp_servers.codegraph.tools '["codegraph_explore"]'
723+
ocr config set mcp_servers.codegraph.setup 'codegraph init && codegraph index'
724+
```
725+
684726
### 環境変数
685727

686728
| 変数 | 用途 |

README.ko-KR.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -631,6 +631,11 @@ Config file: `~/.opencodereview/config.json`
631631
| `llm.extra_headers` | string | 쉼표로 구분된 `key=value` HTTP 헤더 |
632632
| `llm.model` | string | `claude-opus-4-6` |
633633
| `llm.use_anthropic` | boolean | `true` \| `false` |
634+
| `mcp_servers.<name>.command` | string | MCP 서버를 시작하는 명령어 |
635+
| `mcp_servers.<name>.args` | array | MCP 서버의 커맨드라인 인수 |
636+
| `mcp_servers.<name>.env` | array | 환경 변수 (`KEY=VALUE` 형식) |
637+
| `mcp_servers.<name>.tools` | array | 허용할 도구 이름 (비어 있으면 모든 도구 허용) |
638+
| `mcp_servers.<name>.setup` | string | 서버 시작 전에 실행할 설정 명령어 |
634639
| `language` | string | 임의의 언어 이름, 예: `English`, `Chinese` (기본값: `English`) |
635640
| `telemetry.enabled` | boolean | `true` \| `false` |
636641
| `telemetry.exporter` | string | `console` \| `otlp` |
@@ -639,6 +644,43 @@ Config file: `~/.opencodereview/config.json`
639644

640645
환경 변수는 config file보다 우선합니다.
641646

647+
### MCP Server
648+
649+
Open Code Review는 [Model Context Protocol (MCP)](https://modelcontextprotocol.io/) 서버를 지원하여 리뷰 에이전트가 stdio 전송을 통해 코드 리뷰 중에 외부 도구를 사용할 수 있습니다.
650+
651+
CLI로 MCP 서버를 설정합니다:
652+
653+
```bash
654+
# MCP 서버 추가
655+
ocr config set mcp_servers.<name>.command <command>
656+
ocr config set mcp_servers.<name>.args '["arg1","arg2"]'
657+
ocr config set mcp_servers.<name>.env '["KEY=VALUE"]'
658+
ocr config set mcp_servers.<name>.tools '["tool_name"]'
659+
ocr config set mcp_servers.<name>.setup '<setup command>'
660+
661+
# MCP 서버 삭제
662+
ocr config unset mcp_servers.<name>
663+
```
664+
665+
| 필드 | 필수 | 설명 |
666+
|------|------|------|
667+
| `command` || MCP 서버를 시작하는 실행 명령어 |
668+
| `args` | 아니오 | 서버에 전달할 커맨드라인 인수 |
669+
| `env` | 아니오 | 환경 변수 (`KEY=VALUE` 형식) |
670+
| `tools` | 아니오 | 허용할 도구 이름. 비어 있으면 서버의 모든 도구 사용 가능 |
671+
| `setup` | 아니오 | 서버 시작 전에 실행할 셸 명령어 (예: 인덱스 빌드) |
672+
673+
> **참고:** MCP 도구의 이름이 내장 도구와 충돌하면 경고와 함께 건너뜁니다. `setup` 명령어의 타임아웃은 5분입니다.
674+
675+
**예시: [CodeGraph](https://github.com/nicholasgasior/codegraph)를 추가하여 코드 구조 분석 강화**
676+
677+
```bash
678+
ocr config set mcp_servers.codegraph.command codegraph
679+
ocr config set mcp_servers.codegraph.args '["serve","--mcp"]'
680+
ocr config set mcp_servers.codegraph.tools '["codegraph_explore"]'
681+
ocr config set mcp_servers.codegraph.setup 'codegraph init && codegraph index'
682+
```
683+
642684
### Environment Variables
643685

644686
| Variable | Purpose |

README.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -678,6 +678,11 @@ Config file: `~/.opencodereview/config.json`
678678
| `llm.extra_headers` | string | Comma-separated `key=value` HTTP headers |
679679
| `llm.model` | string | `claude-opus-4-6` |
680680
| `llm.use_anthropic` | boolean | `true` \| `false` |
681+
| `mcp_servers.<name>.command` | string | Command to start the MCP server |
682+
| `mcp_servers.<name>.args` | array | Command-line arguments for the MCP server |
683+
| `mcp_servers.<name>.env` | array | Environment variables in `KEY=VALUE` format |
684+
| `mcp_servers.<name>.tools` | array | Allowed tool names (empty = all tools) |
685+
| `mcp_servers.<name>.setup` | string | Setup command to run before starting the server |
681686
| `language` | string | Any language name, e.g. `English`, `Chinese` (default: `English`) |
682687
| `telemetry.enabled` | boolean | `true` \| `false` |
683688
| `telemetry.exporter` | string | `console` \| `otlp` |
@@ -686,6 +691,43 @@ Config file: `~/.opencodereview/config.json`
686691

687692
Environment variables take precedence over the config file.
688693

694+
### MCP Server
695+
696+
Open Code Review supports [Model Context Protocol (MCP)](https://modelcontextprotocol.io/) servers, allowing the review agent to use external tools during code review via the stdio transport.
697+
698+
Configure MCP servers via the CLI:
699+
700+
```bash
701+
# Add an MCP server
702+
ocr config set mcp_servers.<name>.command <command>
703+
ocr config set mcp_servers.<name>.args '["arg1","arg2"]'
704+
ocr config set mcp_servers.<name>.env '["KEY=VALUE"]'
705+
ocr config set mcp_servers.<name>.tools '["tool_name"]'
706+
ocr config set mcp_servers.<name>.setup '<setup command>'
707+
708+
# Delete an MCP server
709+
ocr config unset mcp_servers.<name>
710+
```
711+
712+
| Field | Required | Description |
713+
|-------|----------|-------------|
714+
| `command` | Yes | The executable command to start the MCP server |
715+
| `args` | No | Command-line arguments passed to the server |
716+
| `env` | No | Environment variables in `KEY=VALUE` format |
717+
| `tools` | No | Allowed tool names; if empty, all tools from the server are available |
718+
| `setup` | No | A shell command to run before starting the server (e.g. build an index) |
719+
720+
> **Note:** If an MCP tool's name conflicts with a built-in tool, it will be skipped with a warning. The `setup` command has a 5-minute timeout.
721+
722+
**Example: Add [CodeGraph](https://github.com/nicholasgasior/codegraph) for code structure analysis**
723+
724+
```bash
725+
ocr config set mcp_servers.codegraph.command codegraph
726+
ocr config set mcp_servers.codegraph.args '["serve","--mcp"]'
727+
ocr config set mcp_servers.codegraph.tools '["codegraph_explore"]'
728+
ocr config set mcp_servers.codegraph.setup 'codegraph init && codegraph index'
729+
```
730+
689731
### Environment Variables
690732

691733
| Variable | Purpose |

README.ru-RU.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -675,6 +675,11 @@ OCR разрешает правила ревью по цепочке приор
675675
| `llm.extra_headers` | string | HTTP-заголовки `key=value` через запятую |
676676
| `llm.model` | string | `claude-opus-4-6` |
677677
| `llm.use_anthropic` | boolean | `true` \| `false` |
678+
| `mcp_servers.<name>.command` | string | Команда для запуска MCP-сервера |
679+
| `mcp_servers.<name>.args` | array | Аргументы командной строки для MCP-сервера |
680+
| `mcp_servers.<name>.env` | array | Переменные окружения в формате `KEY=VALUE` |
681+
| `mcp_servers.<name>.tools` | array | Разрешённые имена инструментов (пусто = все инструменты) |
682+
| `mcp_servers.<name>.setup` | string | Команда настройки перед запуском сервера |
678683
| `language` | string | Любое название языка, например `English`, `Chinese` (по умолчанию: `English`) |
679684
| `telemetry.enabled` | boolean | `true` \| `false` |
680685
| `telemetry.exporter` | string | `console` \| `otlp` |
@@ -683,6 +688,43 @@ OCR разрешает правила ревью по цепочке приор
683688

684689
Переменные окружения имеют приоритет над файлом конфигурации.
685690

691+
### MCP-сервер
692+
693+
Open Code Review поддерживает серверы [Model Context Protocol (MCP)](https://modelcontextprotocol.io/), позволяя агенту ревью использовать внешние инструменты во время проверки кода через stdio-транспорт.
694+
695+
Настройка MCP-серверов через CLI:
696+
697+
```bash
698+
# Добавить MCP-сервер
699+
ocr config set mcp_servers.<name>.command <command>
700+
ocr config set mcp_servers.<name>.args '["arg1","arg2"]'
701+
ocr config set mcp_servers.<name>.env '["KEY=VALUE"]'
702+
ocr config set mcp_servers.<name>.tools '["tool_name"]'
703+
ocr config set mcp_servers.<name>.setup '<setup command>'
704+
705+
# Удалить MCP-сервер
706+
ocr config unset mcp_servers.<name>
707+
```
708+
709+
| Поле | Обязательно | Описание |
710+
|------|-------------|----------|
711+
| `command` | Да | Исполняемая команда для запуска MCP-сервера |
712+
| `args` | Нет | Аргументы командной строки для сервера |
713+
| `env` | Нет | Переменные окружения в формате `KEY=VALUE` |
714+
| `tools` | Нет | Разрешённые имена инструментов; если пусто — доступны все инструменты сервера |
715+
| `setup` | Нет | Shell-команда для выполнения перед запуском сервера (например, построение индекса) |
716+
717+
> **Примечание:** Если имя MCP-инструмента конфликтует со встроенным инструментом, он будет пропущен с предупреждением. Таймаут команды `setup` составляет 5 минут.
718+
719+
**Пример: добавление [CodeGraph](https://github.com/nicholasgasior/codegraph) для усиления анализа структуры кода**
720+
721+
```bash
722+
ocr config set mcp_servers.codegraph.command codegraph
723+
ocr config set mcp_servers.codegraph.args '["serve","--mcp"]'
724+
ocr config set mcp_servers.codegraph.tools '["codegraph_explore"]'
725+
ocr config set mcp_servers.codegraph.setup 'codegraph init && codegraph index'
726+
```
727+
686728
### Переменные окружения
687729

688730
| Переменная | Назначение |

README.zh-CN.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -663,6 +663,11 @@ OCR 通过四层优先级链解析评审规则。每层采用首次匹配原则
663663
| `llm.extra_headers` | string | 逗号分隔的 `key=value` HTTP 头 |
664664
| `llm.model` | string | `claude-opus-4-6` |
665665
| `llm.use_anthropic` | boolean | `true` \| `false` |
666+
| `mcp_servers.<name>.command` | string | 启动 MCP 服务器的命令 |
667+
| `mcp_servers.<name>.args` | array | MCP 服务器的命令行参数 |
668+
| `mcp_servers.<name>.env` | array | 环境变量,`KEY=VALUE` 格式 |
669+
| `mcp_servers.<name>.tools` | array | 允许使用的工具名称(为空则允许所有工具) |
670+
| `mcp_servers.<name>.setup` | string | 启动服务器前运行的初始化命令 |
666671
| `language` | string | 任意语言名称,例如 `English``Chinese`(默认:`English`|
667672
| `telemetry.enabled` | boolean | `true` \| `false` |
668673
| `telemetry.exporter` | string | `console` \| `otlp` |
@@ -671,6 +676,43 @@ OCR 通过四层优先级链解析评审规则。每层采用首次匹配原则
671676

672677
环境变量优先级高于配置文件。
673678

679+
### MCP Server
680+
681+
Open Code Review 支持 [Model Context Protocol (MCP)](https://modelcontextprotocol.io/) 服务器,允许评审 Agent 在代码评审过程中通过 stdio 传输协议调用外部工具。
682+
683+
通过 CLI 配置 MCP 服务器:
684+
685+
```bash
686+
# 添加 MCP 服务器
687+
ocr config set mcp_servers.<name>.command <command>
688+
ocr config set mcp_servers.<name>.args '["arg1","arg2"]'
689+
ocr config set mcp_servers.<name>.env '["KEY=VALUE"]'
690+
ocr config set mcp_servers.<name>.tools '["tool_name"]'
691+
ocr config set mcp_servers.<name>.setup '<setup command>'
692+
693+
# 删除 MCP 服务器
694+
ocr config unset mcp_servers.<name>
695+
```
696+
697+
| 字段 | 必填 | 说明 |
698+
|------|------|------|
699+
| `command` || 启动 MCP 服务器的可执行命令 |
700+
| `args` || 传递给服务器的命令行参数 |
701+
| `env` || 环境变量,`KEY=VALUE` 格式 |
702+
| `tools` || 允许使用的工具名称;为空则服务器的所有工具均可用 |
703+
| `setup` || 启动服务器前运行的 shell 命令(例如构建索引) |
704+
705+
> **注意:** 如果 MCP 工具的名称与内置工具冲突,该工具将被跳过并输出警告。`setup` 命令的超时时间为 5 分钟。
706+
707+
**示例:添加 [CodeGraph](https://github.com/nicholasgasior/codegraph) 增强代码结构分析能力**
708+
709+
```bash
710+
ocr config set mcp_servers.codegraph.command codegraph
711+
ocr config set mcp_servers.codegraph.args '["serve","--mcp"]'
712+
ocr config set mcp_servers.codegraph.tools '["codegraph_explore"]'
713+
ocr config set mcp_servers.codegraph.setup 'codegraph init && codegraph index'
714+
```
715+
674716
### 环境变量
675717

676718
| 变量 | 用途 |

0 commit comments

Comments
 (0)