Skip to main content
Glama
response.util.ts1.75 kB
/** * Utility for formatting MCP tool responses * Provides consistent response structure for all tools */ export interface McpResponse { content: Array<{ type: 'text'; text: string; }>; } export interface SuccessResponseData { success: true; message?: string; data?: any; pagination?: Record<string, any>; } export interface ErrorResponseData { success: false; error: string; } type ResponseData = SuccessResponseData | ErrorResponseData; export class ResponseUtil { /** * Format a successful response for MCP * @param message - Success message to display * @param data - Response data to include * @param pagination - Optional pagination info */ static success( message: string, data?: any, pagination?: Record<string, any>, ): McpResponse { const response: SuccessResponseData = { success: true, message, }; if (data !== undefined) { response.data = data; } if (pagination !== undefined) { response.pagination = pagination; } return { content: [ { type: 'text' as const, text: JSON.stringify(response, null, 2), }, ], }; } /** * Format an error response for MCP * @param error - Error message to display */ static error(error: string): McpResponse { const response: ErrorResponseData = { success: false, error, }; return { content: [ { type: 'text' as const, text: JSON.stringify(response, null, 2), }, ], }; } /** * Format unauthenticated response */ static unauthenticated(): McpResponse { return this.error('User not authenticated. Please login first.'); } }

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/arshad-khan1/Timesheet-mcp'

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