class ToolRegistryImpl {
  constructor() {
    this.tools = /* @__PURE__ */ new Map();
    this.moduleMap = /* @__PURE__ */ new Map();
  }
  registerTool(tool, options) {
    if (!tool?.name) {
      throw new Error("MCP tool must define a name");
    }
    if (this.tools.has(tool.name)) {
      console.warn(`[McpToolRegistry] Tool "${tool.name}" already registered, overwriting`);
    }
    this.tools.set(tool.name, tool);
    if (options?.moduleId) {
      const existing = this.moduleMap.get(options.moduleId) ?? [];
      if (!existing.includes(tool.name)) {
        existing.push(tool.name);
      }
      this.moduleMap.set(options.moduleId, existing);
    }
  }
  getTools() {
    return new Map(this.tools);
  }
  getTool(name) {
    return this.tools.get(name);
  }
  listToolNames() {
    return Array.from(this.tools.keys());
  }
  listToolsByModule(moduleId) {
    return this.moduleMap.get(moduleId) ?? [];
  }
  unregisterTool(name) {
    this.tools.delete(name);
    for (const [moduleId, tools] of this.moduleMap.entries()) {
      const index = tools.indexOf(name);
      if (index !== -1) {
        tools.splice(index, 1);
        this.moduleMap.set(moduleId, tools);
      }
    }
  }
  clear() {
    this.tools.clear();
    this.moduleMap.clear();
  }
}
const toolRegistry = new ToolRegistryImpl();
function registerMcpTool(tool, options) {
  toolRegistry.registerTool(tool, options);
}
function getToolRegistry() {
  return toolRegistry;
}
function unregisterMcpTool(name) {
  toolRegistry.unregisterTool(name);
}
export {
  getToolRegistry,
  registerMcpTool,
  toolRegistry,
  unregisterMcpTool
};
//# sourceMappingURL=tool-registry.js.map
