MCPcopy
hub / github.com/codeaashu/claude-code / tryUnwrapTextPayload

Function tryUnwrapTextPayload

src/tools/MCPTool/UI.tsx:327–362  ·  view source on GitHub ↗
(content: string)

Source from the content-addressed store, hash-verified

325 * pretty-printing keeps \n escaped but we want real line breaks + truncation.
326 */
327export function tryUnwrapTextPayload(content: string): {
328 body: string;
329 extras: [string, string][];
330} | null {
331 const entries = parseJsonEntries(content, {
332 maxChars: MAX_JSON_PARSE_CHARS,
333 maxKeys: 4
334 });
335 if (entries === null) return null;
336 // Find the one dominant string payload. Trim first: a trailing \n on a
337 // short sibling (e.g. pagination hints) shouldn't make it "dominant".
338 let body: string | null = null;
339 const extras: [string, string][] = [];
340 for (const [key, value] of entries) {
341 if (typeof value === 'string') {
342 const t = value.trimEnd();
343 const isDominant = t.length > UNWRAP_MIN_STRING_LEN || t.includes('\n') && t.length > 50;
344 if (isDominant) {
345 if (body !== null) return null; // two big strings — ambiguous
346 body = t;
347 continue;
348 }
349 if (t.length > 150) return null;
350 extras.push([key, t.replace(/\s+/g, ' ')]);
351 } else if (value === null || typeof value === 'number' || typeof value === 'boolean') {
352 extras.push([key, String(value)]);
353 } else {
354 return null; // nested object/array — use flat or pretty-print path
355 }
356 }
357 if (body === null) return null;
358 return {
359 body,
360 extras
361 };
362}
363const SLACK_ARCHIVES_RE = /^https:\/\/[a-z0-9-]+\.slack\.com\/archives\/([A-Z0-9]+)\/p\d+$/;
364
365/**

Callers 1

MCPTextOutputFunction · 0.85

Calls 2

parseJsonEntriesFunction · 0.85
pushMethod · 0.45

Tested by

no test coverage detected