lithtrix_blob_download
Retrieve blob bytes via blob ID. Returns JSON with base64-encoded content and content type.
Instructions
Download blob bytes (GET /v1/blobs/{blob_id}). Returns JSON with content_base64 and content_type. Requires LITHTRIX_API_KEY.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| blob_id | Yes | Content-addressed blob id (b_ + 16 hex chars) |
Implementation Reference
- tools/blobs.js:194-217 (registration)Registration of the lithtrix_blob_download tool on the MCP server using server.tool(). Calls blobDownloadResult() helper on success.
server.tool( "lithtrix_blob_download", "Download blob bytes (GET /v1/blobs/{blob_id}). Returns JSON with content_base64 and content_type. " + "Requires LITHTRIX_API_KEY.", { blob_id: blobIdSchema }, async ({ blob_id }) => { const apiKey = process.env.LITHTRIX_API_KEY; if (!apiKey) return missingApiKeyResponse(); const path = `/v1/blobs/${encodeURIComponent(blob_id)}`; let response; try { response = await fetch(new URL(path, LITHTRIX_API_URL), { headers: { Authorization: `Bearer ${apiKey}`, Accept: "*/*", }, }); } catch (err) { return networkErrorResponse(err); } return blobDownloadResult(response); } ); - tools/blobs.js:198-198 (schema)Input schema: blob_id (string, length 19, regex /^b_[0-9a-f]{16}$/) validated via blobIdSchema.
{ blob_id: blobIdSchema }, - tools/blobs.js:199-216 (handler)Handler function: checks LITHTRIX_API_KEY, GETs /v1/blobs/{blob_id}, returns blobDownloadResult(response).
async ({ blob_id }) => { const apiKey = process.env.LITHTRIX_API_KEY; if (!apiKey) return missingApiKeyResponse(); const path = `/v1/blobs/${encodeURIComponent(blob_id)}`; let response; try { response = await fetch(new URL(path, LITHTRIX_API_URL), { headers: { Authorization: `Bearer ${apiKey}`, Accept: "*/*", }, }); } catch (err) { return networkErrorResponse(err); } return blobDownloadResult(response); } - tools/blobs.js:75-117 (helper)Helper function blobDownloadResult() that reads the response as arrayBuffer, encodes to base64, extracts content-type, and returns JSON with content_base64, content_type, size_bytes.
async function blobDownloadResult(response) { if (!response.ok) { let body; try { body = await response.json(); } catch { body = {}; } return { content: [ { type: "text", text: JSON.stringify({ error: body.message ?? `Lithtrix API error (HTTP ${response.status})`, error_code: body.error_code ?? "UNKNOWN", status: body.status, }), }, ], isError: true, }; } const buf = await response.arrayBuffer(); const b64 = Buffer.from(buf).toString("base64"); const ct = response.headers.get("content-type") || "application/octet-stream"; return { content: [ { type: "text", text: JSON.stringify( { content_base64: b64, content_type: ct, size_bytes: buf.byteLength, }, null, 2 ), }, ], }; } - tools/blobs.js:10-14 (helper)blobIdSchema — Zod schema validating blob_id format (length 19, prefix b_ + 16 hex chars).
const blobIdSchema = z .string() .length(19) .regex(/^b_[0-9a-f]{16}$/) .describe("Content-addressed blob id (b_ + 16 hex chars)");