Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,21 @@ exports[`keyboard commit vs control action commit > mcp: enter on install result
}
`;

exports[`keyboard commit vs control action commit > mcp: esc on the install question vs set_mcp_outcome skipped 1`] = `
{
"action": {
"mcpComplete": true,
"mcpOutcome": "skipped",
"screen": "exit",
},
"keyboard": {
"mcpComplete": true,
"mcpOutcome": "skipped",
"screen": "exit",
},
}
`;

exports[`keyboard commit vs control action commit > outro: any key vs dismiss_outro 1`] = `
{
"action": {
Expand Down
20 changes: 18 additions & 2 deletions e2e-harness/__tests__/keyboard-equivalence.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -193,17 +193,33 @@ const PAIRS: Pair[] = [
name: 'mcp: enter on install results vs set_mcp_outcome installed',
program: Program.PostHogIntegration,
screen: ScreenId.Mcp,
ready: (_, frame) => frame.includes('Press enter'),
ready: (_, frame) => frame.includes('Add the PostHog MCP to your coding'),
arrange: (s) => {
confirmed(s);
authed(s);
ran(s);
s.setOutroDismissed();
},
keys: [ENTER],
// Agree to the install, then leave the results.
keys: [ENTER, ENTER],
action: 'set_mcp_outcome',
params: { outcome: 'installed', clients: ['Cursor', 'Claude Code'] },
},
{
name: 'mcp: esc on the install question vs set_mcp_outcome skipped',
program: Program.PostHogIntegration,
screen: ScreenId.Mcp,
ready: (_, frame) => frame.includes('Add the PostHog MCP to your coding'),
arrange: (s) => {
confirmed(s);
authed(s);
ran(s);
s.setOutroDismissed();
},
keys: [ESC],
action: 'set_mcp_outcome',
params: { outcome: 'skipped' },
},
{
name: 'slack-connect: skip vs dismiss_slack',
// Only `wizard slack` shows this screen now that no program flow does.
Expand Down
9 changes: 5 additions & 4 deletions src/tui/__tests__/__snapshots__/frames/mcp-120x40.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@

Cost (running): $0.00 · no agent turns yet Ctrl+T to hide

Adding the PostHog MCP to your coding agents
Add the PostHog MCP to your coding agents?

Found 2 coding agents. Setting each one up on this computer.
Found 2 coding agents: Claude Code, Cursor.
Adding it writes a posthog server to each agent's own config, outside this project.

⠋ Claude Code plugin + MCP Installing…
· Cursor MCP Waiting
▸ Add the PostHog MCP
Skip
10 changes: 6 additions & 4 deletions src/tui/__tests__/__snapshots__/frames/mcp-80x28.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@

Cost (running): $0.00 · no agent turns yet Ctrl+T to hide

Adding the PostHog MCP to your coding agents
Add the PostHog MCP to your coding agents?

Found 2 coding agents. Setting each one up on this computer.
Found 2 coding agents: Claude Code, Cursor.
Adding it writes a posthog server to each agent's own config, outside this
project.

⠋ Claude Code plugin + MCP Installing…
· Cursor MCP Waiting
▸ Add the PostHog MCP
Skip
133 changes: 133 additions & 0 deletions src/tui/__tests__/mcp-screen-outcome.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -485,3 +485,136 @@ it('reports a failed detection once, as its error shows, before Enter', async ()
]);
expect(store.mcpComplete).toBe(false);
});

it('asks before installing when confirmInstall is set, and writes nothing until the user agrees', async () => {
const store = new WizardStore(Tool.McpAdd);
store.session = buildSession({ installDir: '/app' });
const install = vi.fn<McpInstaller['install']>((names) =>
Promise.resolve(
names.map((name) => ({ name, status: McpClientStatus.Changed })),
),
);
const { stdin, lastFrame } = render(
<McpScreen
store={store}
installer={{ ...installer, install }}
confirmInstall
/>,
);
await vi.waitFor(() =>
expect(lastFrame()).toContain('Add the PostHog MCP to your coding agents?'),
);
expect(lastFrame()).toContain('Found 1 coding agent: Cursor.');
await tick();
expect(install).not.toHaveBeenCalled();
expect(mcpCompleteCalls()).toEqual([]);

// "Add the PostHog MCP" is the first option.
stdin.write(ENTER);
await vi.waitFor(() => expect(lastFrame()).toContain('Press enter'));
expect(install).toHaveBeenCalledWith(
['Cursor'],
expect.anything(),
undefined,
);
expect(lastFrame()).toContain('The PostHog MCP is ready in 1 coding agent');
});

it('installs nothing when the user skips the confirmation', async () => {
const store = new WizardStore(Tool.McpAdd);
store.session = buildSession({ installDir: '/app' });
const install = vi.fn<McpInstaller['install']>(() => Promise.resolve([]));
const { stdin, lastFrame } = render(
<McpScreen
store={store}
installer={{ ...installer, install }}
confirmInstall
/>,
);
await vi.waitFor(() => expect(lastFrame()).toContain('Skip'));
await tick();
for (const key of [DOWN, ENTER]) {
stdin.write(key);
await tick();
}
await vi.waitFor(() => expect(store.mcpComplete).toBe(true));
expect(store.mcpOutcome).toBe(McpOutcome.Skipped);
expect(install).not.toHaveBeenCalled();
expect(mcpCompleteCalls()).toEqual([
[
'mcp complete',
expect.objectContaining({
mcp_outcome: McpOutcome.Skipped,
mcp_installed_clients: [],
}),
],
]);
});

it('installs nothing on esc from the confirmation', async () => {
const store = new WizardStore(Tool.McpAdd);
store.session = buildSession({ installDir: '/app' });
const install = vi.fn<McpInstaller['install']>(() => Promise.resolve([]));
const { stdin, lastFrame } = render(
<McpScreen
store={store}
installer={{ ...installer, install }}
confirmInstall
/>,
);
await vi.waitFor(() =>
expect(lastFrame()).toContain('Add the PostHog MCP to your coding agents?'),
);
await tick();
stdin.write(ESC);
await vi.waitFor(() => expect(store.mcpComplete).toBe(true));
expect(store.mcpOutcome).toBe(McpOutcome.Skipped);
expect(install).not.toHaveBeenCalled();
});

it('still offers the AI assistants after the coding-agent install is skipped', async () => {
const store = new WizardStore(Tool.McpAdd);
store.session = buildSession({ installDir: '/app' });
const detectClients = () =>
Promise.resolve([
{
name: 'Cursor',
kind: 'local' as const,
supportsPlugin: false,
pluginBundlesMcp: false,
},
{
name: 'Example Web App',
kind: 'account' as const,
supportsPlugin: false,
pluginBundlesMcp: false,
finish: {
url: 'https://example.com/connectors/posthog',
instruction: 'Sign in and click "Connect" to finish.',
},
},
]);
const install = vi.fn<McpInstaller['install']>(() => Promise.resolve([]));
const { stdin, lastFrame } = render(
<McpScreen
store={store}
installer={{ ...installer, detectClients, install }}
confirmInstall
/>,
);
await vi.waitFor(() => expect(lastFrame()).toContain('Skip'));
await tick();
for (const key of [DOWN, ENTER]) {
stdin.write(key);
await tick();
}
await vi.waitFor(() => expect(lastFrame()).toContain('Step 2 of 2'));
expect(install).not.toHaveBeenCalled();

await tick();
stdin.write(ESC);
await vi.waitFor(() => expect(store.mcpComplete).toBe(true));
expect(store.mcpOutcome).toBe(McpOutcome.Skipped);
expect(store.mcpInstalledClients).toEqual([]);
expect(install).not.toHaveBeenCalled();
});
6 changes: 5 additions & 1 deletion src/tui/screen-registry.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,11 @@ export function createScreens(
[ScreenId.ProjectPicker]: <ProjectPickerScreen store={store} />,
[ScreenId.Run]: <RunScreen store={store} />,
[ScreenId.Mcp]: (
<McpScreen store={store} installer={services.mcpInstaller} />
<McpScreen
store={store}
installer={services.mcpInstaller}
confirmInstall
/>
),
[ScreenId.SlackConnect]: <SlackConnectScreen store={store} />,
[ScreenId.Outro]: <OutroScreen store={store} />,
Expand Down
67 changes: 62 additions & 5 deletions src/tui/screens/McpScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
* importing business logic directly. Testable, no dynamic imports.
*
* Supports two modes via the `mode` prop:
* - 'install': detect clients → install in every local client → results
* → open the connector page of each account client the user picks
* - 'install': detect clients → (with `confirmInstall`, ask first) → install
* in every local client → results → open the connector page of each
* account client the user picks
* - 'remove': detect installed local clients → pick which (esc cancels) → remove
*
* A successful install ends on one screen: a row per client, any login
Expand Down Expand Up @@ -50,6 +51,12 @@ interface McpScreenProps {
samplePrompts?: string[];
/** The last menu item, which leaves the screen. `mcp add` says Exit. */
exitLabel?: string;
/**
* Ask before writing to any coding agent's user-wide config. The setup flow
* sets it: there the install is a side step the user didn't ask for. `mcp
* add` leaves it off, since running that command is the request.
*/
confirmInstall?: boolean;
}

enum Phase {
Expand Down Expand Up @@ -309,6 +316,7 @@ export const McpScreen = ({
mode = 'install',
samplePrompts = [],
exitLabel = 'Continue',
confirmInstall = false,
}: McpScreenProps) => {
useSyncExternalStore(
(cb) => store.subscribe(cb),
Expand Down Expand Up @@ -385,6 +393,9 @@ export const McpScreen = ({
} else if (local.length === 0) {
setClients(detected);
setPhase(Phase.Assistants);
} else if (confirmInstall) {
setClients(detected);
setPhase(Phase.Ask);
} else {
setClients(detected);
void installAll(local);
Expand Down Expand Up @@ -607,7 +618,23 @@ export const McpScreen = ({
: [],
);

// The remove picker has no escape binding of its own; esc removes nothing.
/** The user declined the install: write nothing, and go on to the assistants. */
const declineInstall = () => {
if (accountClients.length === 0) {
markDone(store, McpOutcome.Skipped);
return;
}
stepOne.current = {
outcome: McpOutcome.Skipped,
ready: [],
features: reportFeatures(store.mcpFeatures ?? [...ALL_FEATURE_VALUES]),
logins: [],
};
setPhase(Phase.Assistants);
};

// The pickers have no escape binding of their own; esc removes or installs
// nothing.
useKeyBindings(
'mcp-remove-cancel',
phase === Phase.Ask
Expand All @@ -616,7 +643,9 @@ export const McpScreen = ({
match: KeyMatch.Escape,
label: 'esc',
action: 'cancel',
handler: () => markDone(store, McpOutcome.Skipped),
handler: isRemove
? () => markDone(store, McpOutcome.Skipped)
: declineInstall,
},
]
: [],
Expand Down Expand Up @@ -660,6 +689,8 @@ export const McpScreen = ({

const heading = isRemove
? 'Remove the PostHog MCP'
: phase === Phase.Ask
? 'Add the PostHog MCP to your coding agents?'
: phase === Phase.Assistants
? 'Connect PostHog to your AI assistants'
: phase !== Phase.Done
Expand Down Expand Up @@ -742,7 +773,33 @@ export const McpScreen = ({
</Text>
))}

{phase === Phase.Ask && (
{phase === Phase.Ask && !isRemove && (
<Box flexDirection="column">
<Box marginBottom={1} flexDirection="column">
<Text>
Found {plural(localClients.length, 'coding agent')}:{' '}
{localClients.map((c) => c.name).join(', ')}.
</Text>
<Text dimColor>
Adding it writes a posthog server to each agent&apos;s own
config, outside this project.
</Text>
</Box>
<PickerMenu
options={[
{ label: 'Add the PostHog MCP', value: 'install' },
{ label: 'Skip', value: 'skip' },
]}
onSelect={(value) => {
const picked = Array.isArray(value) ? value[0] : value;
if (picked === 'install') void installAll(localClients);
else declineInstall();
}}
/>
</Box>
)}

{phase === Phase.Ask && isRemove && (
<PickerMenu
message="Select the coding agents to remove the PostHog MCP from"
mode="multi"
Expand Down