# nezha-mcp **Repository Path**: futurecodes/nezha-mcp ## Basic Information - **Project Name**: nezha-mcp - **Description**: nezha mcp - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: main - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2026-06-19 - **Last Updated**: 2026-06-20 ## Categories & Tags **Categories**: Uncategorized **Tags**: MCP ## README # nezha-mcp Standalone MCP server for operating a Nezha ChatGPT web account like a human user. It exposes explicit tools for browsing conversations, choosing models and composer modes, sending messages, and uploading files. Each user should run their own local copy with their own Nezha account credentials. ## What it does - logs into Nezha with the local `.env` - lists and selects account nodes - lists and opens sidebar conversations - starts a new chat or continues an existing conversation - lists models and mode candidates - remembers selected model and mode locally - sends prompts with optional attachments - exposes MCP resources for status, selection, models, modes, and conversations ## Quick start ```bash cp .env.example .env uv sync ``` Fill in at least: ```dotenv NEZHA_USERNAME=your_nezha_username NEZHA_PASSWORD=your_nezha_password NEZHA_BASE_URL=https://www.nezhasoft.com DEFAULT_MODEL= ``` ## Two ways to use This MCP server supports two transport modes. Pick the one that fits your use case. ### Option A: STDIO (local, personal use) The MCP client (Claude Code, Cursor, etc.) launches the server as a **child process** each time it starts, and communicates through stdin/stdout pipes. - ✅ Simplest setup — no port, no network - ✅ Each user runs their own copy with their own credentials - ❌ Code must be installed locally on every machine - ❌ Cannot be shared with others over the network **Step 1:** Add to your MCP client config (Claude Code `settings.json`, Cursor `mcp.json`, etc.): ```json { "mcpServers": { "nezha": { "command": "uv", "args": ["run", "python", "-m", "mcp_nezha.server"], "cwd": "/absolute/path/to/nezha-mcp" } } } ``` **Step 2:** Restart your MCP client. It will automatically start the server when needed. > The client forks a child process each time it starts. The child dies when the > client exits. No port is used, no manual `uv run` needed. ### Option B: Streamable HTTP (remote, team use) The server runs as a **standalone HTTP service**. Remote MCP clients connect to it over the network. - ✅ One server, multiple users can connect - ✅ Clients don't need the code — just a URL - ✅ Server stays running independently - ❌ Needs a port open (default 3004) - ❌ Network security required (firewall, VPN, or reverse proxy) **Step 1:** Set transport in `.env`: ```dotenv MCP_TRANSPORT=streamable-http API_HOST=0.0.0.0 API_PORT=3004 ``` **Step 2:** Start the server (on your server machine): ```bash uv run python -m mcp_nezha.server ``` The MCP endpoint is now at `http://:3004/mcp`. **Step 3:** Remote clients connect with: ```json { "mcpServers": { "nezha": { "url": "http://your-server-ip:3004/mcp" } } } ``` > **Security:** When binding to `0.0.0.0`, anyone on the network can reach your > MCP server. Use firewall rules, a reverse proxy with auth, or a VPN to limit > access. ## Architecture ``` ┌─────────────────────────────────────────────────────────┐ │ Nezha MCP │ │ │ │ ┌──────────────┐ ┌──────────────────────────────┐ │ │ │ mcp_nezha/ │ │ app/ │ │ │ │ │ │ │ │ │ │ server.py ──┼───▶│ conversation.py │ │ │ │ (FastMCP) │ │ (chat turn: send → reply) │ │ │ │ │ │ │ │ │ │ operator.py─┼───▶│ upstream.py ──▶ Nezha API │ │ │ │ │ │ │ │ │ └──────────────┘ └──────────────────────────────┘ │ │ │ │ Transport: STDIO (local) or Streamable HTTP (remote) │ └─────────────────────────────────────────────────────────┘ ``` - `mcp_nezha/` — MCP server exposing tools/resources for AI clients - `app/` — core Nezha conversation logic and upstream HTTP client - `mcp_nezha/operator.py` imports `_send_nezha_turn` from `app/conversation.py` directly ## Environment variables | Variable | Default | Description | |----------|---------|-------------| | `NEZHA_USERNAME` | — | Nezha account username (required) | | `NEZHA_PASSWORD` | — | Nezha account password (required) | | `NEZHA_BASE_URL` | `https://www.nezhasoft.com` | Nezha web origin | | `NEZHA_AUTH_TOKEN` | — | Reusable auth token (optional) | | `NEZHA_COOKIE` | — | Reusable cookie (optional) | | `NEZHA_SELECTED_CAR_ID` | — | Pin to a specific node ID | | `MCP_TRANSPORT` | `stdio` | `stdio` or `streamable-http` | | `API_HOST` | `0.0.0.0` | HTTP listen host | | `API_PORT` | `3004` | HTTP listen port | | `API_KEY` | `change-me-local-key` | Bearer token for HTTP auth | | `DEFAULT_MODEL` | — | Default model slug | | `MODEL_ALLOWLIST` | — | Comma-separated model filter | | `REQUEST_TIMEOUT_SECONDS` | `120` | Upstream HTTP timeout | | `STREAM_TIMEOUT_SECONDS` | `900` | Max seconds to wait for one streamed reply | | `NEZHA_OUTPUT_DIR` | `nezha-outputs` | Directory for downloaded outputs | ## Tools - `nezha_status` — auth, subscription, quota, default model - `nezha_current_selection` — current node, conversation, model, mode - `nezha_list_nodes` — list shared ChatGPT account nodes - `nezha_select_node` — select and enter a node - `nezha_list_conversations` — list sidebar conversations - `nezha_get_conversation` — load full conversation with messages - `nezha_select_conversation` — open/select a conversation - `nezha_new_chat` — clear selection for new chat - `nezha_list_models` — list available models and quota - `nezha_list_modes` — list chat/agent/research modes - `nezha_select_model` — remember preferred model - `nezha_select_mode` — remember preferred mode - `nezha_stream_status` — check if conversation is generating - `nezha_upload_file` — prepare local file for upload (max 100MB) - `nezha_send_message` — send/continue a chat turn ## Resources - `nezha://status` - `nezha://selection` - `nezha://models` - `nezha://modes` - `nezha://conversations/recent` - `nezha://conversation/{conversation_id}` ## Local files - `.nezha-login-cache.json`: cached login cookies and access token - `.nezha-mcp-state.json`: selected conversation, node, model, mode, and ids - `.nezha-mcp-modes.json`: optional local mode presets promoted from captures These files are ignored by git and stay on each user's machine. They do not store prompt text or full conversation bodies. ## Share with friends **Via STDIO (each person runs their own):** - each friend clones the repo and creates their own `.env` - do not share `.env`, browser cookies, or login cache files - the MCP actions operate on that user's own Nezha account - if friends install in different directories, only the `cwd` in the MCP config needs to change **Via Streamable HTTP (one server, many users):** - one person runs the server with `MCP_TRANSPORT=streamable-http` - share the URL `http://:3004/mcp` with friends - each friend only needs to add the URL to their MCP client config — no code installation needed - all users share the same Nezha account on the server side ## Smoke test Check the direct operator layer: ```bash uv run python tools/smoke_mcp_nezha.py --conversations ``` Check the FastMCP tool layer: ```bash uv run python tools/smoke_mcp_server.py --conversations ``` ## Capture and mode replay Run Playwright capture: ```bash set -a && source .env && set +a npx -y playwright@1.60.0 test tools/inspect_nezha.spec.ts --project=chromium --headed ``` Analyze captured `/backend-api/f/conversation` payloads: ```bash uv run python tools/analyze_nezha_capture.py network-capture.json ``` To promote verified mode presets, copy [`docs/nezha-mcp-modes.example.json`](docs/nezha-mcp-modes.example.json) to `.nezha-mcp-modes.json` and replace each `raw_mode_replay` block with analyzer output.