Skip to content

Commit 8cb5d47

Browse files
committed
fix(parallel-mcp): use truncateUtf16Safe for error message truncation
Three .slice(0, 500) truncation sites in the Parallel MCP search extension may cut UTF-16 surrogate pairs in half when the error payload contains multi-byte characters such as emoji. Replace all with truncateUtf16Safe to keep the truncated output valid Unicode.
1 parent 3f2466c commit 8cb5d47

1 file changed

Lines changed: 4 additions & 3 deletions

File tree

extensions/parallel/src/parallel-mcp-search.runtime.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
} from "openclaw/plugin-sdk/provider-http";
88
import { withTrustedWebSearchEndpoint } from "openclaw/plugin-sdk/provider-web-search";
99
import { isRecord } from "openclaw/plugin-sdk/string-coerce-runtime";
10+
import { truncateUtf16Safe } from "openclaw/plugin-sdk/text-utility-runtime";
1011

1112
// Free hosted Search MCP. This keyless transport is used only after the user
1213
// explicitly selects the `parallel-free` web_search provider. Docs:
@@ -154,11 +155,11 @@ export function selectMcpEnvelope(text: string, requestId: string): JsonRpcMessa
154155
*/
155156
export function extractMcpToolPayload(envelope: JsonRpcMessage): McpToolPayload {
156157
if ("error" in envelope) {
157-
throw new Error(`Parallel MCP error: ${JSON.stringify(envelope.error).slice(0, 500)}`);
158+
throw new Error(`Parallel MCP error: ${truncateUtf16Safe(JSON.stringify(envelope.error), 500)}`);
158159
}
159160
const result = isRecord(envelope.result) ? envelope.result : {};
160161
if (result.isError) {
161-
throw new Error(`Parallel MCP tool error: ${JSON.stringify(result).slice(0, 500)}`);
162+
throw new Error(`Parallel MCP tool error: ${truncateUtf16Safe(JSON.stringify(result), 500)}`);
162163
}
163164
if (isRecord(result.structuredContent)) {
164165
return result.structuredContent;
@@ -177,7 +178,7 @@ export function extractMcpToolPayload(envelope: JsonRpcMessage): McpToolPayload
177178
}
178179
}
179180
throw new Error(
180-
`Parallel MCP returned no parseable content: ${JSON.stringify(result).slice(0, 500)}`,
181+
`Parallel MCP returned no parseable content: ${truncateUtf16Safe(JSON.stringify(result), 500)}`,
181182
);
182183
}
183184

0 commit comments

Comments
 (0)