Skip to content

feat(agent): add internal MCP server for self-modification#1969

Draft
sakce wants to merge 3 commits intomainfrom
feat/posthog-code-internal-mcp
Draft

feat(agent): add internal MCP server for self-modification#1969
sakce wants to merge 3 commits intomainfrom
feat/posthog-code-internal-mcp

Conversation

@sakce
Copy link
Copy Markdown
Contributor

@sakce sakce commented May 1, 2026

Problem

Code can't do anything to itself. I find that annoying. We need to let it modify itself.

Changes

Local HTTP MCP server, started with the main process and torn down on quit, that exposes four self-modification tools to the running agent: read/write the user's custom instructions and list/add MCP server installations on the active project.

Mirrors McpProxyService: binds 127.0.0.1:0, generates a per-boot random bearer token, registers @preDestroy cleanup. AgentAuthAdapter appends one extra entry to the agent's MCP server list. A tRPC subscription keeps the renderer settings store in sync when the agent rewrites custom instructions in the encrypted renderer-storage bucket.

Generated-By: PostHog Code
Task-Id: 934a7fa1-fbb6-4f1d-89d3-f6abc69b7e23

How did you test this?

ran it locally to install the Linear MCP server (OAuth flow) and the NYC subway for the API key route.

Publish to changelog?

sakce added 3 commits May 1, 2026 08:57
Local HTTP MCP server, started with the main process and torn down on
quit, that exposes four self-modification tools to the running agent:
read/write the user's custom instructions and list/add MCP server
installations on the active project.

Mirrors McpProxyService: binds 127.0.0.1:0, generates a per-boot random
bearer token, registers @preDestroy cleanup. AgentAuthAdapter appends
one extra entry to the agent's MCP server list. A tRPC subscription
keeps the renderer settings store in sync when the agent rewrites
custom instructions in the encrypted renderer-storage bucket.

Generated-By: PostHog Code
Task-Id: 934a7fa1-fbb6-4f1d-89d3-f6abc69b7e23
Installing an MCP server via add_mcp_server now triggers a session
refresh so the new tools become available without restarting the agent.

- Emit McpServerInstalled after successful install (api_key + OAuth)
- For OAuth, poll the backend until pending_oauth flips, then emit
- AgentService listens and calls _posthog/refresh_session per session
- Defer the refresh when a turn is in flight; fire it after turn ends
- Drop the local api_key requirement check (backend enforces it; this
  unblocks no-auth servers that need a dummy key value)
The setup.ts default `/mock/userData` works locally as root but EACCES
in GitHub runners. Mocking the store at the test level keeps the fix
scoped — the polling tests never need real store state.

Generated-By: PostHog Code
Task-Id: 934a7fa1-fbb6-4f1d-89d3-f6abc69b7e23
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