Skip to main content
Glama
tool-registry.ts1.8 kB
/** * Tool registry for MCP server */ import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js"; import type { ToolContext } from "../tools/base-tool.js"; import { UploadFileTool } from "../tools/implementations/upload-file-tool.js"; import { UploadContentTool } from "../tools/implementations/upload-content-tool.js"; import { QueryTool } from "../tools/implementations/query-tool.js"; type Tool = | UploadFileTool | UploadContentTool | QueryTool; export class ToolRegistry { private registeredTools: string[] = []; private toolInstances = new Map<string, Tool>(); constructor(private server: McpServer) {} /** * Initialize tool registry by creating tool instances */ initialize(context: ToolContext): void { // Manual tool registration for safety and explicit review const tools: Tool[] = [ new UploadFileTool(context), new UploadContentTool(context), new QueryTool(context), ]; for (const tool of tools) { this.toolInstances.set(tool.name, tool); } console.log(`✅ ToolRegistry initialized with ${String(this.toolInstances.size)} tools`); } getToolByName(name: string): Tool | undefined { return this.toolInstances.get(name); } setupToolHandlers(): void { for (const tool of this.toolInstances.values()) { // Pass Zod schema directly to MCP SDK // SDK handles JSON Schema conversion internally for both stdio and HTTP transports this.server.registerTool( tool.name, { description: tool.description, inputSchema: tool.getInputSchema().shape, }, tool.handler.bind(tool) as never, ); this.registeredTools.push(tool.name); } } getRegisteredTools(): string[] { return this.registeredTools; } }

Implementation Reference

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/masseater/gemini-rag-mcp'

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