Skip to content

Commit a8ca21b

Browse files
committed
fix(parallel): use truncateUtf16Safe for MCP error JSON truncation
The extractMcpToolPayload function and error messages use naive .slice(0, 500) on JSON-serialized errors and results which can split surrogate pairs. Replace with truncateUtf16Safe().
1 parent 9566ade commit a8ca21b

1 file changed

Lines changed: 6 additions & 3 deletions

File tree

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

Lines changed: 6 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,13 @@ 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(
159+
`Parallel MCP error: ${truncateUtf16Safe(JSON.stringify(envelope.error), 500)}`,
160+
);
158161
}
159162
const result = isRecord(envelope.result) ? envelope.result : {};
160163
if (result.isError) {
161-
throw new Error(`Parallel MCP tool error: ${JSON.stringify(result).slice(0, 500)}`);
164+
throw new Error(`Parallel MCP tool error: ${truncateUtf16Safe(JSON.stringify(result), 500)}`);
162165
}
163166
if (isRecord(result.structuredContent)) {
164167
return result.structuredContent;
@@ -177,7 +180,7 @@ export function extractMcpToolPayload(envelope: JsonRpcMessage): McpToolPayload
177180
}
178181
}
179182
throw new Error(
180-
`Parallel MCP returned no parseable content: ${JSON.stringify(result).slice(0, 500)}`,
183+
`Parallel MCP returned no parseable content: ${truncateUtf16Safe(JSON.stringify(result), 500)}`,
181184
);
182185
}
183186

0 commit comments

Comments
 (0)