/**
* Central Tool Registry
*
* Consolidates all 60 MCP tools across 6 modules:
* - Auth Module (8 tools): Authentication and authorization operations
* - User Module (10 tools): User and permission management
* - Read Module (16 tools): Read-only data retrieval
* - Write Module (8 tools): Create, update, delete operations
* - Execute Module (9 tools): Action execution and lifecycle management
* - Terminal Module (9 tools): Terminal session and command execution
*
* Total: 60 tools
*/
import type { Tool } from '@modelcontextprotocol/sdk/types.js';
import { createLogger } from './utils/logger.js';
// Module imports (will be created)
import { authTools } from './tools/auth.js';
import { userTools } from './tools/user.js';
import { allReadTools } from './tools/read-tools.js';
import { writeTools } from './tools/write.js';
import { executeTools } from './tools/execute/index.js';
import { terminalTools } from './tools/terminal.js';
const logger = createLogger('registry');
/**
* Tool registry with metadata for each module
*/
export interface ModuleRegistration {
name: string;
description: string;
tools: Tool[];
requiredAuth: boolean;
category: 'auth' | 'user' | 'read' | 'write' | 'execute' | 'terminal';
}
/**
* All module registrations
*/
export const MODULE_REGISTRATIONS: ModuleRegistration[] = [
{
name: 'auth',
description: 'Authentication and authorization operations',
tools: authTools,
requiredAuth: false, // Auth tools themselves don't require auth
category: 'auth',
},
{
name: 'user',
description: 'User and permission management',
tools: userTools,
requiredAuth: true,
category: 'user',
},
{
name: 'read',
description: 'Read-only data retrieval operations',
tools: allReadTools,
requiredAuth: true,
category: 'read',
},
{
name: 'write',
description: 'Create, update, and delete operations',
tools: writeTools,
requiredAuth: true,
category: 'write',
},
{
name: 'execute',
description: 'Action execution and resource lifecycle management',
tools: executeTools,
requiredAuth: true,
category: 'execute',
},
{
name: 'terminal',
description: 'Terminal session and command execution',
tools: terminalTools,
requiredAuth: true,
category: 'terminal',
},
];
/**
* Central tool registry
*/
export class ToolRegistry {
private tools: Map<string, Tool> = new Map();
private moduleMap: Map<string, ModuleRegistration> = new Map();
private authRequiredTools: Set<string> = new Set();
constructor() {
this.registerAllModules();
}
/**
* Register all modules and their tools
*/
private registerAllModules(): void {
logger.info('Registering all modules');
for (const module of MODULE_REGISTRATIONS) {
this.registerModule(module);
}
logger.info('Tool registration complete', {
totalModules: MODULE_REGISTRATIONS.length,
totalTools: this.tools.size,
authRequiredTools: this.authRequiredTools.size,
});
}
/**
* Register a single module
*/
private registerModule(module: ModuleRegistration): void {
logger.debug(`Registering module: ${module.name}`, {
toolCount: module.tools.length,
requiredAuth: module.requiredAuth,
});
this.moduleMap.set(module.name, module);
for (const tool of module.tools) {
if (this.tools.has(tool.name)) {
logger.warn(`Duplicate tool name detected: ${tool.name}`);
continue;
}
this.tools.set(tool.name, tool);
if (module.requiredAuth) {
this.authRequiredTools.add(tool.name);
}
}
}
/**
* Get all registered tools
*/
getAllTools(): Tool[] {
return Array.from(this.tools.values());
}
/**
* Get a specific tool by name
*/
getTool(name: string): Tool | undefined {
return this.tools.get(name);
}
/**
* Check if a tool requires authentication
*/
requiresAuth(toolName: string): boolean {
return this.authRequiredTools.has(toolName);
}
/**
* Get all tools for a specific module
*/
getModuleTools(moduleName: string): Tool[] {
const module = this.moduleMap.get(moduleName);
return module?.tools ?? [];
}
/**
* Get module metadata
*/
getModule(moduleName: string): ModuleRegistration | undefined {
return this.moduleMap.get(moduleName);
}
/**
* Get all module names
*/
getModuleNames(): string[] {
return Array.from(this.moduleMap.keys());
}
/**
* Get tools by category
*/
getToolsByCategory(category: ModuleRegistration['category']): Tool[] {
const modules = Array.from(this.moduleMap.values()).filter(
(m) => m.category === category
);
return modules.flatMap((m) => m.tools);
}
/**
* Validate registry integrity
*/
validate(): { valid: boolean; errors: string[] } {
const errors: string[] = [];
// Check for expected module count
if (this.moduleMap.size !== 6) {
errors.push(`Expected 6 modules, found ${this.moduleMap.size}`);
}
// Check for expected tool count
if (this.tools.size !== 60) {
errors.push(`Expected 60 tools, found ${this.tools.size}`);
}
// Check for duplicate tool names
const toolNames = Array.from(this.tools.keys());
const uniqueNames = new Set(toolNames);
if (toolNames.length !== uniqueNames.size) {
errors.push('Duplicate tool names detected');
}
// Check that each module has tools
for (const [name, module] of this.moduleMap) {
if (module.tools.length === 0) {
errors.push(`Module ${name} has no tools`);
}
}
return {
valid: errors.length === 0,
errors,
};
}
/**
* Get registry statistics
*/
getStats(): Record<string, unknown> {
const stats: Record<string, number> = {
totalModules: this.moduleMap.size,
totalTools: this.tools.size,
authRequiredTools: this.authRequiredTools.size,
};
for (const module of MODULE_REGISTRATIONS) {
stats[`${module.name}Tools`] = module.tools.length;
}
return stats;
}
}
/**
* Singleton registry instance
*/
export const registry = new ToolRegistry();