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

Function persistBinaryContent

src/utils/mcpOutputStorage.ts:148–174  ·  view source on GitHub ↗
(
  bytes: Buffer,
  mimeType: string | undefined,
  persistId: string,
)

Source from the content-addressed store, hash-verified

146 * for PDFs, pandas for xlsx, etc.).
147 */
148export async function persistBinaryContent(
149 bytes: Buffer,
150 mimeType: string | undefined,
151 persistId: string,
152): Promise<PersistBinaryResult> {
153 await ensureToolResultsDir()
154 const ext = extensionForMimeType(mimeType)
155 const filepath = join(getToolResultsDir(), `${persistId}.${ext}`)
156
157 try {
158 await writeFile(filepath, bytes)
159 } catch (error) {
160 const err = toError(error)
161 logError(err)
162 return { error: err.message }
163 }
164
165 // mime type and extension are safe fixed-vocabulary strings (not paths/code)
166 logEvent('tengu_binary_content_persisted', {
167 mimeType: (mimeType ??
168 'unknown') as AnalyticsMetadata_I_VERIFIED_THIS_IS_NOT_CODE_OR_FILEPATHS,
169 sizeBytes: bytes.length,
170 ext: ext as AnalyticsMetadata_I_VERIFIED_THIS_IS_NOT_CODE_OR_FILEPATHS,
171 })
172
173 return { filepath, size: bytes.length, ext }
174}
175
176/**
177 * Build a short message telling Claude where binary content was saved.

Callers 3

callFunction · 0.85
getURLMarkdownContentFunction · 0.85
persistBlobToTextBlockFunction · 0.85

Calls 6

ensureToolResultsDirFunction · 0.85
extensionForMimeTypeFunction · 0.85
getToolResultsDirFunction · 0.85
toErrorFunction · 0.85
logEventFunction · 0.85
logErrorFunction · 0.70

Tested by

no test coverage detected