Skip to main content
Glama
toolRegistration.ts1.48 kB
/** * Common tool registration utilities for the BSV MCP server */ import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js"; import type { z } from "zod"; export interface ToolConfig<TArgs = Record<string, unknown>> { name: string; description: string; schema: z.ZodSchema<TArgs>; handler: (args: TArgs) => Promise<ToolResponse>; } export interface ToolResponse { content: Array<{ type: "text"; text: string; }>; isError?: boolean; } /** * Register a tool with standard error handling and response formatting */ export function registerTool<TArgs = Record<string, unknown>>( server: McpServer, config: ToolConfig<TArgs>, ): void { server.tool(config.name, config.schema, async (args: TArgs) => { try { return await config.handler(args); } catch (error) { return { content: [ { type: "text" as const, text: `Error: ${error instanceof Error ? error.message : String(error)}`, }, ], isError: true, }; } }); } /** * Helper function to create a simple tool registration function */ export function createToolRegistration<TDeps = undefined>( toolName: string, description: string, schema: z.ZodSchema<Record<string, unknown>>, handler: ( args: Record<string, unknown>, deps?: TDeps, ) => Promise<ToolResponse>, ) { return (server: McpServer, deps?: TDeps) => { registerTool(server, { name: toolName, description, schema, handler: (args) => handler(args, deps), }); }; }

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/b-open-io/bsv-mcp'

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