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

Function persistBlobToTextBlock

src/services/mcp/client.ts:2598–2627  ·  view source on GitHub ↗

* Decode base64 binary content, write it to disk with the proper extension, * and return a small text block with the file path. Replaces the old behavior * of dumping raw base64 into the context.

(
  bytes: Buffer,
  mimeType: string | undefined,
  serverName: string,
  sourceDescription: string,
)

Source from the content-addressed store, hash-verified

2596 * of dumping raw base64 into the context.
2597 */
2598async function persistBlobToTextBlock(
2599 bytes: Buffer,
2600 mimeType: string | undefined,
2601 serverName: string,
2602 sourceDescription: string,
2603): Promise<Array<ContentBlockParam>> {
2604 const persistId = `mcp-${normalizeNameForMCP(serverName)}-blob-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`
2605 const result = await persistBinaryContent(bytes, mimeType, persistId)
2606
2607 if ('error' in result) {
2608 return [
2609 {
2610 type: 'text',
2611 text: `${sourceDescription}Binary content (${mimeType || 'unknown type'}, ${bytes.length} bytes) could not be saved to disk: ${result.error}`,
2612 },
2613 ]
2614 }
2615
2616 return [
2617 {
2618 type: 'text',
2619 text: getBinaryBlobSavedMessage(
2620 result.filepath,
2621 mimeType,
2622 result.size,
2623 sourceDescription,
2624 ),
2625 },
2626 ]
2627}
2628
2629/**
2630 * Processes MCP tool result into a normalized format.

Callers 1

transformResultContentFunction · 0.85

Calls 4

normalizeNameForMCPFunction · 0.85
persistBinaryContentFunction · 0.85
toStringMethod · 0.65

Tested by

no test coverage detected