Skip to content

[SOLUTION] Fix for Happy Codex MCP error -32000 and external MCP servers not working in Codex #167

Closed

Description

@huntsyea

Multiple people have reported MCP error -32000: Connection closed and external MCP servers (for me I just use Context7) not being available in Happy Codex after fixing the mcp to mcp-server issue. I believe this affects issues #158, #155, and #164.

I did the following and have happy codex working with MCPs. Not sure if it right but it's working.

Step 1: Install MCP servers globally

Avoid npx instability (found this through logs) by installing MCP servers as global binaries:

pnpm add -g @upstash/context7-mcp
# or: npm install -g @upstash/context7-mcp

Step 2: Configure binary paths

Update your ~/.codex/config.toml to use installed binaries:

[mcp_servers.context7]
command = "context7-mcp"
args = ["--api-key", "your-api-key-here"]

Step 3: Change Happy Codex MCP config passing

The core issue is in how Happy Codex constructs the MCP server configuration when spawning the Codex MCP server.

Location: node_modules/happy-coder/dist/runCodex-*.cjs around line 1100

Current code:

const mcpServers = {
  happy: { command: bridgeCommand, args: ["--url", happyServer.url] }
};
// Only passes Happy's bridge, ignores ~/.codex/config.toml

Changed code (reads and merges Codex config):

// Read existing Codex MCP servers from ~/.codex/config.toml
let existingMcpServers = {};
try {
  const codexConfigPath = join(os.homedir(), '.codex', 'config.toml');
  if (fs.existsSync(codexConfigPath)) {
    // Parse TOML and extract [mcp_servers.*] sections
    // (full parsing implementation needed)
  }
} catch (error) {
  logger.debug(`Error reading Codex config: ${error.message}`);
}

// Merge Happy's bridge WITH existing external MCP servers
const mcpServers = {
  happy: { command: bridgeCommand, args: ["--url", happyServer.url] },
  ...existingMcpServers  // Include Context7, etc.
};

Results

• No more "MCP error -32000: Connection closed"
• External MCP servers (Context7, etc.) available in Happy
• MCP server connection with no npx failures
• Happy respects existing Codex MCP server configuration

Environment Tested

• OS: macOS 26
• Package Manager: pnpm v10.18.0
• Happy Coder: v0.11.1

I am unsure if merging the mcp configs + bridge is right way to go about it but hopefully this helps with fixes.

Activity

  1. songtianlun commented on Oct 10, 2025

    @songtianlun

    I tried making the same modifications, but I got the same error.

    Error: MCP error -32000: Connection closed
    

    It doesn't seem to work for me. My system is Ubuntu 22.04.

  2. CaiJingLong commented on Oct 11, 2025

    @CaiJingLong

    The issue with macOS is the same, and the sessions created cannot be closed; they will always remain in the list.

  3. redpintings commented on Oct 11, 2025

    @redpintings

    codex 0.45
    macOS
    iPhone

    Error: MCP error -32000: Connection closed

  4. huntsyea commented on Oct 12, 2025

    @huntsyea
    Author

    codex 0.45
    macOS
    iPhone

    Error: MCP error -32000: Connection closed

    After above?

  5. huntsyea commented on Oct 12, 2025

    @huntsyea
    Author

    The issue with macOS is the same, and the sessions created cannot be closed; they will always remain in the list.

    After above? Resetting and reinstalling prior to doing this cleared mine it's all working properly

  6. kts-kris commented on Oct 14, 2025

    @kts-kris

    I tried this solution, but it didn’t work for me at first. Later, I reinstalled Codex (using Homebrew), reinstalled Happy, and cleared the config.toml file — after that, everything started working fine, and the MCP startup errors were gone. Then I reconfigured MCP, and it still worked perfectly. I’d recommend anyone having the same issue to give this a try.

  7. songtianlun commented on Oct 15, 2025

    @songtianlun

    This issue is similar to this one:
    #158

    It appears to be resolved now; installing the latest version should fix it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions