Skip to content

Local UI to run and train LLMs and diffusion models. Supports GGUF, MLX, Qwen3.8, DeepSeek-V4.1, MiniMax-H3, Gemma 4, FLUX and more.

Studio: MCP widget approval cards show the arguments being sent (#14458)

Daniel Handff0fb917d19
diff --git a/studio/frontend/scripts/check-bundle-budget.ts b/studio/frontend/scripts/check-bundle-budget.ts
index 957ab8d25c3..d5bb4df6190 100644
--- a/studio/frontend/scripts/check-bundle-budget.ts
+++ b/studio/frontend/scripts/check-bundle-budget.ts
@@ -338,8 +338,11 @@ export const BUDGET = {
// machine and build, Node 22, 96 chunks); the share switch itself is in the lazy Connections tab. Raised by that.
// The browser panel's page history (#14283) on top measures 6,876,588 B raw / 2,070,700 B transfer (merged with
// main at 04d2beec9, Node 24, 97 chunks). Raised to that plus the same margin.
- transferBytes: 2_070_889,
- rawBytes: 6_876_748,
+ // The MCP app tool arguments on the approval card (#14458) in the eager chat UI add 341 B raw / 110 B transfer
+ // (6,862,706 -> 6,863,047 B raw, 2,066,422 -> 2,066,532 B transfer against 2aeeceb07e, one machine and build,
+ // 96 chunks). Raised by that.
+ transferBytes: 2_070_999,
+ rawBytes: 6_877_089,
};
// The chunk count is reported but not budgeted. Splitting a page out of the entry raises it while lowering the
diff --git a/studio/frontend/src/features/chat/mcp-apps/mcp-app-frame.tsx b/studio/frontend/src/features/chat/mcp-apps/mcp-app-frame.tsx
index 88dac381de7..e7e6cc9164e 100644
--- a/studio/frontend/src/features/chat/mcp-apps/mcp-app-frame.tsx
+++ b/studio/frontend/src/features/chat/mcp-apps/mcp-app-frame.tsx
@@ -20,8 +20,10 @@ import {
RESIZE_FALLBACK,
bridgeShim,
cspFrameQuery,
+ forReview,
newBridgeToken,
toolApprovalScope,
+ toolArgsForReview,
toolResultParams,
withBridgeShim,
} from "./mcp-ui";
@@ -76,16 +78,6 @@ interface PendingToolCall {
const clampHeight = (h: number) =>
Math.min(Math.max(h, MIN_HEIGHT), MAX_HEIGHT);
-function argsPreview(args: Record<string, unknown>): string {
- if (Object.keys(args).length === 0) return "";
- try {
- const text = JSON.stringify(args, null, 2);
- return text.length > 600 ? `${text.slice(0, 600)}…` : text;
- } catch {
- return "";
- }
-}
-
// The shell's CSP is fixed at request time, so declared domains ride the URL; never the auth token.
function frameSrc(csp: McpUiResource["ui"]["csp"] | null): string {
const query = cspFrameQuery(csp);
@@ -205,7 +197,8 @@ export function McpAppFrame(props: McpAppFrameProps) {
if (pendingRef.current.length >= MAX_PENDING_TOOL_CALLS) {
throw new RpcError("Too many tool requests are waiting");
}
- const preview = argsPreview(args);
+ // The card shows what an Allow will post; a very long call says how much is not shown.
+ const preview = toolArgsForReview(args);
const [allow, always] = await new Promise<[boolean, boolean]>((done) =>
setQueue([
...pendingRef.current,
@@ -476,7 +469,9 @@ export function McpAppFrame(props: McpAppFrameProps) {
>
<div>
{asking.link ? "This app wants to open " : "This app wants to run "}
- <span className="font-mono break-all">{asking.name}</span>
+ <span className="font-mono break-all">
+ {forReview(asking.name)}
+ </span>
{pendingCalls.length > 1
? ` (+${pendingCalls.length - 1} more waiting)`
: ""}
diff --git a/studio/frontend/src/features/chat/mcp-apps/mcp-ui.ts b/studio/frontend/src/features/chat/mcp-apps/mcp-ui.ts
index 619e5c17a8f..9d58bb40dca 100644
--- a/studio/frontend/src/features/chat/mcp-apps/mcp-ui.ts
+++ b/studio/frontend/src/features/chat/mcp-apps/mcp-ui.ts
@@ -85,6 +85,37 @@ export function toolApprovalScope(
return threadId ? `${session}:${threadId}` : session;
}
+export const MAX_REVIEW_ARGS_CHARS = 20_000;
+
+// Every default-ignorable code point (bidi controls, tags, variation selectors, fillers), plus line separators.
+const HIDDEN_CHARS = /[\p{Default_Ignorable_Code_Point}\u2028\u2029]/gu;
+
+/** Bidi and invisible characters as `\uXXXX`, so what a card shows can't read reordered or hide text. */
+export function forReview(text: string): string {
+ // Per UTF-16 unit, so an astral character becomes a surrogate pair JSON.parse still reads.
+ return text.replace(HIDDEN_CHARS, (c) =>
+ Array.from(
+ { length: c.length },
+ (_, i) => `\\u${c.charCodeAt(i).toString(16).padStart(4, "0")}`,
+ ).join(""),
+ );
+}
+
+/** A widget call's arguments as they will be sent; a very long one is cut with a note saying so. */
+export function toolArgsForReview(args: Record<string, unknown>): string {
+ if (Object.keys(args).length === 0) return "";
+ let text: string;
+ try {
+ // Escaped inside JSON strings, so the shown text still parses to the sent arguments.
+ text = forReview(JSON.stringify(args, null, 2));
+ } catch {
+ return "(the arguments cannot be shown)";
+ }
+ if (text.length <= MAX_REVIEW_ARGS_CHARS) return text;
+ const hidden = text.length - MAX_REVIEW_ARGS_CHARS;
+ return `${text.slice(0, MAX_REVIEW_ARGS_CHARS)}\n… ${hidden.toLocaleString()} more characters are sent but not shown`;
+}
+
/** The tool-result seed: server blocks, image bytes put back from the images envelope in order. */
export function toolResultParams(
ui: McpUiEnvelope,
diff --git a/studio/frontend/tests/mcp-app-args-review.test.ts b/studio/frontend/tests/mcp-app-args-review.test.ts
new file mode 100644
index 00000000000..ffd360c5701
--- /dev/null
+++ b/studio/frontend/tests/mcp-app-args-review.test.ts
@@ -0,0 +1,68 @@
+// SPDX-License-Identifier: AGPL-3.0-only
+// Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
+
+import assert from "node:assert/strict";
+import { readFileSync } from "node:fs";
+import test from "node:test";
+
+import * as mcpUi from "../src/features/chat/mcp-apps/mcp-ui.ts";
+
+const frame = readFileSync(
+ new URL("../src/features/chat/mcp-apps/mcp-app-frame.tsx", import.meta.url),
+ "utf8",
+);
+
+// Read loosely: on a tree without the export, the assertion below is the failure.
+const review = (mcpUi as Record<string, unknown>).toolArgsForReview as
+ | ((args: Record<string, unknown>) => string | null)
+ | undefined;
+
+test("an argument placed after 600 characters reaches the approval card", () => {
+ assert.equal(typeof review, "function", "mcp-ui.ts exports no toolArgsForReview");
+ const args = { note: "x".repeat(620), path: "/home/user/.ssh/id_ed25519" };
+ const shown = review?.(args);
+ assert.equal(shown, JSON.stringify(args, null, 2));
+ assert.match(shown ?? "", /id_ed25519/);
+});
+
+test("arguments too long to show whole say how much is not shown", () => {
+ assert.equal(typeof review, "function", "mcp-ui.ts exports no toolArgsForReview");
+ const max = (mcpUi as Record<string, unknown>).MAX_REVIEW_ARGS_CHARS as number;
+ const shown = review?.({ blob: "y".repeat(max) }) ?? "";
+ assert.match(shown, /more characters are sent but not shown$/);
+ assert.equal(review?.({}), "");
+});
+
+test("the frame shows the reviewed arguments, not a silent 600-character cut", () => {
+ assert.doesNotMatch(frame, /\.slice\(0, 600\)/);
+ assert.match(frame, /const preview = toolArgsForReview\(args\);/);
+});
+
+const BS = String.fromCharCode(92);
+
+test("bidi and invisible characters can't reorder or hide what the card shows", () => {
+ const args = { path: "/tmp/\u202Etxt.etoN", note: "a\u200Bb\u2066c\u2028d" };
+ const shown = review?.(args) ?? "";
+ assert.doesNotMatch(shown, /[\u200B\u202E\u2066\u2028]/);
+ assert.ok(shown.includes(`${BS}u202e`));
+ assert.deepEqual(JSON.parse(shown), args);
+ // A ui/open-link card: the real host must stay readable.
+ const forReview = (mcpUi as Record<string, unknown>).forReview as
+ | ((text: string) => string)
+ | undefined;
+ assert.equal(
+ forReview?.("https://good.example\[email protected]/"),
+ `https://good.example${BS}[email protected]/`,
+ );
+ assert.match(frame, /\{forReview\(asking\.name\)\}/);
+});
+
+test("every default-ignorable character is shown, astral ones included", () => {
+ // U+034F, a variation selector, a Hangul filler and a LANGUAGE TAG all render as nothing.
+ const args = { cmd: "rm\u034F -rf\uFE0F /\u3164x\u{E0001}y" };
+ const shown = review?.(args) ?? "";
+ assert.doesNotMatch(shown, /[\u034F\uFE0F\u3164\u{E0001}]/u);
+ assert.ok(shown.includes(`${BS}u034f`));
+ assert.ok(shown.includes(`${BS}udb40${BS}udc01`));
+ assert.deepEqual(JSON.parse(shown), args);
+});