Skip to content

fix: Claude Code support for MCP server installation#169

Merged
ordehi merged 4 commits intomainfrom
fix/claude-code-mcp-support
Nov 8, 2025
Merged

fix: Claude Code support for MCP server installation#169
ordehi merged 4 commits intomainfrom
fix/claude-code-mcp-support

Conversation

@ordehi
Copy link
Copy Markdown
Contributor

@ordehi ordehi commented Nov 7, 2025

Summary

Fixes multiple issues preventing Claude Code from appearing in the MCP client selection list and successfully installing the PostHog MCP server.

Issues Fixed

1. Claude Code not detected

Problem: The claude binary wasn't found because it's typically installed at ~/.claude/local/claude and added as a shell alias, but execSync doesn't load shell configurations.

Solution: Check known Claude Code installation paths:

  • ~/.claude/local/claude (standard installation)
  • /usr/local/bin/claude
  • /opt/homebrew/bin/claude
  • Falls back to PATH check

2. Wrong client shown in reinstall warning

Problem: When selecting only Claude Code, wizard warned about PostHog MCP server already installed in Claude Desktop.

Solution: Only check isServerInstalled() for user-selected clients, not all supported clients.

3. Environment variable expansion broken in Claude Code

Problem: Claude Code has multiple bugs with environment variable expansion in MCP server args. The behavior is inconsistent across different config locations and versions:

GitHub Issues:

Observed behavior:

  • Some users report ${VAR} works in ~/.claude.json (user config) but not .mcp.json (project config)
  • In our testing (Claude Code v2.0.35 on macOS), ${VAR} expansion fails in ~/.claude.json as well, sending literal "${POSTHOG_AUTH_HEADER}" instead of the token value
  • This causes "Missing environment variables: POSTHOG_AUTH_HEADER" connection errors

Solution: Claude Code uses a custom config builder (buildClaudeCodeConfig()) that:

  • Adds https:// protocol (mcp-remote requires valid URLs, was missing causing "Invalid URL" errors)
  • Embeds token directly in Authorization header: Authorization:Bearer phx_... instead of Authorization:${VAR}
  • Keeps env block for backward compatibility if/when bugs are fixed in future Claude Code versions

This workaround works reliably across all Claude Code configurations (user and project scope).

Other clients (Claude Desktop, Cursor, VS Code, Zed) continue using the standard config with ${VAR} expansion as they don't have these bugs.

4. Debug flag support

Enhancement: Added --debug flag support to MCP commands with logging showing:

  • Which clients are detected (✓ supported / ✗ not supported)
  • Which installation paths were checked
  • Final list of supported clients

Testing

  • Manually tested end-to-end on macOS with Claude Code v2.0.35: wizard mcp add --debug
  • Claude Code now appears in client selection
  • No false warnings about other clients
  • PostHog MCP server connects successfully in Claude Code
  • Debug logging helps troubleshoot installation issues

Notes

  • No unit tests added as Claude Code uses CLI-based integration (claude mcp add-json) rather than file-based config like other clients. Properly testing would require extensive mocking of execSync calls. Manual testing confirms all fixes work correctly.
  • Changes are isolated to Claude Code - other MCP clients unaffected

Add support for --debug flag in MCP add/remove commands to enable
verbose logging during MCP server configuration.

Changes:
- Add debug?: boolean to runMCPInstall() parameters in bin.ts
- Call enableDebugLogs() when debug flag is set in src/mcp.ts

This enables users to troubleshoot MCP server installation issues
by running: wizard mcp add --debug
Add debug logging to MCP client detection and fix a bug where the
wizard warned about MCP servers installed in unselected clients.

Changes:
- Import and use debug() in getSupportedClients()
- Log each client's detection status (✓ supported / ✗ not supported)
- Log final count and list of supported clients
- Fix: only check isServerInstalled() for user-selected clients
  instead of all supported clients

Bug fixed: When user selects "Claude Code", wizard no longer warns
about PostHog MCP server already being installed in "Claude Desktop".

This improves UX by only showing relevant reinstall prompts and
makes troubleshooting easier with visibility into detection logic.
Claude Code detection was failing when the 'claude' binary wasn't in
the shell's PATH. The wizard uses execSync with /bin/sh which doesn't
load shell startup files (.zshrc, .bashrc) that configure PATH.

Root cause: Users install Claude Code which creates the binary at
~/.claude/local/claude, then add a shell alias. When the wizard runs,
it can't find 'claude' because aliases don't work in execSync.

Solution: Check standard Claude Code installation locations:
- ~/.claude/local/claude (standard installation path)
- /usr/local/bin/claude (system install)
- /opt/homebrew/bin/claude (Homebrew on Apple Silicon)
- Falls back to PATH check using 'command -v'

The found binary path is cached and reused for all MCP operations
(mcp list, mcp add, mcp remove) to ensure consistent behavior.

Debug logging shows which paths were checked when Claude Code isn't
found, helping users troubleshoot installation issues.

Fixes: Users reported Claude Code not appearing in the MCP client
selection list despite having it installed and working.
@ordehi ordehi requested a review from joshsny November 7, 2025 21:11
@ordehi ordehi enabled auto-merge (squash) November 7, 2025 21:13
Copy link
Copy Markdown
Collaborator

@joshsny joshsny left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great - thanks for doing this!

@ordehi ordehi merged commit 98589b9 into main Nov 8, 2025
10 checks passed
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.

2 participants