Skip to content

fix(mcp): delete the codex server section when the CLI cannot remove it - #1281

Draft
posthog[bot] wants to merge 1 commit into
mainfrom
posthog-self-driving/fixmcp-remove-the-codex-mcp-server-615a2f
Draft

posthog[bot] wants to merge 1 commit into
mainfrom
posthog-self-driving/fixmcp-remove-the-codex-mcp-server-615a2f

Conversation

@posthog

@posthog posthog Bot commented Sep 20, 2026

Copy link
Copy Markdown
Contributor

Problem

  • Users who uninstall the PostHog MCP server see "Failed to remove server from Codex CLI", and the [mcp_servers.posthog] entry stays in ~/.codex/config.toml — a failed uninstall they then have to finish by hand.
  • removeServer treated every non-zero codex mcp remove exit as our failure. In the reported cases the codex CLI wrapper could not spawn its own vendored native binary, so the wizard captured a third-party crash as its own exception.
  • The install path does not depend on the CLI at all: the OAuth branch writes config.toml itself. Only the remove path insisted on the CLI, and unlike the Claude Code sibling it had no "already absent" guard.

Changes

  • Remove now mirrors add: when the CLI is missing or exits non-zero, delete the [mcp_servers.<name>] section from config.toml through the same atomic temp-file write writeServerSection uses.
  • An absent section reports alreadyInstalled (surfaced as "unchanged"), so a server removed out from under us is not a failure.
  • Only a failed config.toml edit captures an exception. A CLI crash no longer does.
  • Section lookup is factored into one findSection helper shared by the write and the delete, so both agree on where a server's body ends.
Case Before After
CLI removes the server success success
CLI missing or crashed failure + captured exception section deleted, success
Server already absent failure + captured exception unchanged, no exception
config.toml write fails n/a failure + captured exception

Test plan

  • src/steps/add-mcp-server-to-clients/clients/__tests__/codex.test.ts covers the four cases above; the whole add-mcp-server-to-clients suite passes (103 tests).
  • pnpm lint clean on both edited files. tsc --noEmit output is unchanged against main.

LLM context

Written by Claude Opus 5 (claude-opus-5) in PostHog Desktop.

  • Considered dropping the CLI call and always editing config.toml. Kept the CLI first: it owns the bearer-token env wiring an API-key install writes, so letting it do the removal keeps that bookkeeping in one place. The direct edit deletes the whole section, so it covers that key too when the CLI is unavailable.
  • Left the Claude Code client alone. It already guards the already-absent case, and it has no config file the wizard writes directly, so the same fallback has nothing to mirror there.

Created with PostHog Desktop from this inbox report.

`codex mcp remove` now falls back to editing ~/.codex/config.toml directly, the
mirror of the write the OAuth install path already does. A broken codex CLI left
the [mcp_servers.posthog] entry in place and reported its own crash as a wizard
exception. An absent server is reported as unchanged, and only a failed
config.toml edit captures an exception.

Generated-By: PostHog Desktop
Task-Id: 6071a238-3d65-45c3-93b4-42dba485bc1e
@github-actions

Copy link
Copy Markdown

🧙 Wizard CI

Run the Wizard CI and test your changes against wizard-workbench example apps by replying with a GitHub comment using one of the following commands:

Test all apps:

  • /wizard-ci all

Test all apps in a directory:

  • /wizard-ci ai-observability
  • /wizard-ci basic-integration
  • /wizard-ci mcp-analytics
  • /wizard-ci replay-vision
  • /wizard-ci revenue
  • /wizard-ci self-driving
  • /wizard-ci warehouse
  • /wizard-ci warehouse-seeded

Test an individual app:

  • /wizard-ci ai-observability/anthropic
  • /wizard-ci ai-observability/google-adk
  • /wizard-ci ai-observability/groq
Show more apps
  • /wizard-ci ai-observability/manual-capture
  • /wizard-ci ai-observability/openai
  • /wizard-ci ai-observability/openai-agents
  • /wizard-ci ai-observability/opentelemetry
  • /wizard-ci ai-observability/vercel-ai
  • /wizard-ci basic-integration/android
  • /wizard-ci basic-integration/angular
  • /wizard-ci basic-integration/astro
  • /wizard-ci basic-integration/django
  • /wizard-ci basic-integration/fastapi
  • /wizard-ci basic-integration/flask
  • /wizard-ci basic-integration/flutter
  • /wizard-ci basic-integration/javascript-node
  • /wizard-ci basic-integration/javascript-web
  • /wizard-ci basic-integration/laravel
  • /wizard-ci basic-integration/next-js
  • /wizard-ci basic-integration/nuxt
  • /wizard-ci basic-integration/python
  • /wizard-ci basic-integration/rails
  • /wizard-ci basic-integration/react-native
  • /wizard-ci basic-integration/react-router
  • /wizard-ci basic-integration/sveltekit
  • /wizard-ci basic-integration/swift
  • /wizard-ci basic-integration/tanstack-router
  • /wizard-ci basic-integration/tanstack-start
  • /wizard-ci basic-integration/vue
  • /wizard-ci mcp-analytics/custom-dispatcher
  • /wizard-ci mcp-analytics/typescript-sdk
  • /wizard-ci replay-vision/javascript-node
  • /wizard-ci replay-vision/next-js
  • /wizard-ci replay-vision/react-vite
  • /wizard-ci revenue/stripe
  • /wizard-ci self-driving/astro
  • /wizard-ci self-driving/fastapi
  • /wizard-ci self-driving/nuxt
  • /wizard-ci self-driving/react-router
  • /wizard-ci self-driving/sveltekit
  • /wizard-ci warehouse/monorepo-env
  • /wizard-ci warehouse/multi-source-next
  • /wizard-ci warehouse/stripe-node
  • /wizard-ci warehouse/zero-source
  • /wizard-ci warehouse-seeded/next-stripe
  • /wizard-ci warehouse-seeded/next-stripe-declined

Test against a Context Mill branch:

  • /wizard-ci all context-mill:my-branch

Add context-mill:<branch> to any command above to pin the Context Mill branch. It defaults to main.

Results will be posted here when complete.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants