Skip to main content
Glama
yone-k

MCP Base Server

by yone-k
tool-handler.ts1.03 kB
import { ErrorCode, McpError } from '@modelcontextprotocol/sdk/types.js'; export class ToolHandler { private validateAndParseInput<T>( args: unknown, schema: any, toolName: string ): T { try { return schema.parse(args || {}); } catch (error) { throw new McpError( ErrorCode.InvalidParams, `Invalid parameters for ${toolName}: ${error instanceof Error ? error.message : String(error)}` ); } } private formatResponse(result: any) { return { content: [ { type: 'text' as const, text: JSON.stringify(result, null, 2) } ] }; } async executeTool(name: string, args: unknown) { switch (name) { case 'example_tool': const result = { message: 'Hello from example tool!', timestamp: new Date().toISOString() }; return this.formatResponse(result); default: throw new McpError( ErrorCode.MethodNotFound, `Unknown tool: ${name}` ); } } }

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/yone-k/mcp-base'

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