Skip to content

fix(claude-code): isolate MCP server cwd#2635

Open
oldnicke wants to merge 1 commit into
vectorize-io:mainfrom
oldnicke:mcp-env-cwd
Open

fix(claude-code): isolate MCP server cwd#2635
oldnicke wants to merge 1 commit into
vectorize-io:mainfrom
oldnicke:mcp-env-cwd

Conversation

@oldnicke

@oldnicke oldnicke commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes #2634.

Claude Code starts the hindsight MCP stdio server from the active project directory. If that project contains an unreadable .env, FastMCP's settings initialization can fail before the plugin config loads.

This changes the launcher to:

  • preserve the original Claude project cwd in HINDSIGHT_MCP_PROJECT_CWD
  • switch to CLAUDE_PLUGIN_DATA before executing mcp_server.py
  • derive the default bank from the preserved project cwd so directoryBankMap and project-based dynamic bank IDs keep working

Tests

  • uv run pytest tests/test_run_mcp.py tests/test_mcp_server.py -v
  • uv run ruff check hindsight-integrations/claude-code/scripts/mcp_server.py hindsight-integrations/claude-code/tests/test_run_mcp.py hindsight-integrations/claude-code/tests/test_mcp_server.py

@koriyoshi2041

Copy link
Copy Markdown
Contributor

I checked this locally on macOS (bash 3.2.57, Python 3.11.14).

What passed:

  • uv run ruff check hindsight-integrations/claude-code/scripts/mcp_server.py hindsight-integrations/claude-code/tests/test_run_mcp.py hindsight-integrations/claude-code/tests/test_mcp_server.py
  • a direct launcher-tail check with a fake exec: it preserved the original project cwd in HINDSIGHT_MCP_PROJECT_CWD and changed the server cwd to CLAUDE_PLUGIN_DATA, so the intended runtime behavior looks right.

One local note: uv run pytest tests/test_run_mcp.py tests/test_mcp_server.py -v produced 6 passed, 1 failed here. The failing case was TestMcpServerWorkingDirectory::test_exec_runs_from_plugin_data_dir_when_project_env_is_unreadable, with the helper returning empty stdout before the split. Since the direct tail check above passes and GitHub CI is green, this looks more like a local harness/subprocess quirk than a blocker in the patch itself.

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.

Claude Code plugin MCP server crashes at startup when cwd contains an unreadable .env

2 participants