Skip to content
Closed
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
10 changes: 6 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,19 @@ 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,
getMcpPermissionToolName,
toSelectorOptions,
} from "./types";

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,40 @@
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 using claudeCode.toolName metadata", () => {
render(
<Theme>
<PermissionSelector
toolCall={{
toolCallId: "tool-1",
title: "exec",
kind: "other",
rawInput: { command: "info execute-sql" },
_meta: { claudeCode: { 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 @@ -11,7 +11,7 @@ import { ReadPermission } from "./ReadPermission";
import { SearchPermission } from "./SearchPermission";
import { SwitchModePermission } from "./SwitchModePermission";
import { ThinkPermission } from "./ThinkPermission";
import type { PermissionToolCall } from "./types";
import { getMcpPermissionToolName, type PermissionToolCall } from "./types";

interface PermissionSelectorProps {
toolCall: PermissionToolCall;
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
9 changes: 9 additions & 0 deletions apps/code/src/renderer/components/permissions/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,15 @@ export interface BasePermissionProps {
onCancel: () => void;
}

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

export function toSelectorOptions(
options: PermissionOption[],
): SelectorOption[] {
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