ucm-mcp-server
Version:
Universal Context Manager MCP Server - AI-native artifact management
105 lines • 5.52 kB
JavaScript
import { McpError, McpErrorCode } from '../utils/McpErrorHandler.js';
// Import utility tools
import { HealthCheckController } from '../tools/utility/HealthCheckController.js';
import { QuickstartTool } from '../tools/utility/QuickstartTool.js';
import { AuthorIndexTool } from '../tools/utility/AuthorIndexTool.js';
import { AuthorRecentsTool } from '../tools/utility/AuthorRecentsTool.js';
import { ListRepositoriesTool } from '../tools/utility/ListRepositoriesTool.js';
import { SubmitFeedbackTool } from '../tools/utility/SubmitFeedbackTool.js';
// Import core tools
import { GetArtifactTool } from '../tools/core/GetArtifactTool.js';
import { GetChunkTool } from '../tools/core/GetChunkTool.js';
import { PublishArtifactTool } from '../tools/core/PublishArtifactTool.js';
import { PublishArtifactFromFileTool } from '../tools/core/PublishArtifactFromFileTool.js';
import { ListArtifactsTool } from '../tools/core/ListArtifactsTool.js';
import { DeleteArtifactTool } from '../tools/core/DeleteArtifactTool.js';
import { GetArtifactVersionsTool } from '../tools/core/GetArtifactVersionsTool.js';
import { SearchArtifactsTool } from '../tools/core/SearchArtifactsTool.js';
import { EditArtifactMetadataTool } from '../tools/core/EditArtifactMetadataTool.js';
// Import repository tools
import { CreateRepositoryTool } from '../tools/repository/CreateRepositoryTool.js';
import { GetRepositoryTool } from '../tools/repository/GetRepositoryTool.js';
import { UpdateRepositoryTool } from '../tools/repository/UpdateRepositoryTool.js';
import { DeleteRepositoryGuidanceTool } from '../tools/repository/DeleteRepositoryGuidanceTool.js';
export class ToolRegistry {
ucmClient;
logger;
trustedAuthors;
authorId;
baseUrl;
tools = new Map();
constructor(ucmClient, logger, trustedAuthors = [], authorId, baseUrl) {
this.ucmClient = ucmClient;
this.logger = logger;
this.trustedAuthors = trustedAuthors;
this.authorId = authorId;
this.baseUrl = baseUrl;
this.registerTools();
}
registerTools() {
// Register utility tools
this.registerTool(new QuickstartTool(this.ucmClient, this.logger, this.authorId));
this.registerTool(new HealthCheckController(this.ucmClient, this.logger, this.authorId));
this.registerTool(new AuthorIndexTool(this.ucmClient, this.logger, this.authorId));
this.registerTool(new AuthorRecentsTool(this.ucmClient, this.logger, this.authorId));
this.registerTool(new ListRepositoriesTool(this.ucmClient, this.logger, this.authorId));
this.registerTool(new SubmitFeedbackTool(this.ucmClient, this.logger, this.authorId));
// Register core tools
this.registerTool(new GetArtifactTool(this.ucmClient, this.logger, this.authorId, this.trustedAuthors));
this.registerTool(new GetChunkTool(this.ucmClient, this.logger, this.authorId));
this.registerTool(new PublishArtifactFromFileTool(this.ucmClient, this.logger, this.authorId));
this.registerTool(new PublishArtifactTool(this.ucmClient, this.logger, this.authorId));
this.registerTool(new ListArtifactsTool(this.ucmClient, this.logger, this.authorId));
this.registerTool(new DeleteArtifactTool(this.ucmClient, this.logger, this.authorId));
this.registerTool(new GetArtifactVersionsTool(this.ucmClient, this.logger, this.authorId));
this.registerTool(new SearchArtifactsTool(this.ucmClient, this.logger, this.authorId));
this.registerTool(new EditArtifactMetadataTool(this.ucmClient, this.logger, this.authorId));
// Register repository tools
this.registerTool(new CreateRepositoryTool(this.ucmClient, this.logger, this.authorId));
this.registerTool(new GetRepositoryTool(this.ucmClient, this.logger, this.authorId));
this.registerTool(new UpdateRepositoryTool(this.ucmClient, this.logger, this.authorId));
this.registerTool(new DeleteRepositoryGuidanceTool(this.ucmClient, this.logger, this.authorId, this.baseUrl));
this.logger.info('ToolRegistry', `Registered ${this.tools.size} MCP tools`);
}
registerTool(tool) {
if (this.tools.has(tool.name)) {
this.logger.warn('ToolRegistry', `Tool ${tool.name} already registered, overwriting`);
}
this.tools.set(tool.name, tool);
this.logger.debug('ToolRegistry', `Registered tool: ${tool.name}`);
}
async listTools() {
const toolList = [];
for (const [, tool] of this.tools) {
toolList.push({
name: tool.name,
description: tool.description,
inputSchema: tool.inputSchema
});
}
return toolList;
}
async executeTool(name, params) {
const tool = this.tools.get(name);
if (!tool) {
throw new McpError(McpErrorCode.MethodNotFound, `Tool '${name}' not found`);
}
this.logger.debug('ToolRegistry', `Executing tool: ${name}`);
try {
const result = await tool.execute(params);
this.logger.debug('ToolRegistry', `Tool ${name} completed successfully`);
return result;
}
catch (error) {
this.logger.error('ToolRegistry', `Tool ${name} execution failed`, '', error);
throw error;
}
}
getToolCount() {
return this.tools.size;
}
hasToolnamed(name) {
return this.tools.has(name);
}
}
//# sourceMappingURL=ToolRegistry.js.map