Skip to content

fix(cloud): preserve posthog-local MCP server across session refresh#2318

Draft
VojtechBartos wants to merge 1 commit into
mainfrom
vojtab/cloud-refresh-preserves-local-tools
Draft

fix(cloud): preserve posthog-local MCP server across session refresh#2318
VojtechBartos wants to merge 1 commit into
mainfrom
vojtab/cloud-refresh-preserves-local-tools

Conversation

@VojtechBartos
Copy link
Copy Markdown
Member

Summary

The cloud agent-server's pre-prompt TTL refresh calls refresh_session with only the external MCP servers from the request. ClaudeAcpAgent.refreshSession then rebuilt options.mcpServers from that set alone — dropping the in-process posthog-local MCP server installed at session creation.

Once dropped, mcp__posthog-local__git_signed_commit no longer existed and the model fell back to plain git commit — which the cloud PreToolUse guard blocks.

The fix stashes the local-tools MCP server instance on Session at creation time and re-merges it during refreshSession, so the rebuilt query keeps the same in-process server (handler still resolves the GH token lazily, per #2313).

Repro

Observed in a cloud task ("add vojta to posthog readme and create a PR"):

  • The model searched ToolSearch for mcp__posthog-local__git_signed_commit — 0 matches, total_deferred_tools: 20.
  • Calling the tool directly returned Error: No such tool available: mcp__posthog-local__git_signed_commit.
  • Without the tool, the model attempted git commit, which is blocked by the cloud PreToolUse guard / sandbox git shim.

Test plan

  • pnpm --filter agent typecheck — clean
  • pnpm --filter agent test — all 446 tests pass
  • New regression tests in claude-agent.refresh.test.ts:
    • re-attaches the in-process posthog-local MCP server
    • omits posthog-local when none was registered at session creation
  • Verify in a cloud task that git_signed_commit remains callable after a pre-prompt TTL refresh.

The cloud agent-server's pre-prompt TTL refresh calls refresh_session
with only the external MCP servers from the request. refreshSession
then rebuilt options.mcpServers from that set alone, dropping the
in-process posthog-local server installed at createSession time.

Once dropped, mcp__posthog-local__git_signed_commit no longer existed
and the model fell back to plain `git commit` — which the cloud
PreToolUse guard blocks.

Stash the local-tools MCP server on Session and re-merge it during
refresh.
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.

1 participant