codex-gpt-bridge
Streamable HTTP MCP bridge that allows ChatGPT to delegate code execution requests to a local official Codex MCP server with configurable safety policies.
README
codex-gpt-bridge
Small MCP bridge project for both directions between ChatGPT/OpenAI models and local Codex.
Plain meaning:
- ChatGPT -> Codex: ChatGPT can act as the planner, while this local HTTP MCP server forwards only scoped execution requests to the official
codex mcp-serverrunning on your machine. - Codex -> ChatGPT-like model: Codex can call a local stdio MCP server named
chatgpt, which forwards explicit prompts to the official OpenAI Responses API.
Important boundary: the Codex -> model direction does not call the ChatGPT web UI or ChatGPT private product backend. It uses the official OpenAI API, so it needs OPENAI_API_KEY and API model access.
Daily ChatGPT -> Codex use
Yes, this is MCP. ChatGPT sees Local Codex Bridge Secure as an app with five MCP tools:
bridge_statuscodex_readcodex_runcodex_replycodex_job_status
ChatGPT role: advisor and reviewer
Treat external ChatGPT as the top-level advisor, not as the local executor. Its two best jobs are:
- Before execution: inspect enough repo context through
codex_read, then write the plan, risks, work order, and success checks. - After execution: act as an independent critical reviewer. It should read the changed files or diff through
codex_readand returnPASSor concrete blockers.
Local Codex is still responsible for execution: editing files, running tests, compiling, rendering, inspecting diffs, and committing. Keep ChatGPT tool calls narrow so it can reason well and so the bridge stays stable.
Advisor prompt:
@Local Codex Bridge Secure 调用 codex_read,只传 prompt:你是这个项目的顶层 advisor。只读调查当前 allowed root,先列出和任务相关的 repo facts,然后给出整体方案、执行顺序、风险、验收标准,以及可以交给 Codex 执行的下一步指令;不要修改任何文件。
Reviewer prompt:
@Local Codex Bridge Secure 调用 codex_read,只传 prompt:你是独立 critical reviewer。只读复查当前改动是否满足计划;不要修改、不要编译、不要运行 shell。只输出 status: PASS/NEEDS_CHANGES、blockers、evidence、next_instruction_for_codex。
Best daily path is OpenAI Secure MCP Tunnel. After the one-time setup, keep the local daemon running with the Keychain-backed launcher:
cd /path/to/codex-gpt-bridge
npm run bridge:chatgpt:secure:keychain
Replace /path/to/... examples with your own absolute local paths.
If this is installed as a macOS LaunchAgent, there is no terminal step. Use ChatGPT directly:
@Local Codex Bridge Secure 调用 codex_read,只传 prompt:调查当前 project 顶层有哪些文件和目录,说明每个重要文件的用途;不要修改任何文件。
Prompt templates
Usually you only need the app name and the task. If the bridge has exactly one
allowed root, codex_read uses that root automatically and always forces
Codex read-only. Use codex_run only when you intentionally start write mode.
Fixed agent flow
Use this flow exactly. Do not guess tool names or pass extra arguments.
- Confirm the app can reach the bridge:
@Local Codex Bridge Secure 调用 bridge_status。只返回 allowedRoots、defaultCwd、defaultSandbox、allowWorkspaceWrite、allowDangerFullAccess、upstreamTools。
- For read-only investigation, call
codex_readand pass onlyprompt:
@Local Codex Bridge Secure 调用 codex_read,只传 prompt:<your task>; 不要修改任何文件。
- If the result contains
status=running, copy the exactjobIdand query it explicitly:
@Local Codex Bridge Secure 调用 codex_job_status,只传 jobId:<exact jobId>
- Use
codex_replyonly after a completed read/run returns athreadId. - Use
codex_runonly for intentional write-mode work, after restarting the bridge with a narrowCODEX_GPT_BRIDGE_ROOT. - If ChatGPT says automatic polling was blocked, do not retry the same vague instruction. Paste the exact
jobId. - If ChatGPT cannot see
codex_read, refresh the app in ChatGPT Settings -> Apps -> Local Codex Bridge Secure -> Refresh, then start a new chat.
Status check:
@Local Codex Bridge Secure 调用 bridge_status。只返回 allowedRoots、defaultCwd、defaultSandbox、allowWorkspaceWrite、allowDangerFullAccess、upstreamTools。
Inspect files in a repo:
@Local Codex Bridge Secure 调用 codex_read,只传 prompt:调查当前 allowed root 的顶层文件和目录,说明每个重要文件的用途;不要修改任何文件。如果返回 status=running 和 jobId,继续调用 codex_job_status 直到 completed 或 failed。
If codex_read or codex_run returns status=running, poll the job:
@Local Codex Bridge Secure 调用 codex_job_status:jobId=<job id from codex_read or codex_run>
ChatGPT may block automatic chained polling when it tries to reuse a jobId
from the previous tool result by itself. If that happens, paste the exact
jobId into the next prompt as shown above; that path is verified.
Continue the same Codex thread after codex_read or codex_run returns a threadId:
@Local Codex Bridge Secure 调用 codex_reply:
threadId=<thread id from previous codex_read or codex_run>
prompt=继续上一轮,只读检查 README.md 和 docs/chatgpt-setup.md 是否解释清楚日常用法;不要修改任何文件。
For a different project, restart the bridge with that repo as the only allowed root:
CODEX_GPT_BRIDGE_ROOT="/absolute/path/to/project" npm run bridge:chatgpt:secure:keychain
For edits, keep the root narrow and start write mode only for the target repo:
CODEX_GPT_BRIDGE_ROOT="/absolute/path/to/project" npm run bridge:chatgpt:secure:write:keychain
Then in ChatGPT:
@Local Codex Bridge Secure 调用 codex_run,只传 prompt:在当前 allowed root 内修改我的简历。先检查相关文件,说明计划,然后执行最小改动并运行可用检查。
For iterative review/edit loops, keep each tool call narrow:
codex_read: ask Codex to inspect the file and return a concrete edit plan.codex_run: ask Codex to apply one narrow edit set. Do not ask it to compile, run long shell commands, or do broad cleanup inside the same bridge call.- Verify locally from Codex or your terminal: compile, render, run tests, and inspect the diff.
codex_read: send the updated file back through ChatGPT for review.- Repeat only if ChatGPT returns a real blocker.
Stable edit prompt:
@Local Codex Bridge Secure 调用 codex_run,只传 prompt:只修改当前 allowed root 内的 <file>。按上一轮建议做最小改动;不要编译、不要运行 shell、不要改其他文件。完成后只总结改了什么。
Stable final review prompt:
@Local Codex Bridge Secure 调用 codex_read,只传 prompt:只读复查 <file> 是否已经解决上一轮 blocker;不要修改、不要编译、不要运行 shell。只输出 status: PASS/NEEDS_CHANGES、blockers、notes。
One-time secure setup needs:
security add-generic-password -a "$USER" -s "codex-gpt-bridge:control-plane-api-key" -w "<runtime-api-key>" -U
security add-generic-password -a "$USER" -s "codex-gpt-bridge:control-plane-tunnel-id" -w "tunnel_..." -U
Then configure ChatGPT with Connection = Tunnel, the matching tunnel id, and
Authentication = No Auth.
The older Cloudflare quick tunnel path still exists for smoke tests, but it is not the recommended daily workflow because the URL changes and can fail DNS.
Why
Codex already ships a stdio MCP server with two useful tools:
codex: start a local Codex session.codex-reply: continue a Codex session by thread id.
ChatGPT Apps/GPTs need an HTTP-accessible MCP endpoint. This project is the small missing adapter: HTTP MCP in, official Codex MCP out, with local safety policy in the middle.
For the other direction, Codex can already connect to stdio MCP servers. This project adds codex-chatgpt-mcp, a small MCP server exposing one tool, ask_chatgpt, backed by the OpenAI Responses API.
Safety defaults
- Binds to
127.0.0.1by default. - Accepts
codex_read.cwdandcodex_run.cwdonly under the configured roots. This is a bridge-level starting-directory gate, not OS-level file isolation. - Uses Codex
read-onlysandbox by default. - Requires either
CODEX_GPT_BRIDGE_TOKENor explicit local-onlyCODEX_GPT_BRIDGE_NO_AUTH=1. - Does not expose raw shell, process control, full Codex app-server, or arbitrary Codex config.
- Blocks delegation when sensitive-looking files such as
.env, private keys, or.pemfiles are present under the requested working directory. - Allows
codex_replyonly for threads first created through this bridge, and reruns the sensitive-file preflight before continuing them. - Blocks
workspace-writeunlessCODEX_GPT_BRIDGE_ALLOW_WRITE=1. - Does not expose
danger-full-accessas a per-call ChatGPT option.
Install
npm install
npm run build
Codex CLI must be installed and logged in:
codex --version
codex mcp-server --help
Codex -> ChatGPT-like model
Set an OpenAI API key first:
export OPENAI_API_KEY="<openai-api-key>"
export CODEX_CHATGPT_MODEL="gpt-5.5"
This repository includes a project-scoped Codex MCP config at .codex/config.toml:
[mcp_servers.chatgpt]
command = "npm"
args = ["run", "chatgpt:mcp"]
env_vars = ["OPENAI_API_KEY", "OPENAI_BASE_URL", "CODEX_CHATGPT_MODEL", "CODEX_CHATGPT_TIMEOUT_MS"]
After opening a fresh Codex thread for this trusted project, Codex should have a chatgpt MCP server with one tool:
ask_chatgpt: send an explicit prompt to the configured OpenAI API model and return text. OptionalreasoningEffortvalues for the defaultgpt-5.5model arenone,low,medium,high, andxhigh.
Manual smoke test without real API access:
npm run build
node dist/chatgpt-cli.js
The server runs over stdio and waits for MCP JSON-RPC messages. The automated test suite verifies tool registration and request shaping without calling the real API.
Prefer the project config above because env_vars forwards OPENAI_API_KEY from the running Codex environment without writing the secret into a config file. If you move this MCP config outside the project, add an absolute cwd that points to this repository before using npm run chatgpt:mcp.
Run locally
From the repo you want ChatGPT to delegate into:
CODEX_GPT_BRIDGE_NO_AUTH=1 \
CODEX_GPT_BRIDGE_ROOTS="$PWD" \
npm run dev
Server:
http://127.0.0.1:8765/mcp
For a non-local bind:
export CODEX_GPT_BRIDGE_TOKEN="$(openssl rand -hex 32)"
CODEX_GPT_BRIDGE_HOST=0.0.0.0 \
CODEX_GPT_BRIDGE_ROOTS="/Users/me/project" \
npm run start
Use Authorization: Bearer <token> from your MCP client.
When exposing a localhost server through an HTTPS tunnel, keep the bridge bound to
127.0.0.1 and explicitly allow the tunnel host so the MCP SDK DNS-rebinding
protection accepts the forwarded Host header:
CODEX_GPT_BRIDGE_ALLOWED_HOSTS=127.0.0.1,localhost,your-tunnel.example.com \
CODEX_GPT_BRIDGE_NO_AUTH=1 \
CODEX_GPT_BRIDGE_ROOTS="/Users/me/project" \
npm run start
Use no-auth only for short-lived localhost/tunnel smoke tests. For durable use, put OAuth or a trusted auth proxy in front of the bridge.
ChatGPT connection
For ChatGPT Apps/GPTs, expose the local MCP endpoint with one of:
- OpenAI Secure MCP Tunnel.
- Cloudflare Tunnel.
- ngrok.
Then configure the ChatGPT app/connector MCP URL to the HTTPS /mcp endpoint. Keep the bridge bound to local host where possible and put the tunnel on top.
Built-in bearer-token auth is intended for local development, manual MCP clients, or a trusted proxy. Production ChatGPT Apps that require protected-tool auth should put an OAuth 2.1 / PKCE layer in front of this bridge; OAuth is not implemented in v0.1.
Observed ChatGPT Developer Mode flow:
- Open ChatGPT Settings -> Apps -> Create app.
- Use Server URL.
- Set MCP Server URL to the tunnel HTTPS
/mcpendpoint. - Set Authentication to No Auth for local smoke tests.
- Accept the custom MCP server risk warning and create/connect the app.
- In a chat, mention the app and ask it to call
bridge_status,codex_read,codex_run,codex_reply, orcodex_job_status.
Tools exposed to ChatGPT
bridge_status
Reports bridge policy, allowed roots, and upstream Codex MCP tool availability.
codex_read
Starts a read-only Codex inspection in an allowed working directory. This is the default daily tool for repo investigation and planning context.
It accepts the same prompt, optional cwd, and optional timeoutMs fields as
codex_run, but it does not accept a sandbox option. The bridge always forwards
sandbox=read-only.
Long reads use the same status=running + jobId flow as codex_run.
codex_run
Starts a Codex session in an allowed working directory. Use this for write-mode
workflows; prefer codex_read for read-only investigation.
If Codex finishes quickly, the tool returns the Codex result directly. If Codex
runs longer than CODEX_GPT_BRIDGE_FAST_RETURN_MS, which defaults to 25 seconds,
the tool returns:
{
"status": "running",
"jobId": "..."
}
Call codex_job_status with that jobId until the job is completed or
failed.
Required:
prompt
Optional:
cwd: defaults to the only configured allowed root; required when multiple roots are configured.sandbox:read-onlyby default;workspace-writeappears only when the bridge owner starts write mode.timeoutMs
Approval policy is owner-controlled through CODEX_GPT_BRIDGE_APPROVAL_POLICY; callers cannot lower it per request.
Sensitive file preflight:
codex_read and codex_run refuse to start if they find common secret files under cwd, including .env, .npmrc, .netrc, private SSH key names, .pem, .key, .p12, and .pfx files. Disable only for a deliberately sanitized environment:
CODEX_GPT_BRIDGE_DISABLE_SECRET_SCAN=1 codex-gpt-bridge
codex_reply
Continues a Codex session that was first created through this bridge.
Required:
threadIdprompt
The bridge rejects unknown thread ids and reruns the sensitive-file preflight against the original session directory before forwarding the reply.
Long replies use the same status=running + jobId flow as codex_run.
codex_job_status
Checks a long-running codex_read, codex_run, or codex_reply job.
Required:
jobId
Tracked sessions are in memory only, capped at 1000 entries, and expire after 6 hours. Restarting the bridge clears them.
Development
npm run check
The tests use a fake upstream and do not call the real model.
Existing project comparison
riccilnl/colameta is highly related and much broader: ChatGPT/GPTs to local executors, plan management, preview/apply, reports, and Git closure. It is alpha and its license text forbids commercial use, so this project does not copy its code.
tuannvm/codex-mcp-server is a mature Claude-to-Codex wrapper. It is useful prior art, but this project targets ChatGPT HTTP MCP and safety policy around the official Codex MCP server.
Recommended Servers
playwright-mcp
A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.
Magic Component Platform (MCP)
An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.
Audiense Insights MCP Server
Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.
VeyraX MCP
Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.
graphlit-mcp-server
The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.
Kagi MCP Server
An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.
E2B
Using MCP to run code via e2b.
Neon Database
MCP server for interacting with Neon Management API and databases
Exa Search
A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.
Qdrant Server
This repository is an example of how to create a MCP server for Qdrant, a vector search engine.