Skip to main content
Glama

Toolkit MCP Server

errors.ts1.09 kB
import { ErrorCode } from '@modelcontextprotocol/sdk/types.js'; export class McpToolError extends Error { constructor( public code: ErrorCode, message: string, public data?: unknown ) { super(message); this.name = 'McpToolError'; } } export function handleToolError(error: unknown): { isError: true; content: Array<{ type: 'text'; text: string }>; } { if (error instanceof McpToolError) { return { isError: true, content: [{ type: 'text', text: `Error ${error.code}: ${error.message}${error.data ? `\nDetails: ${JSON.stringify(error.data)}` : ''}` }] }; } // Handle unknown errors return { isError: true, content: [{ type: 'text', text: `Internal error: ${error instanceof Error ? error.message : 'Unknown error'}` }] }; } export function validateInput<T>( input: unknown, validator: (input: unknown) => input is T, errorMessage: string ): T { if (!validator(input)) { throw new McpToolError( ErrorCode.InvalidParams, errorMessage ); } return input; }

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

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