Codex 2.0 MCP Gateway
Turns a Mac into an MCP host exposing terminal, filesystem, browser automation, and macOS controls to approved AI clients via OpenAI's Secure MCP Tunnel.
README
Codex 2.0 — laptop-hosted MCP gateway
Codex 2.0 turns a Mac into a powerful MCP host that approved AI clients can reach through an OpenAI Secure MCP Tunnel. It exposes terminal, filesystem, Playwright browser automation, macOS screenshots and Accessibility controls, installed Codex skill discovery, and a local activity journal.
What it provides
- One-shot and persistent interactive terminal tools.
- Filesystem access, configured by default from
/. - A dedicated Playwright/CDP browser session.
- macOS screenshots, application activation, Accessibility inspection, mouse, and keyboard controls.
- Discovery and reading of locally installed Codex skills and plugin metadata.
- Workspace-bound tool activity journals under
~/.codex/gateway_sessions. - A safety-oriented MCP instruction policy from
OPERATING_POLICY.md.
Codex's signed Computer Use process, trusted Chrome-extension runtime, hidden system prompt, and OpenAI-hosted connector OAuth sessions cannot be copied into an independent MCP server. This project provides direct local equivalents where possible; clients must connect services such as Google Drive or GitHub separately.
Requirements
- macOS with Python 3.11 or newer.
zsh, Node.js, and npm.- OpenAI Secure MCP Tunnel access, including:
- the
tunnel-clientexecutable; - a provider-generated tunnel ID;
- your own OpenAI Platform runtime API key.
- the
- A ChatGPT plan/workspace that supports custom MCP apps, or another MCP client compatible with the tunnel.
- Optional desktop controls:
brew install cliclick- macOS Screen Recording and Accessibility permission for the launching terminal or tunnel process.
Secure MCP Tunnel is documented for enterprise customers. Creating and managing a tunnel requires the appropriate OpenAI Platform organization permissions, and ChatGPT developer mode is a separate workspace permission. If either surface is unavailable, ask the relevant Platform organization or ChatGPT workspace administrator. This repository does not create or bypass access.
Cost and billing
Do not assume the complete setup is free or consumes no credits:
- The tunnel layer is transport, not inference. Creating a
tunnel_id, authenticatingtunnel-clientto the OpenAI control plane, and keeping that tunnel connected do not themselves call a model or consume model-inference tokens/credits. The runtime API key is used for tunnel/control-plane authentication; merely supplying it does not create an inference request. - This repository and its local Python server do not independently call an OpenAI model merely by running the gateway.
- Secure MCP Tunnel is an enterprise feature. Availability and commercial terms depend on the OpenAI organization/workspace agreement; OpenAI does not document it as an unconditional free service.
- When ChatGPT invokes the MCP, the ChatGPT conversation/model usage remains subject to that workspace's plan, usage limits, credits, and administrator settings. The tunnel does not erase or duplicate those charges.
- If an MCP client separately calls OpenAI models or hosted tools through the Responses API or another Platform API, those requests can be billed at current API rates. A tunnel runtime key must not be treated as a promise that all OpenAI API-key usage is free.
Step-by-step setup
1. Clone and create the Python environment
git clone https://github.com/MeharPro/codex-2.0.git
cd codex-2.0
python3 -m venv .venv
./.venv/bin/python -m pip install --upgrade pip
./.venv/bin/pip install -r requirements.txt
./.venv/bin/playwright install chromium
2. Confirm tunnel and ChatGPT permissions
Open the official Secure MCP Tunnel guide and confirm the intended operator has:
- Tunnels Read + Manage in the OpenAI Platform organization to create or edit a tunnel.
- Tunnels Read + Use to run
tunnel-clientand select the tunnel from a supported product. - ChatGPT developer-mode access in the target workspace. This is administered separately from Platform tunnel permissions.
3. Create the tunnel in OpenAI Platform
- Open Platform tunnel settings.
- Select the Platform organization that should own the tunnel.
- Choose Create tunnel.
- Enter a descriptive display name, such as
codex-2-macbook. The name is for humans and may be chosen by you. - Add a clear description, such as
Local Codex 2.0 MCP gateway. - Associate the target ChatGPT workspace and any Platform organization that should be allowed to discover or use the tunnel.
- Create the tunnel and copy the resulting
tunnel_id.
OpenAI generates the actual ID in the form tunnel_.... Do not invent an ID
from the display name. The same ID is used by tunnel-client and ChatGPT.
Adding another allowed organization/workspace does not create a new ID.
If your organization manages tunnels through the CLI instead, an administrator
can run tunnel-client admin tunnels create with a name, description, and the
intended organization/workspace IDs. This requires an admin key and tunnel
management permission; the long-lived runtime should use a separate runtime
key, not the admin key.
4. Install the OpenAI tunnel client
Download tunnel-client from the link in
Platform tunnel settings
or from the
latest public release.
Keep the binary somewhere on PATH, then verify it:
tunnel-client --version
tunnel-client help quickstart
If it is installed outside PATH, set its absolute location as
TUNNEL_CLIENT in .env.
5. Create and safely store your OpenAI runtime API key
- Open the owning organization's Runtime API keys page.
- Create your own key for this runtime, using a recognizable name such as
codex-2-runtime. - Ensure the key's principal has Tunnels Read + Use for the tunnel.
- Copy the key when OpenAI displays it. Do not use an organization admin key as the long-lived runtime key.
Save that OpenAI Platform key outside the repository. The following zsh commands accept it without putting the value directly in the command line:
mkdir -p "$HOME/.config/codex-mcp"
chmod 700 "$HOME/.config/codex-mcp"
read -s "runtime_key?Paste your OpenAI runtime API key: "
printf '%s' "$runtime_key" > "$HOME/.config/codex-mcp/runtime-api-key"
unset runtime_key
chmod 600 "$HOME/.config/codex-mcp/runtime-api-key"
This is where the user supplies their own OpenAI API key. The gateway does not
put it in .env, pass it to terminal tools, or commit it to Git.
6. Paste the tunnel ID into the ignored local configuration
cp .env.example .env
chmod 600 .env
Edit .env and replace:
TUNNEL_ID=tunnel_REPLACE_ME
with the provider-generated ID copied from Platform tunnel settings:
TUNNEL_ID=tunnel_YOUR_OWN_ID
Leave RUNTIME_API_KEY_FILE pointing to the mode-600 key file created in the
previous step. Keep .env local—it is ignored by Git.
7. Install the one-line command
mkdir -p "$HOME/.local/bin"
ln -sf "$PWD/bin/codex-mcp" "$HOME/.local/bin/codex-mcp"
Add ~/.local/bin to your shell PATH if needed:
export PATH="$HOME/.local/bin:$PATH"
8. Start the gateway in a project folder
cd /path/to/project
codex-mcp
Or pass the folder directly:
codex-mcp /path/to/project
The selected folder becomes the default terminal working directory. Switching to another folder restarts the managed runtime so the new workspace is applied.
Useful lifecycle commands:
codex-mcp status
codex-mcp restart /path/to/project
codex-mcp stop
For diagnostics, use the provider-supported checks:
tunnel-client runtimes status codex-tool-gateway --json
tunnel-client doctor --profile codex-tool-gateway --explain
Do not use nohup or disown; codex-mcp uses the client's managed runtime
supervision.
9. Connect ChatGPT
Keep codex-mcp running during discovery and use:
- Enable developer mode for your ChatGPT workspace/account.
- Open Settings → Plugins or chatgpt.com/plugins.
- Select the plus button to create a developer-mode app.
- Under Connection, choose Tunnel.
- Select the tunnel by its display name. If it is not listed, paste the same
provider-generated
tunnel_idused in.env. - Scan the MCP tools.
- Review every action, especially terminal, filesystem, keyboard, mouse, and write operations.
- Create or publish the app and explicitly connect it for your user.
- Start a new chat, select the app, and ask it to call
gateway_infofollowed byterminal_status.
If the tunnel does not appear, verify that it is associated with the target ChatGPT workspace and that the app creator has Tunnels Read + Use.
ChatGPT freezes an approved snapshot of tool definitions. After updating this server, refresh its actions in Enterprise/Edu. A published Business custom app may need to be recreated and republished to adopt changed tools.
10. Connect another MCP client
Use the tunnel endpoint and authentication details provided by OpenAI in the client's remote-MCP configuration. For a local stdio smoke test, point the client directly at:
/absolute/path/to/codex-2.0/.venv/bin/python
/absolute/path/to/codex-2.0/gateway.py
The first line is the command and the second is its argument. Set
CODEX_MCP_WORKSPACE=/path/to/project when launching locally if you want a
specific default folder.
Browser and desktop setup
The browser tools use Chrome DevTools Protocol at
http://127.0.0.1:9222 by default. Launch a dedicated Chrome profile:
open -na "Google Chrome" --args \
--remote-debugging-port=9222 \
--user-data-dir="$HOME/.codex-gateway/chrome-profile"
Override the endpoint with CDP_URL if needed.
For desktop tools, grant Screen Recording and Accessibility permission in
System Settings → Privacy & Security to the terminal or process launching
tunnel-client.
Local verification
Check syntax without exposing credentials:
./.venv/bin/python -m py_compile gateway.py host_bridge/ctf_browser_mcp.py
zsh -n bin/codex-mcp
Start the stdio MCP server locally:
CODEX_MCP_WORKSPACE="$PWD" ./.venv/bin/python gateway.py
It will wait for MCP messages on standard input. Press Control-C to stop it.
Session history
Each gateway process records tool starts, finishes, failures, duration, and redacted arguments under:
~/.codex/gateway_sessions/YYYY/MM/DD/<session-id>.jsonl
The MCP does not receive the complete ChatGPT transcript, so these files contain
tool activity and explicit gateway_session_note entries—not native Codex
sidebar history.
Updating
codex-mcp stop
git pull --ff-only
./.venv/bin/pip install -r requirements.txt
codex-mcp /path/to/project
Refresh or republish the ChatGPT app if the tool schema changed.
Security reminder
Anyone who can invoke this MCP can potentially read or change files and execute commands as your macOS user. Keep the runtime key private, constrain app access, review action permissions, and stop the gateway when it is not needed.
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。