Skip to main content
Glama
toolResult.mjs1.02 kB
// Formats tool results into MCP response shapes with optional structured content. function normalizeStructuredContent(data) { if (data === undefined || data === null) { return undefined; } if (Array.isArray(data)) { return { items: data }; } if (typeof data === "object") { return data; } return { value: data }; } export function toolResult(data, options = {}) { const structured = normalizeStructuredContent(data); let text = options.text; if (text === undefined) { if (structured !== undefined) { try { text = JSON.stringify(structured); } catch (error) { text = String(structured); } } else if (data !== undefined) { text = String(data); } else { text = ""; } } const result = { content: [{ type: "text", text }], }; if (structured !== undefined) { result.structuredContent = structured; } if (data && typeof data === "object" && data.error) { result.isError = true; } return result; }

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/jahzlariosa/wordpress-mcp'

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