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
23 changes: 19 additions & 4 deletions apps/code/src/renderer/components/permissions/McpPermission.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,32 @@ import {
import { formatInput } from "@features/sessions/components/session-update/toolCallUtils";
import { Box, Code } from "@radix-ui/themes";
import { DefaultPermission } from "./DefaultPermission";
import { type BasePermissionProps, toSelectorOptions } from "./types";
import {
type BasePermissionProps,
type PermissionToolCall,
toSelectorOptions,
} from "./types";

export function getMcpPermissionToolName(
toolCall: PermissionToolCall,
): string | undefined {
const metaToolName = (
toolCall._meta as { claudeCode?: { toolName?: unknown } } | undefined
)?.claudeCode?.toolName;
if (typeof metaToolName === "string") return metaToolName;

const rawToolName = (toolCall.rawInput as { toolName?: unknown } | undefined)
?.toolName;
return typeof rawToolName === "string" ? rawToolName : undefined;
}

export function McpPermission({
toolCall,
options,
onSelect,
onCancel,
}: BasePermissionProps) {
const mcpToolName = (
toolCall._meta as { claudeCode?: { toolName?: string } } | undefined
)?.claudeCode?.toolName;
const mcpToolName = getMcpPermissionToolName(toolCall);

if (!mcpToolName) {
return (
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { Theme } from "@radix-ui/themes";
import { render, screen } from "@testing-library/react";
import { describe, expect, it, vi } from "vitest";
import { PermissionSelector } from "./PermissionSelector";

describe("PermissionSelector", () => {
it("renders MCP permissions from rawInput toolName when metadata is missing", () => {
render(
<Theme>
<PermissionSelector
toolCall={{
toolCallId: "tool-1",
title: "exec",
kind: "other",
rawInput: {
command: "info execute-sql",
toolName: "mcp__posthog__exec",
},
}}
options={[
{ kind: "allow_once", optionId: "allow", name: "Yes" },
{
kind: "allow_always",
optionId: "allow_always",
name: "Yes, always allow",
},
]}
onSelect={vi.fn()}
onCancel={vi.fn()}
/>
</Theme>,
);

expect(
screen.getByText(
(_, element) =>
element?.textContent === "posthog - Read execute-sql (MCP)",
),
).toBeInTheDocument();
expect(screen.queryByText(/^exec$/)).not.toBeInTheDocument();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { DeletePermission } from "./DeletePermission";
import { EditPermission } from "./EditPermission";
import { ExecutePermission } from "./ExecutePermission";
import { FetchPermission } from "./FetchPermission";
import { McpPermission } from "./McpPermission";
import { getMcpPermissionToolName, McpPermission } from "./McpPermission";
import { MovePermission } from "./MovePermission";
import { QuestionPermission } from "./QuestionPermission";
import { ReadPermission } from "./ReadPermission";
Expand All @@ -31,10 +31,8 @@ export function PermissionSelector({
onCancel,
}: PermissionSelectorProps) {
const props = { toolCall, options, onSelect, onCancel };
const meta = toolCall._meta as
| { codeToolKind?: string; claudeCode?: { toolName?: string } }
| undefined;
const agentToolName = meta?.claudeCode?.toolName;
const meta = toolCall._meta as { codeToolKind?: string } | undefined;
const agentToolName = getMcpPermissionToolName(toolCall);
if (agentToolName?.startsWith("mcp__")) {
return <McpPermission {...props} />;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,33 @@ describe("canUseTool MCP approval enforcement", () => {
expect.objectContaining({
toolCall: expect.objectContaining({
title: "The agent wants to call search_crm_objects (HubSpot)",
_meta: {
claudeCode: { toolName: "mcp__HubSpot__search_crm_objects" },
},
}),
}),
);
});

it("passes metadata through generic PostHog exec approval requests", async () => {
setMcpToolApprovalStates({
mcp__posthog__exec: "needs_approval",
});

const context = createContext("mcp__posthog__exec", {
toolInput: { command: "info execute-sql" },
});
const result = await canUseTool(context);

expect(result.behavior).toBe("allow");
expect(context.client.requestPermission).toHaveBeenCalledWith(
expect.objectContaining({
toolCall: expect.objectContaining({
rawInput: expect.objectContaining({
command: "info execute-sql",
toolName: "mcp__posthog__exec",
}),
_meta: { claudeCode: { toolName: "mcp__posthog__exec" } },
}),
}),
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,7 @@ async function handleMcpApprovalFlow(
? [{ type: "content" as const, content: text(description) }]
: [],
rawInput: { ...(toolInput as Record<string, unknown>), toolName },
_meta: { claudeCode: { toolName } },
},
});

Expand Down