-
Notifications
You must be signed in to change notification settings - Fork 59
WIP: Codex MCP investigation - config writing but not working #197
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
mistercrunch
wants to merge
7
commits into
main
Choose a base branch
from
codex-mcp
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
f65abf3 to
23e7d2f
Compare
23e7d2f to
213c934
Compare
Fixes critical bug where Codex couldn't see MCP servers because config was only written to global ~/.codex/config.toml, but Codex prioritizes repo-local .codex/config.toml over global config. Changes: - Write MCP config to worktree-local .codex/config.toml (highest priority) - Also write to global ~/.codex/config.toml as fallback - Include worktreePath in config hash so different worktrees can have different MCP configurations Why this is needed: According to Codex docs, config files have precedence with repo-local config overriding global config. When Codex runs inside a worktree, it checks .codex/config.toml in that directory first, and if found, completely ignores the global config. Verified working: Logs show config is now written to both locations: ✅ [Codex MCP] Updated worktree config with 1 managed MCP server(s) ✅ [Codex MCP] Updated global config with 1 managed MCP server(s) Note: Existing Codex threads won't see newly added MCP servers because Codex locks in MCP configuration at thread creation time. Users must create a new session to pick up MCP servers. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
Reverts to writing MCP config only to global ~/.codex/config.toml. Investigation confirmed that Codex does NOT support repo-local .codex/config.toml files (not mentioned anywhere in official docs). Changes: - Write only to ~/.codex/config.toml (verified supported location) - Remove worktreePath from config hash (not needed for global config) - Add better logging to debug config writing process - Note in code that repo-local config is not supported Investigation findings: - Codex documentation only mentions ~/.codex/config.toml - No mention of repo-local, project-local, or CWD-relative configs - CODEX_HOME environment variable exists but precedence unclear - Help text only references ~/.codex/config.toml Even with this fix, MCP still doesn't work in raw Codex CLI, suggesting deeper SDK or configuration issues beyond file location. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
The @playwright/mcp package requires Playwright browsers to be installed to function. Previously we only installed the npm package, but the actual browser binaries were missing. Changes: - Add system dependencies required by Playwright browsers (Chromium, Firefox, WebKit) - Run `npx playwright install` to download browser binaries - Install before switching to 'agor' user (requires root for system deps) This ensures @playwright/mcp MCP server can actually launch browsers when Codex (or other agents) try to use it. Note: This won't fix the core Codex MCP issue (config is written correctly but Codex still doesn't see servers), but it removes one potential blocker. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
Based on official Codex example-config.md, the 'transport' field is NOT a valid field in Codex MCP server configuration. Codex infers the transport type from which fields are present: - STDIO: when 'command' is specified - HTTP: when 'url' is specified Our config was incorrectly including: ```toml [mcp_servers.playwright_browser_automation] transport = "stdio" # ❌ INVALID - not in Codex config schema command = "npx" args = ["-y", "@playwright/mcp@latest"] ``` Should be: ```toml [mcp_servers.playwright_browser_automation] command = "npx" # ✅ Codex infers STDIO from presence of 'command' args = ["-y", "@playwright/mcp@latest"] ``` This invalid field may have been preventing Codex from recognizing the MCP server configuration entirely! Reference: https://github.com/openai/codex/blob/main/docs/example-config.md 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Status: Work in Progress / Reference Only⚠️
This PR documents investigation and attempted fixes for Codex MCP support. MCP still does not work with Codex even after these changes. Keeping as reference for future work.
Summary
Attempted to enable MCP server support for Codex by writing MCP configuration to
~/.codex/config.toml. The config is written correctly but Codex still doesn't see or use MCP servers, even in the raw CLI.What's in This Branch
1. STDIO Bridge Script (Previous Work)
scripts/agor-mcp-stdio-bridge.jsfor HTTP-to-STDIO translation2. Playwright MCP Installation (Previous Work)
@playwright/mcp@latestto Docker container3. Config Writing Logic (Latest Commits)
First attempt: Tried writing to both worktree-local and global config
.codex/config.toml~/.codex/config.tomlCurrent approach: Write only to global
~/.codex/config.tomlInvestigation Findings
Config File Location ✅
~/.codex/config.toml(confirmed from docs).codex/config.toml(no documentation)CODEX_HOMEenvironment variable not tested/confirmedConfig Writing ✅
From Docker logs:
Config file contains:
Still Not Working ❌
Even with correct config, Codex doesn't see MCP servers:
codexCLI also doesn't show MCP resourcesPossible causes:
@playwright/mcppackage itself has issuesThread-Level MCP Locking ✅ (Documented Limitation)
Existing Codex threads lock in MCP config at creation time. This is a known Codex SDK limitation. New sessions correctly get MCP servers attached, but existing sessions can't pick up newly added servers.
Agor handles this correctly with warnings in logs.
What Works
~/.codex/config.tomlWhat Doesn't Work
codexCLIFiles Changed
packages/core/src/tools/codex/prompt-service.ts- Config writing logic (simplified to global only)scripts/agor-mcp-stdio-bridge.js- HTTP-to-STDIO bridge (created earlier, unused)Dockerfile.dev- Playwright MCP installation (created earlier)Next Steps for Investigation
codexCLICommits
2978620- Initial fix: write to worktree-local config (incorrect assumption)64a9dd2- Revert to global config only (correct approach)🤖 Generated with Claude Code