Skip to main content
Glama
Seitrace

Seitrace Insights MCP Server

Official
by Seitrace
format_api_error.ts1.68 kB
import { CallToolResult } from '@modelcontextprotocol/sdk/types.js'; import axios from 'axios'; import { McpResponse } from './index.js'; /** * Formats API errors for better readability * * @param error Axios error * @returns Formatted error message */ export function formatApiError(error: any): CallToolResult { let message = 'API request failed.'; if (error.response) { message = `API Error: Status ${error.response.status} (${ error.response.statusText || 'Status text not available' }). `; const responseData = error.response.data; const MAX_LEN = 200; if (typeof responseData === 'string') { message += `Response: ${responseData.substring(0, MAX_LEN)}${ responseData.length > MAX_LEN ? '...' : '' }`; } else if (responseData) { try { const jsonString = JSON.stringify(responseData); message += `Response: ${jsonString.substring(0, MAX_LEN)}${ jsonString.length > MAX_LEN ? '...' : '' }`; } catch { message += 'Response: [Could not serialize data]'; } } else { message += 'No response body received.'; } } else if (error.request) { message = 'API Network Error: No response received from server.'; if (error.code) message += ` (Code: ${error.code})`; } else { message += `API Request Setup Error: ${error.message}`; } let errorMessage: string; if (axios.isAxiosError(error)) { errorMessage = message; } else if (error instanceof Error) { errorMessage = error.message; } else { errorMessage = 'Unexpected error: ' + String(error); } return McpResponse(JSON.stringify({ error: errorMessage })); }

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/Seitrace/seitrace-mcp'

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