The best way to control Claude Code, Codex and more from any computer or phone
fix(client-runtime): long MCP app download names no longer split an emoji (#35680)
Julius Marminge committed
Nov 12, 2026 at 15:46 UTC
cfad3109135f8f8fe0ef41633a04b276107913a0
2 files changed
+13
-6
packages/client-runtime/src/mcpApps/host.test.ts
+6
-2
@@ -325,7 +325,7 @@ describe("makeMcpAppHost", () => {
325
326
it("forwards model context and download requests, and declares both", async () => {
327
const contexts: Array<unknown> = [];
328
- const downloads: Array<unknown> = [];
328
+ const downloads: Array<ReadonlyArray<{ readonly name: string }>> = [];
329
const { host, sent } = setup({
330
updateModelContext: async (update) => void contexts.push(update),
331
downloadFile: async (files) => {
@@ -349,6 +349,7 @@ describe("makeMcpAppHost", () => {
349
structuredContent: { overdue: 2, since: undefined },
350
},
351
});
352
+ const longName = `${"a".repeat(199)}😀.csv`;
353
const embedded = {
354
type: "resource",
355
resource: { uri: "file:///report.csv", mimeType: "text/csv", text: "a,b" },
@@ -364,7 +365,7 @@ describe("makeMcpAppHost", () => {
365
id: 3,
366
method: "ui/download-file",
367
params: {
367
- contents: [embedded, { type: "resource_link", uri: "ui://todos/export", name: "x" }],
368
+ contents: [embedded, { type: "resource_link", uri: "ui://todos/export", name: longName }],
369
},
370
});
371
host.receive({ jsonrpc: "2.0", id: 4, method: "ui/download-file", params: { contents: [{}] } });
@@ -380,6 +381,9 @@ describe("makeMcpAppHost", () => {
381
bytes: new TextEncoder().encode("a,b"),
382
},
383
]);
384
+ const capped = downloads[1]?.[1]?.name ?? "";
385
+ expect(capped.length).toBeLessThanOrEqual(200);
386
+ expect(capped.isWellFormed()).toBe(true);
387
expect(sent.find((m) => m.id === 2)?.result).toEqual({});
388
expect(sent.find((m) => m.id === 3)?.result).toEqual({ isError: true });
389
expect(sent.find((m) => m.id === 4)?.error).toMatchObject({ code: -32602 });
packages/client-runtime/src/mcpApps/host.ts
+7
-4
@@ -482,10 +482,13 @@ function downloadName(uri: unknown, name: unknown): string {
482
: typeof uri === "string"
483
? (uri.split(/[/?#]/).findLast(Boolean) ?? "download")
484
: "download";
485
- const safe = Array.from(raw, (char) =>
486
- /[\\/:*?"<>|]/.test(char) || char.charCodeAt(0) < 32 ? "-" : char,
487
- ).join("");
488
- return safe.slice(0, MAX_DOWNLOAD_NAME) || "download";
485
+ let safe = "";
486
+ for (const char of raw) {
487
+ const next = /[\\/:*?"<>|]/.test(char) || char.charCodeAt(0) < 32 ? "-" : char;
488
+ if (safe.length + next.length > MAX_DOWNLOAD_NAME) break;
489
+ safe += next;
490
+ }
491
+ return safe || "download";
492
}
493
494
function readDownloads(contents: unknown): ReadonlyArray<McpAppDownload> | undefined {