Skip to main content
Glama
resource-helpers.ts1.56 kB
/** * Resource helper utilities for MCP resources */ /** * Create a JSON response for MCP resources * * @param data Data to serialize as JSON * @param uri Optional URI for the resource * @returns MCP resource response object */ export function createJsonResponse(data: any, uri?: string) { return { contents: [{ uri: uri || "data:application/json", mimeType: "application/json", text: JSON.stringify(data, null, 2) }] }; } /** * Create a binary response for MCP resources * * @param data Binary data (Buffer or base64 string) * @param mimeType MIME type of the binary data * @param uri Optional URI for the resource * @returns MCP resource response object */ export function createBinaryResponse(data: Buffer | string, mimeType: string, uri?: string) { const blob = typeof data === 'string' ? data : data.toString('base64'); return { contents: [{ uri: uri || `data:${mimeType}`, mimeType: mimeType, blob: blob }] }; } /** * Create an error response for MCP resources * * @param error Error message * @param details Optional error details * @param uri Optional URI for the resource * @returns MCP resource error response */ export function createErrorResponse(error: string, details?: string, uri?: string) { return { contents: [{ uri: uri || "data:application/json", mimeType: "application/json", text: JSON.stringify({ error, details }, null, 2) }] }; }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/mixelpixx/KiCAD-MCP-Server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server