Skip to main content
Glama
safeRegisterTool.ts685 B
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js" import { ZodRawShape } from "zod" /** * Helper function to safely register a tool, catching "already registered" errors */ export const safeRegisterTool = ( server: McpServer, name: string, description: string, schema: ZodRawShape, handler: (args: any) => Promise<any> ) => { try { server.tool(name, description, schema, handler) return { success: true } } catch (error) { if ( error instanceof Error && error.message.includes("already registered") ) { return { success: false, reason: "already_registered" } } throw error // Re-throw any other errors } }

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/rajnandan1/pd-mcp'

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