Skip to content
Merged
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
@@ -1,9 +1,10 @@
import { ActionSelector } from "@components/ActionSelector";
import { parseMcpToolKey } from "@features/mcp-apps/utils/mcp-app-host-utils";
import {
formatPosthogExecBody,
getPostHogExecDisplay,
isPostHogExecTool,
} from "@features/mcp-apps/utils/posthog-exec-display";
} from "@features/posthog-mcp/utils/posthog-exec-display";
import { formatInput } from "@features/sessions/components/session-update/toolCallUtils";
import { Box, Code } from "@radix-ui/themes";
import { DefaultPermission } from "./DefaultPermission";
Expand Down Expand Up @@ -37,7 +38,9 @@ export function McpPermission({
: null;
const serverName = posthogDisplay ? "posthog" : defaultServerName;
const toolName = posthogDisplay?.label ?? defaultToolName;
const fullInput = formatInput(toolCall.rawInput);
const fullInput = posthogDisplay
? formatPosthogExecBody(posthogDisplay.input)
: formatInput(toolCall.rawInput);

return (
<ActionSelector
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,39 @@ export const McpPostHogExec: Story = {
},
};

const posthogExecInfoInput = { command: "info execute-sql" };
export const McpPostHogExecInfo: Story = {
args: {
toolCall: buildMcpToolCallData("mcp__posthog__exec", posthogExecInfoInput),
options: buildPermissionOptions("mcp__posthog__exec", posthogExecInfoInput),
},
};

const posthogExecToolsInput = { command: "tools" };
export const McpPostHogExecTools: Story = {
args: {
toolCall: buildMcpToolCallData("mcp__posthog__exec", posthogExecToolsInput),
options: buildPermissionOptions(
"mcp__posthog__exec",
posthogExecToolsInput,
),
},
};

const posthogExecSearchInput = { command: "search query-" };
export const McpPostHogExecSearch: Story = {
args: {
toolCall: buildMcpToolCallData(
"mcp__posthog__exec",
posthogExecSearchInput,
),
options: buildPermissionOptions(
"mcp__posthog__exec",
posthogExecSearchInput,
),
},
};

const githubIssueInput = {
owner: "PostHog",
repo: "posthog",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
import {
getPostHogExecDisplay,
isPostHogExecTool,
} from "@features/posthog-mcp/utils/posthog-exec-display";
import {
compactInput,
ExpandableIcon,
Expand All @@ -15,10 +19,6 @@ import { Plugs } from "@phosphor-icons/react";
import { Box, Flex } from "@radix-ui/themes";
import { useState } from "react";
import { parseMcpToolKey } from "../utils/mcp-app-host-utils";
import {
getPostHogExecDisplay,
isPostHogExecTool,
} from "../utils/posthog-exec-display";

const POSTHOG_EXEC_INPUT_PREVIEW_MAX_LENGTH = 60;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { describe, expect, it } from "vitest";
import {
formatPosthogExecBody,
getPostHogExecDisplay,
isPostHogExecTool,
} from "./posthog-exec-display";
Expand Down Expand Up @@ -199,3 +200,31 @@ describe("getPostHogExecDisplay", () => {
});
});
});

describe("formatPosthogExecBody", () => {
it("returns undefined for empty input", () => {
expect(formatPosthogExecBody(undefined)).toBeUndefined();
expect(formatPosthogExecBody("")).toBeUndefined();
});

it("pretty-prints JSON object payloads", () => {
expect(formatPosthogExecBody('{"id":3}')).toBe('{\n "id": 3\n}');
});

it("pretty-prints JSON array payloads", () => {
expect(formatPosthogExecBody("[1,2]")).toBe("[\n 1,\n 2\n]");
});

it("returns non-JSON strings unchanged (e.g. search regex)", () => {
expect(formatPosthogExecBody("query-")).toBe("query-");
});

it("returns malformed JSON unchanged", () => {
expect(formatPosthogExecBody('{"id":')).toBe('{"id":');
});

it("returns JSON primitives unchanged (not pretty-printable)", () => {
expect(formatPosthogExecBody("42")).toBe("42");
expect(formatPosthogExecBody('"hello"')).toBe('"hello"');
});
});
Comment thread
skoob13 marked this conversation as resolved.
Original file line number Diff line number Diff line change
Expand Up @@ -108,3 +108,23 @@ function readExplicitInput(value: unknown): string | undefined {
return undefined;
}
}

/**
* Pretty-prints the unwrapped exec args for display in the permission dialog
* body — JSON payloads (the `call` case) render multi-line; non-JSON args
* (e.g. a `search` regex) pass through unchanged.
*/
export function formatPosthogExecBody(
input: string | undefined,
): string | undefined {
if (!input) return undefined;
try {
const parsed = JSON.parse(input);
if (parsed && typeof parsed === "object") {
return JSON.stringify(parsed, null, 2);
}
} catch {
// not JSON — fall through and show raw
}
return input;
}
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,7 @@ describe("canUseTool MCP approval enforcement", () => {
expect.objectContaining({
toolCall: expect.objectContaining({
title: "The agent wants to run `notebooks-destroy` on PostHog",
_meta: { claudeCode: { toolName: "mcp__posthog__exec" } },
}),
}),
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -528,6 +528,7 @@ async function handlePostHogExecApprovalFlow(
},
],
rawInput: { ...(toolInput as Record<string, unknown>), toolName },
_meta: { claudeCode: { toolName } },
},
});

Expand Down
Loading