openai/codex · error · anyhow::Error

MCP server `{server}` is running in environment `{}`, expect

Error message

MCP server `{server}` is running in environment `{}`, expected `{environment_id}`

What it means

Error "MCP server `{server}` is running in environment `{}`, expected `{environment_id}`" thrown in openai/codex.

Source

Thrown at codex-rs/codex-mcp/src/connection_manager.rs:885

    #[allow(clippy::too_many_arguments)]
    pub async fn call_tool(
        &self,
        server: &str,
        tool: &str,
        environment_id: Option<&str>,
        arguments: Option<serde_json::Value>,
        meta: Option<serde_json::Value>,
        requested_timeout: Option<Duration>,
        wait_for_server: bool,
    ) -> Result<CallToolResult> {
        let view = self
            .servers
            .get(server)
            .ok_or_else(|| anyhow!("unknown MCP server '{server}'"))?;
        if let Some(environment_id) = environment_id
            && view.metadata.environment_id != environment_id
        {
            bail!(
                "MCP server `{server}` is running in environment `{}`, expected `{environment_id}`",
                view.metadata.environment_id
            );
        }
        if !view.tool_filter.allows(tool) {
            return Err(anyhow!(
                "tool '{tool}' is disabled for MCP server '{server}'"
            ));
        }
        let client = if wait_for_server {
            view.connection
                .client()
                .await
                .context("failed to get client")?
        } else {
            let client = view
                .connection
                .client

View on GitHub (pinned to 339751715c)

Solutions

  1. Reconnect the MCP server under the expected environment `{environment_id}`, or re-register the environment so the running server's environment matches.

When it happens

Trigger: Thrown at codex-rs/codex-mcp/src/connection_manager.rs:885 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of openai/codex@339751715c (2026-08-25). Data as JSON: /api/errors/144b4f88c609000f. Report an issue: GitHub.