@utaba/ucm-mcp-server
Version:
Universal Context Manager MCP Server - AI Productivity Platform
85 lines • 4.49 kB
JavaScript
import { BaseToolController } from '../base/BaseToolController.js';
import { McpError, McpErrorCode } from '../../utils/McpErrorHandler.js';
export class GetRepositoryTool extends BaseToolController {
constructor(ucmClient, logger, publishingAuthorId) {
super(ucmClient, logger, publishingAuthorId);
}
get name() {
return 'ucm_get_repository';
}
get description() {
const authorInfo = this.publishingAuthorId ? ` Your author id is '${this.publishingAuthorId}'.` : '';
return `Get detailed information about a specific repository, including metadata, statistics, and available categories. Returns repository details along with its content structure.${authorInfo}`;
}
get inputSchema() {
return {
type: 'object',
properties: {
author: {
type: 'string',
description: this.publishingAuthorId ? `Author identifier: ${this.publishingAuthorId}` : 'Author identifier (e.g., "utaba", "1064600359")',
minLength: 1,
maxLength: 50
},
repository: {
type: 'string',
description: 'Repository name (e.g., "main", "project-alpha")',
minLength: 1,
maxLength: 200
}
},
required: ['author', 'repository'],
additionalProperties: false
};
}
validateParams(params) {
super.validateParams(params);
if (!params.author || typeof params.author !== 'string' || params.author.trim() === '') {
throw new McpError(McpErrorCode.InvalidParams, 'Author identifier is required and cannot be empty');
}
if (!params.repository || typeof params.repository !== 'string' || params.repository.trim() === '') {
throw new McpError(McpErrorCode.InvalidParams, 'Repository name is required and cannot be empty');
}
}
async handleExecute(params) {
this.logger.info('GetRepositoryTool', `Getting repository ${params.repository} for author ${params.author}`);
try {
const result = await this.ucmClient.getRepository(params.author, params.repository);
this.logger.info('GetRepositoryTool', `Repository retrieved successfully: ${params.repository}`);
// Enhance the response with additional helpful information
const enhancedResult = {
success: true,
message: `Repository '${params.repository}' retrieved successfully for author '${params.author}'`,
repository: result,
webUrl: `${process.env.NEXT_PUBLIC_BASE_URL || 'http://localhost:3000'}/browse/${params.author}/${params.repository}`,
apiEndpoints: {
browse: `/api/v1/authors/${params.author}/${params.repository}`,
artifacts: `/api/v1/authors/${params.author}/${params.repository}/{category}/{subcategory}`,
files: `/api/v1/files/${params.author}/${params.repository}/{category}/{subcategory}/{filename}`
}
};
return {
content: [
{
type: 'text',
text: JSON.stringify(enhancedResult, null, 2)
}
]
};
}
catch (error) {
this.logger.error('GetRepositoryTool', 'Failed to get repository', '', error);
const errorMessage = error instanceof Error ? error.message : 'Unknown error occurred';
// Handle specific error cases
if (errorMessage.includes('not found') || errorMessage.includes('404')) {
throw new McpError(McpErrorCode.InvalidParams, `Repository '${params.repository}' not found for author '${params.author}'. Please verify the repository name and author identifier.`);
}
if (errorMessage.includes('403') || errorMessage.includes('Forbidden')) {
throw new McpError(McpErrorCode.InvalidParams, `Access denied to repository '${params.repository}' for author '${params.author}'. You may not have permission to view this repository.`);
}
// Generic error
throw new McpError(McpErrorCode.InternalError, `Failed to retrieve repository: ${errorMessage}`);
}
}
}
//# sourceMappingURL=GetRepositoryTool.js.map