@utaba/ucm-mcp-server
Version:
Universal Context Manager MCP Server - AI-native artifact management
50 lines • 2.24 kB
JavaScript
import { McpError, McpErrorCode } from './McpErrorHandler.js';
export class ValidationUtils {
static validateArtifactPath(path) {
// Prevent path traversal
if (path.includes('..') || path.includes('//')) {
throw new McpError(McpErrorCode.InvalidParams, 'Invalid artifact path');
}
}
static sanitizeSearchQuery(query) {
// Remove potentially dangerous characters
return query.replace(/[<>\"'&]/g, '').trim();
}
static validateContentSize(content, maxSize = 1024 * 1024) {
if (content.length > maxSize) {
throw new McpError(McpErrorCode.InvalidParams, 'Content size exceeds maximum allowed');
}
}
static validatePageParams(offset = 0, limit = 20) {
if (offset < 0) {
throw new McpError(McpErrorCode.InvalidParams, 'Offset must be non-negative');
}
if (limit < 1 || limit > 100) {
throw new McpError(McpErrorCode.InvalidParams, 'Limit must be between 1 and 100');
}
}
static validateAuthorId(authorId) {
if (!authorId || typeof authorId !== 'string') {
throw new McpError(McpErrorCode.InvalidParams, 'Author ID is required and must be a string');
}
// Basic validation - alphanumeric, hyphens, underscores
const authorRegex = /^[a-zA-Z0-9\-_]+$/;
if (!authorRegex.test(authorId)) {
throw new McpError(McpErrorCode.InvalidParams, 'Author ID contains invalid characters');
}
}
static validateCategory(category) {
const validCategories = ['commands', 'services', 'patterns', 'implementations', 'contracts', 'guidance'];
if (!validCategories.includes(category)) {
throw new McpError(McpErrorCode.InvalidParams, `Invalid category. Must be one of: ${validCategories.join(', ')}`);
}
}
static validateVersion(version) {
// Semantic version validation
const versionRegex = /^[0-9]+\.[0-9]+\.[0-9]+(?:-[a-zA-Z0-9\-_]+)?$/;
if (!versionRegex.test(version)) {
throw new McpError(McpErrorCode.InvalidParams, 'Version must follow semantic versioning format');
}
}
}
//# sourceMappingURL=ValidationUtils.js.map