chatgpt-review-mcp
by Git-ycy
README.md
# chatgpt-review-mcp
A Model Context Protocol (MCP) server that lets Claude Code (or any MCP-compatible client) send prompts to your **logged-in ChatGPT web session** via Chrome DevTools Protocol. Use it to get a second opinion from GPT without consuming Anthropic tokens or OpenAI API quota — the request goes through your normal browser session using whichever model you have selected in the ChatGPT UI.
Runs on **WSL2 (Ubuntu) + Windows Chrome**. Adapting it to other setups is straightforward but not covered here.
## Architecture
```
Claude Code (WSL)
└─► MCP stdio ──► mcp_server.py (WSL)
└─► playwright.connect_over_cdp ──► 172.26.80.1:9222
│
(netsh portproxy)
▼
Chrome CDP on ::1:9222
│
chatgpt.com tab (logged in)
```
The MCP process runs in WSL. It reuses the Windows Chrome instance you have logged into ChatGPT — no headless browser, no API keys, no scraping-detection fights.
## Prerequisites
- Windows 10/11 with WSL2 Ubuntu
- Chrome installed at `C:\Program Files\Google\Chrome\Application\chrome.exe`
- A paid or free ChatGPT account with a session that stays logged in
- Python 3.10+ inside WSL
## Setup
### 1. Windows-side: launch a dedicated CDP Chrome
Use a **separate profile** so the CDP Chrome does not conflict with your daily Chrome. From WSL:
```bash
bash start-chrome.sh
```
This runs `powershell.exe Start-Process chrome.exe --remote-debugging-port=9222 --user-data-dir=C:\chrome-cdp-profile https://chatgpt.com` and opens a fresh Chrome window. Log in to ChatGPT once — the profile will remember it.
### 2. Windows-side: port forwarding for WSL access
Chrome 149+ only binds `::1:9222` (IPv6 loopback), so WSL cannot reach it directly through the `172.26.80.1` gateway. Fix with one command in **administrator PowerShell**:
```powershell
netsh interface portproxy add v4tov6 listenaddress=0.0.0.0 listenport=9222 connectaddress=::1 connectport=9222
```
Optionally allow the port through Windows Firewall:
```powershell
New-NetFirewallRule -DisplayName "Chrome CDP 9222 (WSL)" -Direction Inbound -Protocol TCP -LocalPort 9222 -Action Allow -Profile Any
```
To remove later: `netsh interface portproxy delete v4tov4 listenaddress=0.0.0.0 listenport=9222`
### 3. WSL-side: Python dependencies
```bash
cd chatgpt-review-mcp
python -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt
```
`playwright` is used only for CDP connection — you do **not** need to run `playwright install`, no local browsers are downloaded.
### 4. Verify connectivity
```bash
python test_connect.py
```
Expected output includes `Chrome: Chrome/...`, the list of open tabs, and `[✓] 找到 ChatGPT 页面`. If it times out, the portproxy in step 2 is usually the culprit.
### 5. Register with Claude Code
```bash
claude mcp add --scope user chatgpt-review -- \
/absolute/path/to/chatgpt-review-mcp/.venv/bin/python \
/absolute/path/to/chatgpt-review-mcp/mcp_server.py
```
Restart Claude Code, then `claude mcp list` should show `chatgpt-review: ... - ✓ Connected`.
## Usage
Once registered, ask Claude Code something like:
- "让 ChatGPT 审一下这个方案:..."
- "Get a second opinion from GPT on this design"
- "用 review_with_chatgpt 帮我看看这段代码"
The `review_with_chatgpt` tool takes:
| Arg | Type | Default | Meaning |
|-----|------|---------|---------|
| `prompt` | str | — | Message to send to ChatGPT (include enough context — GPT does not see your Claude Code conversation) |
| `wait_timeout` | int | 180 | Max seconds to wait for the reply to finish streaming |
| `new_chat` | bool | False | If True, open a **fresh conversation** so there is no prior turn history |
### Making `new_chat=True` truly context-free
ChatGPT has two other memory sources besides the current conversation:
1. **Memory** (explicitly saved facts about you)
2. **Reference chat history** (implicit recall of your other conversations)
Both default **on**. For a strict "independent reviewer with no context" setup, disable both in ChatGPT: profile picture → Settings → Personalization → toggle off *Memory* and *Reference chat history*.
## Command-line use
`chatgpt_client.py` also works standalone:
```bash
python chatgpt_client.py "explain LogSumExp in one sentence"
```
## Troubleshooting
- **`HTTP 探针失败: timed out`** — Windows Firewall or the portproxy rule is not in place. Confirm with `powershell.exe -Command "netsh interface portproxy show all"`.
- **`Get-NetTCPConnection ... 9222` shows `127.0.0.1:9222`** — you are on an old Chrome that still binds IPv4; use a `v4tov4` rule instead of `v4tov6`.
- **MCP returns `"Retry"`** — happens if a previous ChatGPT generation was interrupted and the page still shows a Retry button. The client now polls for text stability and filters this out; if you still hit it, refresh the ChatGPT tab manually.
- **Selectors break** — ChatGPT occasionally changes its DOM. Update the constants at the top of `chatgpt_client.py`: `INPUT_SELECTORS`, `STOP_BUTTON_SELECTORS`, `ASSISTANT_MSG_SELECTOR`.
## Files
| File | Purpose |
|------|---------|
| `chatgpt_client.py` | Core CDP + playwright logic; `ask_chatgpt()` async entry point |
| `mcp_server.py` | FastMCP wrapper exposing `review_with_chatgpt` tool |
| `test_connect.py` | Diagnostic script for the CDP handshake |
| `start-chrome.sh` | Launch CDP Chrome from WSL (recommended) |
| `start-chrome.bat` | Same, as a double-clickable batch file |
| `requirements.txt` | `mcp`, `playwright`, `httpx` |
## License
MIT.
This server cannot be deployed
Maintenance
ActivityStale
ResponsivenessNo issues