Skip to main content
Glama
response.ts927 B
export function parseToolResponse(response: any): any { // If no response or it's a primitive, return as is if (!response || typeof response !== 'object') return response; // Check for content array with text items if (response.content && Array.isArray(response.content)) { const textContent = response.content.find( (item: { type: string; text?: string }) => item.type === 'text' )?.text; if (textContent) { // Check if it's an error message first - only if it starts with 'Error:' if (textContent.startsWith('Error:')) { return { error: textContent }; } try { return JSON.parse(textContent); } catch (e) { // Don't warn on expected error messages if (!textContent.startsWith('Error:')) { console.warn('Failed to parse text content as JSON:', e); } return textContent; } } } return response; }

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/KuchikiRenji/mcp-server'

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