MCP bridge CLI that connects OpenAI Codex to agentrq workspaces.
Warning
Pre-Alpha: This project is in early development. APIs, configurations, and behaviors are subject to change without notice.
@agentrq/codex-gateway bridges the Model Context Protocol (MCP) with the Codex app-server protocol (JSON-RPC 2.0 over stdio).
It automates task execution by:
- Loading your workspace's
.mcp.jsonconfiguration. - Connecting to the agentrq MCP server.
- Spawning
codex app-serveras a subprocess. - Routing tasks from agentrq to Codex threads/turns.
- Collecting agent replies and sending them back to agentrq.
- Auto-reconnecting the MCP transport on disconnection.
- Node.js >= 20
- OpenAI Codex CLI (
npm install -g @openai/codex) - An agentrq workspace with an HTTP MCP server
npm install -g @agentrq/codex-gateway@latestCodex reads project-level MCP server config from .codex/config.toml. Create this file so the Codex agent can use agentrq tools directly during task execution (replace <WORKSPACEID> and <TOKEN> with your values from the agentrq dashboard):
mkdir -p .codex
cat >> .codex/config.toml << 'EOF'
[mcp_servers.agentrq-workspace]
url = "https://<WORKSPACEID>.mcp.agentrq.com/mcp?token=<TOKEN>"
EOFCreate a .mcp.json in your project root so codex-gateway can connect to the same agentrq workspace:
{
"mcpServers": {
"agentrq": {
"type": "http",
"url": "https://<WORKSPACEID>.mcp.agentrq.com/mcp?token=<TOKEN>"
}
}
}Note:
.mcp.jsonis used bycodex-gatewayto receive tasks..codex/config.tomlis used by the Codex agent itself to call agentrq tools (e.g.reply,updateTaskStatus) during execution.
Run codex-gateway from your agentrq workspace root (the directory containing .mcp.json):
# Default: runs `codex app-server`
codex-gateway
# Custom codex command
codex-gateway -- codex app-server| Variable | Description | Default |
|---|---|---|
CODEX_MODEL |
Override the model used for all threads/turns | (codex default) |
codex-gateway searches for .mcp.json starting in the current working directory and up to 3 parent directories.
Example .mcp.json:
{
"mcpServers": {
"agentrq": {
"type": "http",
"url": "https://your-workspace.mcp.agentrq.com?token=..."
}
}
}codex-gateway prefers servers with agentrq in the name; falls back to the first HTTP server with a url.
┌──────────────────────────┐ JSON-RPC 2.0 / JSONL ┌─────────────────┐
│ codex app-server │ ◄─────────────────────────► │ │
│ (OpenAI Codex agent) │ │ codex-gateway │
└──────────────────────────┘ │ │
│ MCP Bridge │
│ │
┌───────────────────┤ │
│ │ │
▼ └─────────────────┘
┌───────────────────────────┐
│ agentrq MCP Server │
│ (HTTP / StreamableHTTP) │
└───────────────────────────┘
- Config Loading — Reads
.mcp.jsonto find the agentrq MCP server. - MCP Connection — Establishes a
StreamableHTTPClientTransportwith automatic retry and reconnection. - Codex Spawning — Launches
codex app-servervia stdio. - Handshake — Sends
initialize+initializedto the Codex app-server. - Task Routing — When a task arrives from agentrq:
- Extracts
chat_idas the task identifier. - Creates a new Codex thread for the chat (or reuses one if the same
chat_idarrives again). - Starts a turn with the task content.
- Streams
item/agentMessage/deltanotifications into a reply buffer.
- Extracts
- Reply — When
turn/completedfires, sends the buffered text back via agentrq'sreplytool. - Recursive Execution — After each task, checks for the next pending task automatically.
| File | Description |
|---|---|
src/index.ts |
Entry point; orchestrates config loading, MCP connection, Codex spawning, and task lifecycle. |
src/codexClient.ts |
JSON-RPC 2.0 client for the Codex app-server — handles JSONL I/O, request correlation, and turn completion. |
src/mcpClient.ts |
EventEmitter-based MCP client with auto-reconnection, notification handling, and tool call dispatch. |
src/config.ts |
Parses .mcp.json from the current directory tree up to 3 levels deep. |
src/taskIdentity.ts |
Extracts chat_id from MCP notification metadata or task text. |
# Install dependencies
npm install
# Run in development mode
npm run dev
# Type-check
npm run typecheck
# Run tests
npm testContributions are welcome! Please feel free to submit pull requests or open issues.
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add: amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
By contributing to this project, you agree that your contributions will be licensed under the project's Apache License 2.0.
Apache License 2.0
Copyright (c) 2026 Contextual, Inc.
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.