Skip to content

The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.

fix(mcp-ui): key remembered tool confirmations by name and arguments

oxoxDev4ca78e075c06
diff --git a/app/src/features/conversations/tools/mcpUi/McpAppFrame.test.tsx b/app/src/features/conversations/tools/mcpUi/McpAppFrame.test.tsx
index 2edcdae665..91d55d7196 100644
--- a/app/src/features/conversations/tools/mcpUi/McpAppFrame.test.tsx
+++ b/app/src/features/conversations/tools/mcpUi/McpAppFrame.test.tsx
@@ -106,6 +106,30 @@ describe('McpAppFrame tool decisions', () => {
expect(await screen.findByTestId('mcp-ui-confirm')).toBeInTheDocument();
});
+ it('does not reuse an approval for the same tool with different arguments', async () => {
+ const { handlers } = await mountFrame();
+
+ let approved!: Promise<unknown>;
+ act(() => {
+ approved = handlers.callTool('place_order', { item: 'tea' });
+ });
+ fireEvent.click(await screen.findByRole('button', { name: 'Allow' }));
+ await expect(approved).resolves.toEqual({ tool: 'place_order' });
+
+ let sameArgs!: Promise<unknown>;
+ act(() => {
+ sameArgs = handlers.callTool('place_order', { item: 'tea' });
+ });
+ await expect(sameArgs).resolves.toEqual({ tool: 'place_order' });
+ expect(screen.queryByTestId('mcp-ui-confirm')).toBeNull();
+
+ act(() => {
+ void handlers.callTool('place_order', { item: 'laptop' }).catch(() => undefined);
+ });
+ expect(await screen.findByTestId('mcp-ui-confirm')).toBeInTheDocument();
+ expect(api.toolCall).not.toHaveBeenCalledWith('shop', 'place_order', { item: 'laptop' }, true);
+ });
+
it('keeps one bridge and hands it newer data for the same widget', async () => {
const { view } = await mountFrame();
view.rerender(<McpAppFrame presentation={presentation({ q: 2 })} />);
diff --git a/app/src/features/conversations/tools/mcpUi/McpAppFrame.tsx b/app/src/features/conversations/tools/mcpUi/McpAppFrame.tsx
index 2ab7b7d25e..906480d8e6 100644
--- a/app/src/features/conversations/tools/mcpUi/McpAppFrame.tsx
+++ b/app/src/features/conversations/tools/mcpUi/McpAppFrame.tsx
@@ -90,13 +90,14 @@ export function McpAppFrame({ presentation }: { presentation: McpUiPresentation
if (!serverId) throw new Error('No server for this view');
const first = await mcpUiApi.toolCall(serverId, name, args, false);
if (!first.requires_confirmation) return first.result;
- let decision = decisionsRef.current.get(name);
+ const decisionKey = JSON.stringify([name, args]);
+ let decision = decisionsRef.current.get(decisionKey);
if (!decision) {
decision = new Promise<void>((resolve, reject) =>
setPending({ name, args, resolve, reject })
);
decision.catch(() => undefined);
- decisionsRef.current.set(name, decision);
+ decisionsRef.current.set(decisionKey, decision);
}
await decision;
const confirmed = await mcpUiApi.toolCall(serverId, name, args, true);