Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

fix(desktop): improve pi MCP tool details (#102430)

Jonathan Mielooda5f8bb0aed5
diff --git a/products/desktop/apps/mobile/src/features/chat/utils/posthogExecDisplay.test.ts b/products/desktop/apps/mobile/src/features/chat/utils/posthogExecDisplay.test.ts
index ca08b80c334d..168f98639432 100644
--- a/products/desktop/apps/mobile/src/features/chat/utils/posthogExecDisplay.test.ts
+++ b/products/desktop/apps/mobile/src/features/chat/utils/posthogExecDisplay.test.ts
@@ -26,7 +26,7 @@ describe("isPostHogExecTool", () => {
describe("getPostHogExecDisplay", () => {
it("collapses `call <tool>` to the bare sub-tool label", () => {
expect(getPostHogExecDisplay({ command: "call experiment-list" })).toEqual({
- label: "experiment-list",
+ label: "List experiment",
input: undefined,
});
});
@@ -37,7 +37,7 @@ describe("getPostHogExecDisplay", () => {
command: 'call execute-sql {"query":"SELECT 1"}',
}),
).toEqual({
- label: "execute-sql",
+ label: "Execute sql",
input: '{"query":"SELECT 1"}',
});
});
@@ -49,6 +49,13 @@ describe("getPostHogExecDisplay", () => {
});
});
+ it("does not infer an action from an unknown `all` suffix", () => {
+ expect(getPostHogExecDisplay({ command: "call foo-bar-all" })).toEqual({
+ label: "Foo bar all",
+ input: undefined,
+ });
+ });
+
it("formats `schema <tool> <field_path>` as a dotted locator", () => {
expect(
getPostHogExecDisplay({
@@ -81,7 +88,7 @@ describe("getPostHogExecDisplay", () => {
input: { query: "SELECT 1" },
}),
).toEqual({
- label: "execute-sql",
+ label: "Execute sql",
input: '{"query":"SELECT 1"}',
});
});
diff --git a/products/desktop/packages/agent/src/adapters/claude/claude-agent.slash-command.test.ts b/products/desktop/packages/agent/src/adapters/claude/claude-agent.slash-command.test.ts
index a8fff01c3a74..658fc5b06874 100644
--- a/products/desktop/packages/agent/src/adapters/claude/claude-agent.slash-command.test.ts
+++ b/products/desktop/packages/agent/src/adapters/claude/claude-agent.slash-command.test.ts
@@ -11,6 +11,7 @@ vi.mock("@anthropic-ai/claude-agent-sdk", () => ({
vi.mock("./mcp/tool-metadata", () => ({
fetchMcpToolMetadata: vi.fn().mockResolvedValue(undefined),
getConnectedMcpServerNames: vi.fn().mockReturnValue([]),
+ getCachedMcpTools: vi.fn().mockReturnValue([]),
setMcpToolApprovalStates: vi.fn(),
isMcpToolReadOnly: vi.fn().mockReturnValue(false),
getMcpToolMetadata: vi.fn().mockReturnValue(undefined),
diff --git a/products/desktop/packages/agent/src/pi/conversation/translatePiMessage.ts b/products/desktop/packages/agent/src/pi/conversation/translatePiMessage.ts
index b9ab14b04fa9..7d1d1df9bfc7 100644
--- a/products/desktop/packages/agent/src/pi/conversation/translatePiMessage.ts
+++ b/products/desktop/packages/agent/src/pi/conversation/translatePiMessage.ts
@@ -18,6 +18,7 @@ import {
isPiToolName,
mcpToolKey,
type PiToolName,
+ parsePiMcpCallDetails,
posthogToolMeta,
} from "@posthog/shared";
import { z } from "zod";
@@ -66,6 +67,7 @@ const mcpToolDetailsSchema: z.ZodType<McpCallDetails> = z.object({
mcp: z.object({
server: z.string().min(1),
tool: z.string().min(1),
+ title: z.string().min(1).optional(),
result: mcpResultMetaSchema.optional(),
}),
}),
@@ -271,10 +273,15 @@ export function createPiMessageTranslator(): PiMessageTranslator {
toolCall.details = result.details;
}
+ const piMcpCallDetails = parsePiMcpCallDetails(toolName, args);
const mcpDetails = mcpToolDetailsSchema.safeParse(result.details);
if (mcpDetails.success) {
const mcp = mcpDetails.data.posthog.mcp;
- toolCall._meta = posthogToolMeta({ toolName: mcpToolKey(mcp), mcp });
+ toolCall._meta = posthogToolMeta({
+ toolName: mcpToolKey(mcp),
+ mcp,
+ ...(piMcpCallDetails ? { mcpProxy: piMcpCallDetails } : {}),
+ });
const resultMeta = mcp.result;
if (
@@ -287,6 +294,11 @@ export function createPiMessageTranslator(): PiMessageTranslator {
...resultMeta,
});
}
+ } else if (piMcpCallDetails) {
+ toolCall._meta = posthogToolMeta({
+ toolName,
+ mcpProxy: piMcpCallDetails,
+ });
}
const translator = isPiToolName(toolName)
diff --git a/products/desktop/packages/core/src/sessions/posthogExecDisplay.ts b/products/desktop/packages/core/src/sessions/posthogExecDisplay.ts
index d87f19e42240..a70b754604b8 100644
--- a/products/desktop/packages/core/src/sessions/posthogExecDisplay.ts
+++ b/products/desktop/packages/core/src/sessions/posthogExecDisplay.ts
@@ -1,4 +1,4 @@
-import { parseMcpToolName } from "@posthog/shared";
+import { formatMcpToolLabel, parseMcpToolName } from "@posthog/shared";
const POSTHOG_SERVER_RE = /^(?:plugin_)?posthog(?:_[^_]+)*$/;
const POSTHOG_VERB_RE =
@@ -53,7 +53,7 @@ export function getPostHogExecDisplay(
const call = rest.match(POSTHOG_CALL_BODY_RE);
if (!call) return null;
return {
- label: call[1],
+ label: formatMcpToolLabel(call[1]),
input: explicitInput ?? ((call[2] ?? "").trim() || undefined),
};
}
diff --git a/products/desktop/packages/harness/src/extensions/mcp/proxy-tool.test.ts b/products/desktop/packages/harness/src/extensions/mcp/proxy-tool.test.ts
index c97db8073752..af06a46bea90 100644
--- a/products/desktop/packages/harness/src/extensions/mcp/proxy-tool.test.ts
+++ b/products/desktop/packages/harness/src/extensions/mcp/proxy-tool.test.ts
@@ -13,6 +13,7 @@ import { McpToolCache } from "./tool-cache";
const ECHO_TOOL = {
name: "echo",
+ title: "Echo text tool",
description: "Echo text back",
inputSchema: {
type: "object",
@@ -400,11 +401,19 @@ describe("mcp proxy tool", () => {
});
await manager.startServer("demo", "/workspace");
- const result = await text(tool, {
- tool: "mcp_demo_echo",
- args: '{"text":"hi"}',
+ const result = await tool.execute(
+ "id-1",
+ { tool: "mcp_demo_echo", args: '{"text":"hi"}' } as never,
+ undefined,
+ undefined as never,
+ undefined as never,
+ );
+ expect((result.content[0] as { text: string }).text).toBe("echo: hi");
+ expect(result.details).toMatchObject({
+ kind: "call",
+ title: "Echo text tool",
+ posthog: { mcp: { title: "Echo text tool" } },
});
- expect(result).toBe("echo: hi");
await mock.close();
});
diff --git a/products/desktop/packages/harness/src/extensions/mcp/proxy-tool.ts b/products/desktop/packages/harness/src/extensions/mcp/proxy-tool.ts
index d449eb529e80..ae959d8e2378 100644
--- a/products/desktop/packages/harness/src/extensions/mcp/proxy-tool.ts
+++ b/products/desktop/packages/harness/src/extensions/mcp/proxy-tool.ts
@@ -43,6 +43,7 @@ export interface Hit {
/** Exact pi tool name to call, if known (live or cached). Absent = server-only hit. */
piName?: string;
serverName: string;
+ title?: string;
description: string;
connected: boolean;
score: number;
@@ -63,6 +64,7 @@ export type McpProxyDetails =
kind: "call";
server: string;
tool: string;
+ title?: string;
piName: string;
posthog?: McpCallDetails["posthog"];
};
@@ -97,12 +99,13 @@ async function search(
for (const tool of live) {
const s = score(
queryTerms,
- `${tool.piName} ${tool.mcpName} ${tool.description} ${tool.serverName}`,
+ `${tool.piName} ${tool.mcpName} ${tool.title ?? ""} ${tool.description} ${tool.serverName}`,
);
if (s > 0) {
hits.set(tool.piName, {
piName: tool.piName,
serverName: tool.serverName,
+ ...(tool.title ? { title: tool.title } : {}),
description: truncateDescription(tool.description),
connected: true,
score: s,
@@ -124,12 +127,13 @@ async function search(
if (hits.has(tool.name)) continue;
const s = score(
queryTerms,
- `${tool.name} ${tool.mcpName} ${tool.description} ${server.name}`,
+ `${tool.name} ${tool.mcpName} ${tool.title ?? ""} ${tool.description} ${server.name}`,
);
if (s > 0) {
hits.set(tool.name, {
piName: tool.name,
serverName: server.name,
+ ...(tool.title ? { title: tool.title } : {}),
description: truncateDescription(tool.description),
connected: false,
score: s,
@@ -174,7 +178,7 @@ function formatHits(hits: Hit[]): string {
const suffix = hit.connected
? ""
: " (not connected — connects on first call)";
- return `${hit.piName}${suffix} — ${hit.description}`;
+ return `${hit.piName}${suffix} — ${hit.title ? `${hit.title}: ` : ""}${hit.description}`;
})
.join("\n");
}
@@ -350,11 +354,17 @@ async function callOrConnect(
kind: "call",
server: owner,
tool: meta.mcpName,
+ ...(meta.title ? { title: meta.title } : {}),
piName: name,
- posthog: mcpCallDetails(owner, meta.mcpName, {
- structuredContent,
- _meta,
- }),
+ posthog: mcpCallDetails(
+ owner,
+ meta.mcpName,
+ {
+ structuredContent,
+ _meta,
+ },
+ meta.title,
+ ),
},
};
}
diff --git a/products/desktop/packages/harness/src/extensions/mcp/render.test.ts b/products/desktop/packages/harness/src/extensions/mcp/render.test.ts
index 4fd6df655c90..7c3f85d39bdd 100644
--- a/products/desktop/packages/harness/src/extensions/mcp/render.test.ts
+++ b/products/desktop/packages/harness/src/extensions/mcp/render.test.ts
@@ -273,6 +273,26 @@ describe("renderMcpProxyResult", () => {
expect(text).toBe("demo \u2192 echo\necho: hi");
});
+ it("strips terminal control sequences from the title", () => {
+ const text = renderText(
+ renderMcpProxyResult(
+ {
+ content: [{ type: "text", text: "echo: hi" }],
+ details: {
+ kind: "call",
+ server: "demo",
+ tool: "echo",
+ piName: "mcp_demo_echo",
+ title: "\u001b]52;c;ZW52aW4=\u0007Evil\u001b[2m title",
+ },
+ },
+ resultOptions(),
+ fakeTheme,
+ ),
+ );
+ expect(text).toBe("demo \u2192 Evil title\necho: hi");
+ });
+
it("truncates long output when collapsed, shows it all expanded", () => {
const bigOutput = Array.from({ length: 30 }, (_, i) => `line ${i}`).join(
"\n",
diff --git a/products/desktop/packages/harness/src/extensions/mcp/render.ts b/products/desktop/packages/harness/src/extensions/mcp/render.ts
index f998478f7b20..9ed364f1ae46 100644
--- a/products/desktop/packages/harness/src/extensions/mcp/render.ts
+++ b/products/desktop/packages/harness/src/extensions/mcp/render.ts
@@ -21,6 +21,15 @@ import type { Hit, McpProxyDetails } from "./proxy-tool";
const MAX_COLLAPSED_ARGS_LENGTH = 120;
+const TERMINAL_SEQUENCES_RE =
+ // biome-ignore lint/suspicious/noControlCharactersInRegex: control sequences must be matched to be stripped
+ /\x1b(?:\[[0-?]*[ -/]*[@-~]|\][^\x07\x1b]*(?:\x07|\x1b\\)|[@-_])/g;
+const CONTROL_CHARS_RE = /\p{Cc}/gu;
+
+export function stripTerminalSequences(value: string): string {
+ return value.replace(TERMINAL_SEQUENCES_RE, "").replace(CONTROL_CHARS_RE, "");
+}
+
/** Compact single-line JSON preview of tool arguments. Empty for no args. */
export function formatArgsCompact(
args: unknown,
@@ -50,12 +59,12 @@ export function formatArgsExpanded(args: unknown): string {
}
export function renderMcpToolCall(
- piName: string,
+ displayName: string,
args: unknown,
theme: Theme,
expanded: boolean,
): InstanceType<typeof Text> {
- let text = theme.fg("toolTitle", theme.bold(piName));
+ let text = theme.fg("toolTitle", theme.bold(displayName));
if (expanded) {
const pretty = formatArgsExpanded(args);
if (pretty) {
@@ -180,11 +189,12 @@ function renderSearchResult(
function renderCallOutput(
server: string,
tool: string,
+ title: string | undefined,
content: ReadonlyArray<{ type: string; text?: string }>,
theme: Theme,
expanded: boolean,
): string {
- const header = `${theme.fg("toolTitle", theme.bold(server))} ${theme.fg("muted", "\u2192")} ${theme.fg("dim", tool)}`;
+ const header = `${theme.fg("toolTitle", theme.bold(server))} ${theme.fg("muted", "\u2192")} ${theme.fg("dim", title ? stripTerminalSequences(title) : tool)}`;
const text = content
.map((c) => (c.type === "text" ? (c.text ?? "") : `[${c.type}]`))
.join("\n")
@@ -260,6 +270,7 @@ export function renderMcpProxyResult(
renderCallOutput(
details.server,
details.tool,
+ details.title,
result.content,
theme,
options.expanded,
diff --git a/products/desktop/packages/harness/src/extensions/mcp/test-support.ts b/products/desktop/packages/harness/src/extensions/mcp/test-support.ts
index d8a9f575cd99..3036a3ad3e1d 100644
--- a/products/desktop/packages/harness/src/extensions/mcp/test-support.ts
+++ b/products/desktop/packages/harness/src/extensions/mcp/test-support.ts
@@ -17,6 +17,7 @@ import type { TransportFactory } from "./server-manager";
export interface MockToolSpec {
name: string;
+ title?: string;
description?: string;
inputSchema?: Record<string, unknown>;
/** Handler invoked on tools/call. */
@@ -226,6 +227,7 @@ export function createMockMcpServer(
const listResult = () => ({
tools: tools.map((tool) => ({
name: tool.name,
+ ...(tool.title ? { title: tool.title } : {}),
description: tool.description ?? `mock tool ${tool.name}`,
inputSchema: tool.inputSchema ?? { type: "object", properties: {} },
})),
diff --git a/products/desktop/packages/harness/src/extensions/mcp/tool-bridge.test.ts b/products/desktop/packages/harness/src/extensions/mcp/tool-bridge.test.ts
index 8b1e99031a02..9f61e552d163 100644
--- a/products/desktop/packages/harness/src/extensions/mcp/tool-bridge.test.ts
+++ b/products/desktop/packages/harness/src/extensions/mcp/tool-bridge.test.ts
@@ -198,6 +198,7 @@ describe("ToolBridge", () => {
tools: [
{
name: "echo",
+ title: "Echo text tool",
description: "Echo text",
inputSchema: {
type: "object",
@@ -212,6 +213,8 @@ describe("ToolBridge", () => {
expect(registered.has("mcp_demo_echo")).toBe(true);
expect(registered.get("mcp_demo_echo")?.description).toBe("Echo text");
+ expect(registered.get("mcp_demo_echo")?.label).toBe("Echo text tool");
+ expect(bridge.getToolMeta("mcp_demo_echo")?.title).toBe("Echo text tool");
// Args are surfaced in the TUI via a custom call renderer.
expect(typeof registered.get("mcp_demo_echo")?.renderCall).toBe("function");
expect(getActive()).toContain("mcp_demo_echo");
@@ -219,6 +222,33 @@ describe("ToolBridge", () => {
expect(getActive()).toContain("read");
});
+ it("strips terminal control sequences from server-provided titles", async () => {
+ const { host, registered } = fakeHost();
+ const bridge = new ToolBridge(settings, host);
+ const client = fakeClient({
+ tools: [
+ {
+ name: "hostile",
+ title: "\u001b]52;c;ZW52aW4=\u0007Evil\u001b[2m title",
+ description: "Hostile title",
+ inputSchema: { type: "object", properties: {} },
+ },
+ {
+ name: "blank",
+ title: "\u001b]52;c;ZW52aW4=\u0007",
+ description: "Blank after sanitizing",
+ inputSchema: { type: "object", properties: {} },
+ },
+ ],
+ });
+
+ await bridge.refreshTools("demo", client);
+
+ expect(registered.get("mcp_demo_hostile")?.label).toBe("Evil title");
+ expect(bridge.getToolMeta("mcp_demo_hostile")?.title).toBe("Evil title");
+ expect(registered.get("mcp_demo_blank")?.label).toBe("blank");
+ });
+
it("appends annotation hints to descriptions", async () => {
const { host, registered } = fakeHost();
const bridge = new ToolBridge(settings, host);
diff --git a/products/desktop/packages/harness/src/extensions/mcp/tool-bridge.ts b/products/desktop/packages/harness/src/extensions/mcp/tool-bridge.ts
index 0da5c894dc4f..323e25774859 100644
--- a/products/desktop/packages/harness/src/extensions/mcp/tool-bridge.ts
+++ b/products/desktop/packages/harness/src/extensions/mcp/tool-bridge.ts
@@ -25,7 +25,7 @@ import {
import { boundPersistedMcpResult } from "@posthog/shared";
import type { McpServerConfig, McpSettings } from "./config";
import { McpError } from "./errors";
-import { renderMcpToolCall } from "./render";
+import { renderMcpToolCall, stripTerminalSequences } from "./render";
import { convertJsonSchemaToTypebox } from "./schema";
import { hashServerConfig, type McpToolCache } from "./tool-cache";
@@ -110,6 +110,7 @@ export function convertMcpContent(items: unknown[]): BridgedContent[] {
export interface McpToolDefinition {
name: string;
+ title?: string;
description?: string;
inputSchema: Record<string, unknown>;
annotations?: {
@@ -173,6 +174,7 @@ export interface ToolCollision {
export interface ToolMeta {
serverName: string;
mcpName: string;
+ title?: string;
description: string;
}
@@ -214,6 +216,14 @@ export function truncateBridgedContent(
});
}
+/** Server-provided titles come from `tools/list`, so they are untrusted text. */
+function resolveToolTitle(tool: McpToolDefinition): string {
+ const raw = tool.title ?? tool.annotations?.title;
+ if (raw === undefined) return tool.name;
+ const cleaned = stripTerminalSequences(raw);
+ return cleaned.length > 0 ? cleaned : tool.name;
+}
+
export interface McpResultMeta {
structuredContent?: Record<string, unknown>;
_meta?: Record<string, unknown>;
@@ -224,6 +234,7 @@ export interface McpCallDetails {
mcp: {
server: string;
tool: string;
+ title?: string;
result?: McpResultMeta;
};
};
@@ -233,6 +244,7 @@ export function mcpCallDetails(
server: string,
tool: string,
result: McpResultMeta,
+ title?: string,
): McpCallDetails["posthog"] {
const hasResult =
result.structuredContent !== undefined || result._meta !== undefined;
@@ -240,6 +252,7 @@ export function mcpCallDetails(
mcp: {
server,
tool,
+ ...(title ? { title } : {}),
...(hasResult
? {
result: {
@@ -490,6 +503,9 @@ export class ToolBridge {
this.toolMeta.set(piName, {
serverName,
mcpName: tool.name,
+ ...(tool.title || tool.annotations?.title
+ ? { title: resolveToolTitle(tool) }
+ : {}),
description,
});
const isDirect =
@@ -525,6 +541,9 @@ export class ToolBridge {
tools: tools.map((tool) => ({
name: buildToolName(this.settings.toolPrefix, serverName, tool.name),
mcpName: tool.name,
+ ...(tool.title || tool.annotations?.title
+ ? { title: resolveToolTitle(tool) }
+ : {}),
description: buildDescription(tool),
})),
};
@@ -586,12 +605,17 @@ export class ToolBridge {
this.pi.registerTool({
name: piName,
- label: tool.annotations?.title ?? tool.name,
+ label: resolveToolTitle(tool),
description,
parameters: convertJsonSchemaToTypebox(tool.inputSchema),
renderCall(args, theme, context) {
- return renderMcpToolCall(piName, args, theme, context.expanded);
+ return renderMcpToolCall(
+ `${serverName} - ${resolveToolTitle(tool)}`,
+ args,
+ theme,
+ context.expanded,
+ );
},
async execute(_toolCallId, params, signal) {
@@ -607,10 +631,17 @@ export class ToolBridge {
return {
content,
details: {
- posthog: mcpCallDetails(serverName, tool.name, {
- structuredContent,
- _meta,
- }),
+ posthog: mcpCallDetails(
+ serverName,
+ tool.name,
+ {
+ structuredContent,
+ _meta,
+ },
+ (tool.title ?? tool.annotations?.title)
+ ? resolveToolTitle(tool)
+ : undefined,
+ ),
},
};
},
diff --git a/products/desktop/packages/harness/src/extensions/mcp/tool-cache.ts b/products/desktop/packages/harness/src/extensions/mcp/tool-cache.ts
index ab5c27adf09c..ef746827cb38 100644
--- a/products/desktop/packages/harness/src/extensions/mcp/tool-cache.ts
+++ b/products/desktop/packages/harness/src/extensions/mcp/tool-cache.ts
@@ -24,6 +24,7 @@ export interface CachedToolInfo {
name: string;
/** Original MCP tool name. */
mcpName: string;
+ title?: string;
description: string;
}
diff --git a/products/desktop/packages/shared/src/index.ts b/products/desktop/packages/shared/src/index.ts
index 04c1a3e7f277..9d2d77c8701d 100644
--- a/products/desktop/packages/shared/src/index.ts
+++ b/products/desktop/packages/shared/src/index.ts
@@ -280,11 +280,16 @@ export {
export type { PiMessagingMode, PiRuntimeHealth } from "./pi-session";
export {
createPiToolCallRecord,
+ formatMcpToolLabel,
+ formatPiMcpToolName,
isPiToolName,
PI_TOOL_KIND_BY_NAME,
+ type PiMcpCallDetails,
type PiToolCallInput,
type PiToolCallRecord,
type PiToolName,
+ parsePiMcpCallDetails,
+ readPiMcpCallDetails,
} from "./pi-tool-call";
export { POSTHOG_PRODUCTS, type PostHogProductId } from "./posthog-products";
export {
@@ -388,6 +393,7 @@ export {
posthogToolMeta,
readAgentToolName,
readMcpInstallationId,
+ readMcpProxyCallDetails,
readMcpToolDescriptor,
readMcpToolName,
readParentToolCallId,
diff --git a/products/desktop/packages/shared/src/pi-tool-call.test.ts b/products/desktop/packages/shared/src/pi-tool-call.test.ts
new file mode 100644
index 000000000000..4b4e40f51922
--- /dev/null
+++ b/products/desktop/packages/shared/src/pi-tool-call.test.ts
@@ -0,0 +1,34 @@
+import { describe, expect, it } from "vitest";
+import { parsePiMcpCallDetails } from "./pi-tool-call";
+
+describe("parsePiMcpCallDetails", () => {
+ it.each(["mcp_posthog_exec", "mcp__posthog__exec"])(
+ "normalizes a direct PostHog exec call: %s",
+ (name) => {
+ expect(
+ parsePiMcpCallDetails(name, {
+ command: "call feature-flag-get-all",
+ }),
+ ).toEqual({
+ kind: "tool",
+ name,
+ args: '{"command":"call feature-flag-get-all"}',
+ });
+ },
+ );
+
+ it("does not normalize other MCP tools", () => {
+ expect(
+ parsePiMcpCallDetails("mcp__posthog__feature-flag-get-all", {
+ limit: 5,
+ }),
+ ).toBeUndefined();
+ });
+
+ it("keeps proxy search details", () => {
+ expect(parsePiMcpCallDetails("mcp", { search: "feature flags" })).toEqual({
+ kind: "search",
+ query: "feature flags",
+ });
+ });
+});
diff --git a/products/desktop/packages/shared/src/pi-tool-call.ts b/products/desktop/packages/shared/src/pi-tool-call.ts
index 030ea83d53f4..09b81006e544 100644
--- a/products/desktop/packages/shared/src/pi-tool-call.ts
+++ b/products/desktop/packages/shared/src/pi-tool-call.ts
@@ -23,6 +23,160 @@ export interface PiToolCallInput {
arguments: unknown;
}
+export const piMcpCallDetailsSchema = z.discriminatedUnion("kind", [
+ z.object({ kind: z.literal("search"), query: z.string().min(1) }),
+ z.object({
+ kind: z.literal("tool"),
+ name: z.string().min(1),
+ args: z.string().optional(),
+ }),
+]);
+export type PiMcpCallDetails = z.infer<typeof piMcpCallDetailsSchema>;
+
+const piMcpProxyInputSchema = z.object({
+ search: z.string().trim().min(1).optional(),
+ tool: z.string().trim().min(1).optional(),
+ args: z.string().optional(),
+});
+
+const posthogExecServerPattern = /^(?:plugin_)?posthog(?:_[^_]+)*$/;
+
+function readPiMcpToolParts(
+ name: string,
+): { server: string; tool: string } | undefined {
+ const withoutPrefix = name.replace(/^mcp_+/, "");
+ const canonicalSeparator = withoutPrefix.indexOf("__");
+ if (canonicalSeparator > 0) {
+ return {
+ server: withoutPrefix.slice(0, canonicalSeparator),
+ tool: withoutPrefix.slice(canonicalSeparator + 2),
+ };
+ }
+
+ if (withoutPrefix.endsWith("_exec")) {
+ return { server: withoutPrefix.slice(0, -5), tool: "exec" };
+ }
+ return undefined;
+}
+
+function isPostHogExecToolName(name: string): boolean {
+ const parts = readPiMcpToolParts(name);
+ return (
+ !!parts &&
+ parts.tool === "exec" &&
+ posthogExecServerPattern.test(parts.server)
+ );
+}
+
+export function parsePiMcpCallDetails(
+ name: string,
+ args: unknown,
+): PiMcpCallDetails | undefined {
+ if (name === "mcp") {
+ const parsed = piMcpProxyInputSchema.safeParse(args);
+ if (!parsed.success) return undefined;
+ if (parsed.data.search) {
+ return { kind: "search", query: parsed.data.search };
+ }
+ if (parsed.data.tool) {
+ return {
+ kind: "tool",
+ name: parsed.data.tool,
+ ...(parsed.data.args ? { args: parsed.data.args } : {}),
+ };
+ }
+ return undefined;
+ }
+
+ if (!isPostHogExecToolName(name)) return undefined;
+ const parsed = z
+ .object({ command: z.string() })
+ .passthrough()
+ .safeParse(args);
+ if (!parsed.success) return undefined;
+
+ return {
+ kind: "tool",
+ name,
+ args: JSON.stringify(parsed.data),
+ };
+}
+
+export function readPiMcpCallDetails(
+ details: unknown,
+): PiMcpCallDetails | undefined {
+ const parsed = piMcpCallDetailsSchema.safeParse(details);
+ return parsed.success ? parsed.data : undefined;
+}
+
+function formatMcpPart(value: string): string {
+ return value.replace(/[_-]+/g, " ").replace(/([a-z\d])([A-Z])/g, "$1 $2");
+}
+
+function pluralizeMcpPart(value: string): string {
+ if (value.endsWith("y")) return `${value.slice(0, -1)}ies`;
+ if (value.endsWith("s")) return value;
+ return `${value}s`;
+}
+
+export function formatMcpToolLabel(value: string): string {
+ const parts = value.split(/[_-]+/).filter(Boolean);
+ if (parts.length === 0) return value;
+
+ const verbs = new Set([
+ "check",
+ "create",
+ "delete",
+ "get",
+ "inspect",
+ "list",
+ "query",
+ "read",
+ "remove",
+ "run",
+ "search",
+ "send",
+ "update",
+ ]);
+ const hasAllSuffix = parts.at(-1) === "all";
+ let verbIndex = -1;
+ if (hasAllSuffix && verbs.has(parts.at(-2) ?? "")) {
+ verbIndex = parts.length - 2;
+ } else if (verbs.has(parts.at(-1) ?? "")) {
+ verbIndex = parts.length - 1;
+ } else if (verbs.has(parts[0] ?? "")) {
+ verbIndex = 0;
+ }
+
+ if (verbIndex >= 0) {
+ const verb = parts[verbIndex];
+ const resource = parts.slice(0, verbIndex);
+ if (verb && resource.length > 0) {
+ const resourceLabel = formatMcpPart(resource.join(" "));
+ return `${verb.charAt(0).toUpperCase()}${verb.slice(1)} ${hasAllSuffix ? pluralizeMcpPart(resourceLabel) : resourceLabel}`;
+ }
+ }
+
+ const label = formatMcpPart(value);
+ return label.charAt(0).toUpperCase() + label.slice(1);
+}
+
+export function formatPiMcpToolName(name: string, toolLabel?: string): string {
+ const withoutPrefix = name.replace(/^mcp_+/, "");
+ const separator = withoutPrefix.indexOf("__");
+ if (separator > 0) {
+ const server = withoutPrefix.slice(0, separator);
+ const tool = withoutPrefix.slice(separator + 2);
+ return `${formatMcpPart(server)} - ${toolLabel ?? formatMcpToolLabel(tool)}`;
+ }
+
+ const [server, ...toolParts] = withoutPrefix.split("_");
+ if (server && toolParts.length > 0) {
+ return `${formatMcpPart(server)} - ${toolLabel ?? formatMcpToolLabel(toolParts.join("_"))}`;
+ }
+ return formatMcpToolLabel(withoutPrefix);
+}
+
export const piToolCallRecordSchema = z.object({
id: z.string(),
name: z.string(),
@@ -43,6 +197,7 @@ export const piToolCallRecordSchema = z.object({
]),
status: z.enum(["pending", "in_progress", "completed", "failed"]),
rawInput: z.unknown(),
+ details: piMcpCallDetailsSchema.optional(),
locations: z
.array(
z.object({
@@ -80,6 +235,8 @@ export function createPiToolCallRecord(
status: AgentToolCallStatus,
): PiToolCallRecord {
const locations = readLocations(input.name, input.arguments);
+ const details = parsePiMcpCallDetails(input.name, input.arguments);
+
return {
id: input.id,
name: input.name,
@@ -87,6 +244,7 @@ export function createPiToolCallRecord(
kind: isPiToolName(input.name) ? PI_TOOL_KIND_BY_NAME[input.name] : "other",
status,
rawInput: input.arguments,
+ ...(details ? { details } : {}),
...(locations ? { locations } : {}),
};
}
diff --git a/products/desktop/packages/shared/src/tool-meta.ts b/products/desktop/packages/shared/src/tool-meta.ts
index 5c339f12054f..6636bfdaea2f 100644
--- a/products/desktop/packages/shared/src/tool-meta.ts
+++ b/products/desktop/packages/shared/src/tool-meta.ts
@@ -7,11 +7,14 @@
* which prefer this channel and fall back to the legacy `_meta.claudeCode.toolName`
* the Claude adapter still writes. New adapters should only populate `posthog`.
*/
+import { type PiMcpCallDetails, readPiMcpCallDetails } from "./pi-tool-call";
+
export interface PosthogToolMeta {
/** Agent-facing tool name, e.g. "Bash" or "mcp__posthog__exec". */
toolName: string;
/** Set only for MCP tool calls — the originating server + tool. */
- mcp?: { server: string; tool: string };
+ mcp?: { server: string; tool: string; title?: string };
+ mcpProxy?: PiMcpCallDetails;
mcpInstallationId?: string;
/** Parent subagent tool call for nested activity. */
parentToolCallId?: string;
@@ -77,7 +80,7 @@ export function readParentToolCallId(meta: unknown): string | undefined {
*/
export function readMcpToolDescriptor(
meta: unknown,
-): { server: string; tool: string } | undefined {
+): { server: string; tool: string; title?: string } | undefined {
const m = asToolCallMeta(meta);
if (m?.posthog?.mcp) return m.posthog.mcp;
const name = m?.posthog?.toolName ?? m?.claudeCode?.toolName;
@@ -93,6 +96,12 @@ export function readMcpToolName(meta: unknown): string | undefined {
return mcp ? mcpToolKey(mcp) : undefined;
}
+export function readMcpProxyCallDetails(
+ meta: unknown,
+): PiMcpCallDetails | undefined {
+ return readPiMcpCallDetails(asToolCallMeta(meta)?.posthog?.mcpProxy);
+}
+
export function readMcpInstallationId(meta: unknown): string | undefined {
return asToolCallMeta(meta)?.posthog?.mcpInstallationId;
}
diff --git a/products/desktop/packages/ui/src/features/mcp-apps/components/McpToolView.test.tsx b/products/desktop/packages/ui/src/features/mcp-apps/components/McpToolView.test.tsx
index e53233b4279c..b0a219c38a68 100644
--- a/products/desktop/packages/ui/src/features/mcp-apps/components/McpToolView.test.tsx
+++ b/products/desktop/packages/ui/src/features/mcp-apps/components/McpToolView.test.tsx
@@ -25,7 +25,11 @@ function textContent(text: string): NonNullable<ToolCall["content"]> {
function renderView(toolCall: ToolCall) {
return render(
<Theme>
- <McpToolView toolCall={toolCall} mcpToolName="posthog__query" expanded />
+ <McpToolView
+ toolCall={toolCall}
+ mcpToolName="mcp__posthog__query"
+ expanded
+ />
</Theme>,
);
}
@@ -39,4 +43,38 @@ describe("McpToolView", () => {
expect(screen.getByText(marker)).toBeInTheDocument();
});
+
+ it.each([
+ {
+ toolName: "mcp__posthog__query",
+ rawInput: {},
+ meta: {
+ posthog: {
+ toolName: "mcp__posthog__query",
+ mcp: { server: "posthog", tool: "query", title: "Run query" },
+ },
+ },
+ expected: "posthog - Run query",
+ },
+ {
+ toolName: "mcp__posthog__exec",
+ rawInput: { command: "call feature-flag-get-all" },
+ expected: "posthog - Get feature flags",
+ },
+ ])(
+ "shows the relevant MCP tool name",
+ ({ toolName, rawInput, meta, expected }) => {
+ render(
+ <Theme>
+ <McpToolView
+ toolCall={makeToolCall({ rawInput, _meta: meta })}
+ mcpToolName={toolName}
+ expanded
+ />
+ </Theme>,
+ );
+
+ expect(screen.getByText(expected)).toBeInTheDocument();
+ },
+ );
});
diff --git a/products/desktop/packages/ui/src/features/mcp-apps/components/McpToolView.tsx b/products/desktop/packages/ui/src/features/mcp-apps/components/McpToolView.tsx
index 6e99d80395c3..c44a4c60e5f1 100644
--- a/products/desktop/packages/ui/src/features/mcp-apps/components/McpToolView.tsx
+++ b/products/desktop/packages/ui/src/features/mcp-apps/components/McpToolView.tsx
@@ -3,6 +3,7 @@ import {
getPostHogExecDisplay,
isPostHogExecTool,
} from "@posthog/core/sessions/posthogExecDisplay";
+import { readMcpToolDescriptor } from "@posthog/shared";
import { useChatThreadChrome } from "../../sessions/components/chat-thread/chatThreadChrome";
import { ToolRow } from "../../sessions/components/session-update/ToolRow";
import {
@@ -43,11 +44,13 @@ export function McpToolView({
const { serverName: defaultServerName, toolName: defaultToolName } =
parseMcpToolKey(mcpToolName);
+ const descriptor = readMcpToolDescriptor(toolCall._meta);
const posthogDisplay = isPostHogExecTool(mcpToolName)
? getPostHogExecDisplay(rawInput)
: null;
- const serverName = posthogDisplay ? "posthog" : defaultServerName;
- const toolName = posthogDisplay?.label ?? defaultToolName;
+ const toolName =
+ posthogDisplay?.label ?? descriptor?.title ?? defaultToolName;
+ const displayName = `${defaultServerName} - ${toolName}`;
const inputPreview = posthogDisplay
? posthogDisplay.input
? truncateText(
@@ -79,7 +82,6 @@ export function McpToolView({
</>
) : undefined;
- const labelClass = chatChrome ? "text-muted-foreground" : "text-gray-10";
const previewClass = chatChrome
? "text-muted-foreground/50"
: "text-accent-11";
@@ -93,12 +95,7 @@ export function McpToolView({
defaultOpen={expanded}
content={body}
>
- <ToolTitle>
- <span className={labelClass}>{serverName}</span>
- {" - "}
- {toolName}
- <span className={labelClass}>{" (MCP)"}</span>
- </ToolTitle>
+ <ToolTitle>{displayName}</ToolTitle>
{inputPreview && (
<ToolTitle>
<span className={previewClass}>{inputPreview}</span>
diff --git a/products/desktop/packages/ui/src/features/posthog-mcp/utils/posthog-exec-display.test.ts b/products/desktop/packages/ui/src/features/posthog-mcp/utils/posthog-exec-display.test.ts
index 8971ccfd3b44..e33986595f9f 100644
--- a/products/desktop/packages/ui/src/features/posthog-mcp/utils/posthog-exec-display.test.ts
+++ b/products/desktop/packages/ui/src/features/posthog-mcp/utils/posthog-exec-display.test.ts
@@ -29,7 +29,7 @@ describe("getPostHogExecDisplay", () => {
expect(
getPostHogExecDisplay({ command: "call experiment-list" }),
).toEqual({
- label: "experiment-list",
+ label: "List experiment",
input: undefined,
});
});
@@ -40,7 +40,7 @@ describe("getPostHogExecDisplay", () => {
command: 'call execute-sql {"query":"SELECT 1"}',
}),
).toEqual({
- label: "execute-sql",
+ label: "Execute sql",
input: '{"query":"SELECT 1"}',
});
});
@@ -51,7 +51,7 @@ describe("getPostHogExecDisplay", () => {
command: 'call --json experiment-update {"id":1}',
}),
).toEqual({
- label: "experiment-update",
+ label: "Update experiment",
input: '{"id":1}',
});
});
@@ -138,7 +138,7 @@ describe("getPostHogExecDisplay", () => {
command: 'call execute-sql {"query":"SELECT 1"}',
input: "SELECT 2",
}),
- ).toEqual({ label: "execute-sql", input: "SELECT 2" });
+ ).toEqual({ label: "Execute sql", input: "SELECT 2" });
});
it("prefers an explicit object `input` (serialised) over command-embedded args (call)", () => {
@@ -147,7 +147,7 @@ describe("getPostHogExecDisplay", () => {
command: "call execute-sql",
input: { query: "SELECT 1" },
}),
- ).toEqual({ label: "execute-sql", input: '{"query":"SELECT 1"}' });
+ ).toEqual({ label: "Execute sql", input: '{"query":"SELECT 1"}' });
});
it("folds explicit `input` into the schema dotted locator", () => {
@@ -165,7 +165,7 @@ describe("getPostHogExecDisplay", () => {
command: 'call execute-sql {"query":"x"}',
input: " ",
}),
- ).toEqual({ label: "execute-sql", input: '{"query":"x"}' });
+ ).toEqual({ label: "Execute sql", input: '{"query":"x"}' });
});
});
@@ -196,7 +196,7 @@ describe("getPostHogExecDisplay", () => {
});
expect(
getPostHogExecDisplay({ command: " call execute-sql " }),
- ).toEqual({ label: "execute-sql", input: undefined });
+ ).toEqual({ label: "Execute sql", input: undefined });
});
});
});
@@ -209,7 +209,7 @@ describe("mcp proxy shape (Pi harness)", () => {
args: '{"command":"call query-trends --from=-7d"}',
}),
).toEqual({
- label: "query-trends",
+ label: "Query trends",
input: "--from=-7d",
});
});
diff --git a/products/desktop/packages/ui/src/features/sessions/components/chat-thread/ToolGroup.test.tsx b/products/desktop/packages/ui/src/features/sessions/components/chat-thread/ToolGroup.test.tsx
index 73c1512ce862..a6d7427c175b 100644
--- a/products/desktop/packages/ui/src/features/sessions/components/chat-thread/ToolGroup.test.tsx
+++ b/products/desktop/packages/ui/src/features/sessions/components/chat-thread/ToolGroup.test.tsx
@@ -1,5 +1,5 @@
import { ServiceProvider } from "@posthog/di/react";
-import { posthogToolMeta } from "@posthog/shared";
+import { createPiToolCallRecord, posthogToolMeta } from "@posthog/shared";
import type { ConversationItem } from "@posthog/ui/features/sessions/components/buildConversationItems";
import { Theme } from "@radix-ui/themes";
import { render, screen } from "@testing-library/react";
@@ -46,6 +46,61 @@ function subagentItem(
} as SessionUpdateItem;
}
+function toolItem(
+ id: string,
+ options: {
+ title: string;
+ details?: unknown;
+ toolMeta?: ReturnType<typeof posthogToolMeta>;
+ },
+): SessionUpdateItem {
+ return {
+ type: "session_update",
+ id,
+ update: {
+ sessionUpdate: "tool_call",
+ toolCallId: id,
+ title: options.title,
+ kind: "other",
+ status: "in_progress",
+ details: options.details,
+ _meta: options.toolMeta,
+ },
+ turnContext: {
+ toolCalls: new Map(),
+ childItems: new Map(),
+ turnCancelled: false,
+ turnComplete: false,
+ },
+ } as SessionUpdateItem;
+}
+
+function piToolItem(
+ id: string,
+ name: string,
+ args: unknown,
+): SessionUpdateItem {
+ const toolCall = createPiToolCallRecord(
+ { id, name, arguments: args },
+ "in_progress",
+ );
+ return {
+ type: "session_update",
+ id,
+ update: {
+ sessionUpdate: "tool_call",
+ toolCallId: id,
+ ...toolCall,
+ },
+ turnContext: {
+ toolCalls: new Map(),
+ childItems: new Map(),
+ turnCancelled: false,
+ turnComplete: false,
+ },
+ } as SessionUpdateItem;
+}
+
function thoughtItem(
id: string,
options: { thoughtComplete: boolean; turnComplete?: boolean },
@@ -96,6 +151,62 @@ describe("ToolGroup", () => {
],
expected: "Subagents",
},
+ {
+ name: "names an MCP proxy call while it is active",
+ items: [
+ piToolItem("mcp-call", "mcp", {
+ tool: "mcp_posthog_query_trends",
+ args: "{}",
+ }),
+ ],
+ expected: "posthog - Query trends",
+ },
+ {
+ name: "names a direct PostHog exec call while it is active",
+ items: [
+ piToolItem("mcp-exec", "mcp_posthog_exec", {
+ command: "call feature-flag-get-all",
+ }),
+ ],
+ expected: "posthog - Get feature flags",
+ },
+ {
+ name: "names an MCP search while it is active",
+ items: [piToolItem("mcp-search", "mcp", { search: "dashboard metrics" })],
+ expected: 'Searching MCP tools for "dashboard metrics"',
+ },
+ {
+ name: "names a direct MCP tool while it is active",
+ items: [piToolItem("mcp-direct", "mcp__posthog__query-trends", {})],
+ expected: "posthog - Query trends",
+ },
+ {
+ name: "uses the server and tool after MCP metadata arrives",
+ items: [
+ toolItem("mcp-metadata", {
+ title: "mcp",
+ toolMeta: posthogToolMeta({
+ toolName: "mcp__posthog__query-trends",
+ mcp: {
+ server: "posthog",
+ tool: "query-trends",
+ title: "Query trends",
+ },
+ }),
+ }),
+ ],
+ expected: "posthog - Query trends",
+ },
+ {
+ name: "ignores malformed MCP display details",
+ items: [
+ toolItem("mcp-invalid", {
+ title: "mcp",
+ details: { kind: "tool", name: 42 },
+ }),
+ ],
+ expected: "MCP",
+ },
{
name: "reads as thinking while a trailing thought streams",
items: [
diff --git a/products/desktop/packages/ui/src/features/sessions/components/chat-thread/ToolGroup.tsx b/products/desktop/packages/ui/src/features/sessions/components/chat-thread/ToolGroup.tsx
index 5d91d00b5979..148df48475a0 100644
--- a/products/desktop/packages/ui/src/features/sessions/components/chat-thread/ToolGroup.tsx
+++ b/products/desktop/packages/ui/src/features/sessions/components/chat-thread/ToolGroup.tsx
@@ -7,11 +7,18 @@ import {
import { readAgentToolName } from "@posthog/shared";
import type { ToolCall } from "@posthog/ui/features/sessions/types";
import { Spinner } from "@posthog/ui/primitives/Spinner";
-import { AnimatePresence, motion, useReducedMotion } from "framer-motion";
+import {
+ AnimatePresence,
+ domAnimation,
+ LazyMotion,
+ m,
+ useReducedMotion,
+} from "framer-motion";
import { memo, useMemo } from "react";
import type { ConversationItem } from "../buildConversationItems";
import { summarizeMemo } from "../new-thread/buildThreadGroups";
import { isSubagentSpawnTool } from "../session-update/collaborationTools";
+import { mcpToolDisplayName } from "../session-update/mcpToolDisplay";
import { SessionUpdateView } from "../session-update/SessionUpdateView";
import { iconForToolCall } from "../session-update/toolCallUtils";
@@ -140,12 +147,16 @@ export const ToolGroup = memo(function ToolGroup({
// thought-only run has to resolve to no current tool rather than throw on `undefined`.
const currentItem = lastActiveTool(tools) ?? tools.at(-1);
const current = currentItem ? resolveTool(currentItem) : null;
- const currentName = currentItem ? friendlyName(toolKey(currentItem)) : null;
- const currentContext =
- current?.toolCall.title &&
- currentName &&
- current.toolCall.title.toLocaleLowerCase() !==
- currentName.toLocaleLowerCase()
+ const mcpName = current ? mcpToolDisplayName(current.toolCall) : undefined;
+ const currentName = currentItem
+ ? (mcpName ?? friendlyName(toolKey(currentItem)))
+ : null;
+ const currentContext = mcpName
+ ? null
+ : current?.toolCall.title &&
+ currentName &&
+ current.toolCall.title.toLocaleLowerCase() !==
+ currentName.toLocaleLowerCase()
? current.toolCall.title
: null;
const LeadIcon = current
@@ -203,31 +214,33 @@ export const ToolGroup = memo(function ToolGroup({
>
{/* `mode="wait"` so the outgoing label clears before the next fades in. Overlapping them
on a single line reads as a flicker rather than a change. */}
- <AnimatePresence mode="wait" initial={false}>
- <motion.span
- key={labelKey}
- className="flex min-w-0 items-center gap-1.5"
- initial={reduceMotion ? false : LABEL_MOTION.initial}
- animate={reduceMotion ? undefined : LABEL_MOTION.animate}
- exit={reduceMotion ? undefined : LABEL_MOTION.exit}
- transition={reduceMotion ? undefined : LABEL_MOTION.transition}
- >
- {showSummary ? (
- <span className="truncate">{summary.doneLabel}</span>
- ) : thinking || !currentName ? (
- <span className="shrink-0 font-medium">Thinking…</span>
- ) : (
- <>
- <span className="shrink-0 font-medium">{currentName}</span>
- {currentContext ? (
- <span className="truncate text-muted-foreground/70">
- {currentContext}
- </span>
- ) : null}
- </>
- )}
- </motion.span>
- </AnimatePresence>
+ <LazyMotion features={domAnimation}>
+ <AnimatePresence mode="wait" initial={false}>
+ <m.span
+ key={labelKey}
+ className="flex min-w-0 items-center gap-1.5"
+ initial={reduceMotion ? false : LABEL_MOTION.initial}
+ animate={reduceMotion ? undefined : LABEL_MOTION.animate}
+ exit={reduceMotion ? undefined : LABEL_MOTION.exit}
+ transition={reduceMotion ? undefined : LABEL_MOTION.transition}
+ >
+ {showSummary ? (
+ <span className="truncate">{summary.doneLabel}</span>
+ ) : thinking || !currentName ? (
+ <span className="shrink-0 font-medium">Thinking…</span>
+ ) : (
+ <>
+ <span className="shrink-0 font-medium">{currentName}</span>
+ {currentContext ? (
+ <span className="truncate text-muted-foreground/70">
+ {currentContext}
+ </span>
+ ) : null}
+ </>
+ )}
+ </m.span>
+ </AnimatePresence>
+ </LazyMotion>
</ChatMarkerContent>
</ChatMarker>
);
diff --git a/products/desktop/packages/ui/src/features/sessions/components/new-thread/buildThreadGroups.test.ts b/products/desktop/packages/ui/src/features/sessions/components/new-thread/buildThreadGroups.test.ts
index 1864419541db..7773619fc474 100644
--- a/products/desktop/packages/ui/src/features/sessions/components/new-thread/buildThreadGroups.test.ts
+++ b/products/desktop/packages/ui/src/features/sessions/components/new-thread/buildThreadGroups.test.ts
@@ -95,6 +95,27 @@ describe("buildThreadGroups MCP detection", () => {
expect(grouping.keepMounted).toEqual([0]);
});
+ it("uses the nested PostHog action in a live group label", () => {
+ const item = toolCallItem("mcp-exec", undefined, {
+ title: "Execute PostHog command",
+ status: "in_progress",
+ details: {
+ kind: "tool",
+ name: "mcp_posthog_exec",
+ args: '{"command":"call feature-flag-get-all"}',
+ },
+ });
+ if (item.type === "session_update") {
+ item.turnContext.turnComplete = false;
+ }
+
+ const grouping = buildThreadGroups([item], {});
+ const row = grouping.rows[0];
+ expect(row.kind).toBe("tool_group");
+ if (row.kind !== "tool_group") return;
+ expect(row.summary.liveLabel).toBe("posthog - Get feature flags");
+ });
+
it("folds non-MCP tool calls into a collapsed group", () => {
const plain = toolCallItem("t1", {
posthog: { toolName: "Bash" },
diff --git a/products/desktop/packages/ui/src/features/sessions/components/new-thread/buildThreadGroups.ts b/products/desktop/packages/ui/src/features/sessions/components/new-thread/buildThreadGroups.ts
index 60701f4b2d1b..b7547575b8f9 100644
--- a/products/desktop/packages/ui/src/features/sessions/components/new-thread/buildThreadGroups.ts
+++ b/products/desktop/packages/ui/src/features/sessions/components/new-thread/buildThreadGroups.ts
@@ -20,6 +20,7 @@ import {
isWorkflowTool,
} from "@posthog/ui/features/sessions/components/session-update/collaborationTools";
import { hasInlineArtifact } from "@posthog/ui/features/sessions/components/session-update/inlineArtifacts";
+import { mcpToolDisplayName } from "@posthog/ui/features/sessions/components/session-update/mcpToolDisplay";
import { iconForToolKind } from "@posthog/ui/features/sessions/components/session-update/toolIcons";
import type { ToolCall } from "@posthog/ui/features/sessions/types";
@@ -220,8 +221,15 @@ function summarize(items: ConversationItem[]): GroupSummary {
if (item.type !== "session_update") continue;
const update = item.update;
if (update.sessionUpdate === "tool_call") {
- // Most recent tool's title — what the chip shows while still running.
- if (update.title) liveLabel = update.title;
+ const resolved = update.toolCallId
+ ? item.turnContext.toolCalls.get(update.toolCallId)
+ : undefined;
+ const displayName = mcpToolDisplayName(
+ resolved ?? (update as unknown as ToolCall),
+ );
+ if (displayName ?? update.title) {
+ liveLabel = displayName ?? update.title ?? null;
+ }
lastToolStatus = update.status ?? undefined;
const name = getToolName(update);
if (isWorkflowTool(name ?? update.title)) {
diff --git a/products/desktop/packages/ui/src/features/sessions/components/session-update/ToolCallBlock.test.tsx b/products/desktop/packages/ui/src/features/sessions/components/session-update/ToolCallBlock.test.tsx
index 49079c306a04..bb303fbfe1cd 100644
--- a/products/desktop/packages/ui/src/features/sessions/components/session-update/ToolCallBlock.test.tsx
+++ b/products/desktop/packages/ui/src/features/sessions/components/session-update/ToolCallBlock.test.tsx
@@ -85,7 +85,7 @@ describe("ToolCallBlock routing", () => {
// The MCP branch renders the title in its header; assert it lands somewhere
// (i.e. the call did not blow up unbound) without an MCP block present.
- expect(screen.getByText("exec")).toBeInTheDocument();
+ expect(screen.getByText("posthog - Exec")).toBeInTheDocument();
});
it("renders a directory listing as a list, not a read", () => {
diff --git a/products/desktop/packages/ui/src/features/sessions/components/session-update/ToolCallView.test.tsx b/products/desktop/packages/ui/src/features/sessions/components/session-update/ToolCallView.test.tsx
index a2b461d25ac5..e175734805e8 100644
--- a/products/desktop/packages/ui/src/features/sessions/components/session-update/ToolCallView.test.tsx
+++ b/products/desktop/packages/ui/src/features/sessions/components/session-update/ToolCallView.test.tsx
@@ -39,4 +39,52 @@ describe("ToolCallView", () => {
expect(screen.getByText(marker)).toBeInTheDocument();
});
+
+ it.each([
+ {
+ title: "mcp",
+ details: { kind: "search", query: "business knowledge" },
+ expected: "Search MCP tools",
+ },
+ {
+ title: "mcp",
+ details: {
+ kind: "tool",
+ name: "mcp_posthog_exec",
+ args: JSON.stringify({ command: "call feature-flag-get-all" }),
+ },
+ expected: "posthog - Get feature flags",
+ },
+ {
+ title: "mcp__posthog__project-get",
+ meta: {
+ posthog: {
+ toolName: "mcp__posthog__project-get",
+ mcp: { server: "posthog", tool: "project-get", title: "Get project" },
+ },
+ },
+ expected: "posthog - Get project",
+ },
+ {
+ title: "mcp",
+ meta: {
+ posthog: {
+ toolName: "mcp",
+ mcpProxy: {
+ kind: "tool",
+ name: "mcp_posthog_exec",
+ args: JSON.stringify({ command: "schema feature-flag-get-all" }),
+ },
+ },
+ },
+ expected: "posthog - Inspect feature-flag-get-all fields",
+ },
+ ])(
+ "shows a readable MCP tool label",
+ ({ title, details, meta, expected }) => {
+ renderView(makeToolCall({ title, details, _meta: meta }));
+
+ expect(screen.getByText(expected)).toBeInTheDocument();
+ },
+ );
});
diff --git a/products/desktop/packages/ui/src/features/sessions/components/session-update/ToolCallView.tsx b/products/desktop/packages/ui/src/features/sessions/components/session-update/ToolCallView.tsx
index b3fd4d29d93a..2c761a013f5c 100644
--- a/products/desktop/packages/ui/src/features/sessions/components/session-update/ToolCallView.tsx
+++ b/products/desktop/packages/ui/src/features/sessions/components/session-update/ToolCallView.tsx
@@ -1,4 +1,12 @@
-import { compactHomePath } from "@posthog/shared";
+import { getPostHogExecDisplay } from "@posthog/core/sessions/posthogExecDisplay";
+import {
+ compactHomePath,
+ formatPiMcpToolName,
+ readMcpProxyCallDetails,
+ readMcpToolDescriptor,
+ readPiMcpCallDetails,
+} from "@posthog/shared";
+import type { ToolCall } from "@posthog/ui/features/sessions/types";
import { useChatThreadChrome } from "../chat-thread/chatThreadChrome";
import { ToolRow } from "./ToolRow";
import {
@@ -36,6 +44,48 @@ interface ToolCallViewProps extends ToolViewProps {
agentToolName?: string;
}
+function mcpProxyDisplay(
+ toolCall: ToolCall,
+): { title: string; input?: string } | undefined {
+ const details =
+ readPiMcpCallDetails(toolCall.details) ??
+ readMcpProxyCallDetails(toolCall._meta);
+ if (details?.kind === "search") {
+ return { title: "Search MCP tools", input: details.query };
+ }
+ if (details?.kind === "tool") {
+ const posthogDisplay = getPostHogExecDisplay({
+ tool: details.name,
+ args: details.args,
+ });
+ const descriptor = readMcpToolDescriptor(toolCall._meta);
+ const label = posthogDisplay?.label ?? descriptor?.title;
+ if (label) {
+ return {
+ title: formatPiMcpToolName(details.name, label),
+ ...(posthogDisplay?.input ? { input: posthogDisplay.input } : {}),
+ };
+ }
+ return { title: formatPiMcpToolName(details.name) };
+ }
+ const descriptor = readMcpToolDescriptor(toolCall._meta);
+ if (descriptor) {
+ return {
+ title: formatPiMcpToolName(
+ `mcp__${descriptor.server}__${descriptor.tool}`,
+ descriptor.title,
+ ),
+ };
+ }
+ if (toolCall.title.startsWith("mcp_")) {
+ return { title: formatPiMcpToolName(toolCall.title) };
+ }
+ if (toolCall.title === "mcp") {
+ return { title: "MCP" };
+ }
+ return undefined;
+}
+
export function ToolCallView({
toolCall,
turnCancelled,
@@ -66,20 +116,25 @@ export function ToolCallView({
toolDisplay && typeof highlightValue === "string"
? { ...toolDisplay, value: highlightValue }
: undefined;
+ const mcpDisplay = mcpProxyDisplay(toolCall);
// New thread reads back in past tense once the tool has finished ("Reading" → "Read"); the legacy
// thread keeps the original present-tense prefix so ConversationView is unchanged when toggled off.
- const displayText = specialDisplay
- ? chatChrome && !isLoading
- ? specialDisplay.pastPrefix
- : specialDisplay.prefix
- : filePath
- ? `Read ${getFilename(filePath)}`
- : title
- ? compactHomePath(title)
- : undefined;
+ const displayText =
+ mcpDisplay?.title ??
+ (specialDisplay
+ ? chatChrome && !isLoading
+ ? specialDisplay.pastPrefix
+ : specialDisplay.prefix
+ : filePath
+ ? `Read ${getFilename(filePath)}`
+ : title
+ ? compactHomePath(title)
+ : undefined);
- const inputPreview = specialDisplay?.value ?? compactInput(rawInput);
+ const inputPreview = mcpDisplay
+ ? mcpDisplay.input
+ : (specialDisplay?.value ?? compactInput(rawInput));
const fullInput = formatInput(rawInput);
const output = stripCodeFences(getContentText(content) ?? "");
diff --git a/products/desktop/packages/ui/src/features/sessions/components/session-update/mcpToolDisplay.ts b/products/desktop/packages/ui/src/features/sessions/components/session-update/mcpToolDisplay.ts
new file mode 100644
index 000000000000..74e609633c68
--- /dev/null
+++ b/products/desktop/packages/ui/src/features/sessions/components/session-update/mcpToolDisplay.ts
@@ -0,0 +1,42 @@
+import { getPostHogExecDisplay } from "@posthog/core/sessions/posthogExecDisplay";
+import {
+ formatPiMcpToolName,
+ readMcpProxyCallDetails,
+ readMcpToolDescriptor,
+ readPiMcpCallDetails,
+} from "@posthog/shared";
+import type { ToolCall } from "@posthog/ui/features/sessions/types";
+
+export function mcpToolDisplayName(toolCall: ToolCall): string | undefined {
+ const details =
+ readPiMcpCallDetails(toolCall.details) ??
+ readMcpProxyCallDetails(toolCall._meta);
+ if (details?.kind === "search") {
+ return `Searching MCP tools for "${details.query}"`;
+ }
+ if (details?.kind === "tool") {
+ const posthogDisplay = getPostHogExecDisplay({
+ tool: details.name,
+ args: details.args,
+ });
+ const descriptor = readMcpToolDescriptor(toolCall._meta);
+ const label = posthogDisplay?.label ?? descriptor?.title;
+ return label
+ ? formatPiMcpToolName(details.name, label)
+ : formatPiMcpToolName(details.name);
+ }
+
+ const descriptor = readMcpToolDescriptor(toolCall._meta);
+ if (descriptor) {
+ return formatPiMcpToolName(
+ `mcp__${descriptor.server}__${descriptor.tool}`,
+ descriptor.title,
+ );
+ }
+
+ if (toolCall.title.startsWith("mcp_")) {
+ return formatPiMcpToolName(toolCall.title);
+ }
+
+ return toolCall.title === "mcp" ? "MCP" : undefined;
+}