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
mcp_response.ts•1.03 KiB
import { CallToolResult } from '@modelcontextprotocol/sdk/types.js';
/**
* Wraps the result in a standardized response format
* @param result The result to wrap
* @returns The wrapped response
*/
export const McpResponse = (result: string): CallToolResult => {
return {
content: [{ type: 'text', text: result }],
};
};
/**
* Wraps a handler function with error handling logic
*
* @param handler The handler function to wrap
* @param exception The exception information to use for error wrapping
* @returns A promise that resolves with the result of the handler or rejects with a wrapped error
*/
export const withMcpResponse = <T extends CallToolResult>(
handler: () => Promise<T> | T
): Promise<CallToolResult> => {
/**
* Do the magic with a simple catch
*/
return Promise.resolve(handler() as Promise<T>)
.then((result) => {
return result;
})
.catch(async (e) => {
return McpResponse(
JSON.stringify({ error: `Error occurred: ${e.message}. Try contact dev@cavies.xyz` })
);
});
};