You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Plugin MCP servers: no workspace/project-root signal (hooks have cwd; MCP servers don't) #37903
CLIIssues related to the Codex CLIenhancementNew feature or requestmcpIssues related to the use of model context protocol (MCP) serversskillsIssues related to skills
A plugin ships a stdio MCP server that serves per-project data (in our case: a per-project knowledge index — the server must know which project the session is working in to serve the right one). Hooks can do this today: every hook payload carries cwd with the session working directory. Plugin MCP servers cannot.
Current behavior (codex-cli 0.146.0)
A plugin-registered stdio MCP server with "cwd": "." is spawned in the plugin's materialized cache directory (~/.codex/plugins/cache/<marketplace>/<plugin>/<version>/), so process.cwd() carries no project information.
No substitution token or injected environment variable exposes the workspace/session root to plugin MCP server configs (nothing analogous to hook payload cwd; env_vars only whitelists variables from the codex process environment, which requires a manual per-shell export).
The MCP client does not declare the roots capability, so roots/list is unavailable as an in-protocol signal (codex-rs/codex-mcp/src/rmcp_client.rs constructs client capabilities without roots as of rust-v0.146.0).
The net effect: a plugin MCP server cannot be project-aware without asking users to export an environment variable in every shell before launching codex.
Ask
Any one of these would close the gap:
A substitution token for plugin MCP server env/args values that resolves to the session workspace root (the equivalent of the cwd field hooks already receive), or
An injected environment variable carrying the workspace root in the MCP server child process, or
Declaring the roots capability and answering roots/list with the workspace folder.
Option 1 or 2 seems most consistent with the existing hook contract, and with the MCP spec's 2026-07-28 direction (Roots is deprecated there in favor of server configuration).
Environment
codex-cli 0.146.0, macOS
Plugin installed via codex plugin add from a marketplace repo
Injected env var (option 2): set CODEX_WORKSPACE_ROOT (and maybe CODEX_SESSION_CWD, mirroring the hook payload's cwd) unconditionally in the child env at spawn. Smallest change, zero config surface.
Substitution token (option 1): expand something like ${workspaceRoot} in args/env values before spawn. This pairs naturally with Agent Plugin mcp.json does not resolve ${VAR} env values for MCP servers #38438, which reports that plugin mcp.json${VAR} env references aren't resolved at all today — one substitution pass could fix both.
One caveat worth designing for: server processes are currently spawned per connection-set and can outlive a single session or serve a session whose cwd changes mid-thread (ThreadSettingsOverrides supports cwd updates, and #38585 wants /cd). An env var freezes the value at spawn; if mid-session correctness matters, the MCP-spec answer is passing it per-request (e.g. _meta) rather than per-process — worth stating which contract the feature promises.
We have the same problem with the Nx plugin (nrwl/nx-ai-agents-config). Its stdio nx-mcp server needs to know which Nx workspace the session is in. Codex starts the server in the plugin's cache directory, so it can't find the workspace. As a workaround, every repository that uses the plugin declares [mcp_servers.nx-mcp] in its .codex/config.toml (command = "npx", args = ["nx", "mcp"]) to replace the plugin's server. That defeats much of the point of shipping the server in a plugin.
Still reproducible on codex-cli 0.166.0. I logged process.cwd() and the environment from a probe stdio server, with codex exec run from a workspace:
Plugin manifest
Server cwd
Workspace signal
Agent Plugins format (root plugin.json + mcp.json)
.codex-plugin/plugin.json only ("mcpServers": "./mcp.json")
the session's cwd (the workspace)
cwd
both manifests
the plugin cache directory (the Agent Plugins manifest wins)
none
So the two plugin formats behave differently. A plugin with a Codex manifest gets the workspace as its cwd. The same plugin written to the Agent Plugins format can't get the workspace at all, because the spec's cwd pattern only allows paths under ./, ${PLUGIN_ROOT} or ${PLUGIN_DATA}, and Codex applies that rule (#36796).
Any of the three options above would fix this for us. An injected CODEX_WORKSPACE_ROOT, or a ${workspaceRoot} placeholder allowed in args/env, would let Agent Plugins servers get back what Codex-manifest plugins already have.
CLIIssues related to the Codex CLIenhancementNew feature or requestmcpIssues related to the use of model context protocol (MCP) serversskillsIssues related to skills
Activity
feat(plugins): codex MCP launcher joins the chain via --default-root
jdcodes1 commentedon Aug 18, 2026
Implementation note supporting option 1/2: the plumbing is one hop away. The stdio launcher already threads a
fallback_cwd(used when the server config omitscwd) plus per-serverenv_varsthrough spawn (https://github.com/openai/codex/blob/1f41cc5d92/codex-rs/rmcp-client/src/stdio_server_launcher.rs#L190-L199,#L94-L95) — so both proposed shapes are local changes at the same site:CODEX_WORKSPACE_ROOT(and maybeCODEX_SESSION_CWD, mirroring the hook payload'scwd) unconditionally in the child env at spawn. Smallest change, zero config surface.${workspaceRoot}inargs/envvalues before spawn. This pairs naturally with Agent Plugin mcp.json does not resolve ${VAR} env values for MCP servers #38438, which reports that pluginmcp.json${VAR}env references aren't resolved at all today — one substitution pass could fix both.One caveat worth designing for: server processes are currently spawned per connection-set and can outlive a single session or serve a session whose cwd changes mid-thread (
ThreadSettingsOverridessupports cwd updates, and #38585 wants/cd). An env var freezes the value at spawn; if mid-session correctness matters, the MCP-spec answer is passing it per-request (e.g._meta) rather than per-process — worth stating which contract the feature promises.docs(plugins): codex README names the workspace-signal issue and the …
MaxKless commentedon Nov 19, 2026
We have the same problem with the Nx plugin (nrwl/nx-ai-agents-config). Its stdio
nx-mcpserver needs to know which Nx workspace the session is in. Codex starts the server in the plugin's cache directory, so it can't find the workspace. As a workaround, every repository that uses the plugin declares[mcp_servers.nx-mcp]in its.codex/config.toml(command = "npx",args = ["nx", "mcp"]) to replace the plugin's server. That defeats much of the point of shipping the server in a plugin.Still reproducible on codex-cli 0.166.0. I logged
process.cwd()and the environment from a probe stdio server, withcodex execrun from a workspace:plugin.json+mcp.json)~/.codex/plugins/cache/<marketplace>/<plugin>/1.0.0PLUGIN_ROOTis set.codex-plugin/plugin.jsononly ("mcpServers": "./mcp.json")So the two plugin formats behave differently. A plugin with a Codex manifest gets the workspace as its cwd. The same plugin written to the Agent Plugins format can't get the workspace at all, because the spec's
cwdpattern only allows paths under./,${PLUGIN_ROOT}or${PLUGIN_DATA}, and Codex applies that rule (#36796).Any of the three options above would fix this for us. An injected
CODEX_WORKSPACE_ROOT, or a${workspaceRoot}placeholder allowed inargs/env, would let Agent Plugins servers get back what Codex-manifest plugins already have.