UNPKG

@andrewlwn77/s3-upload-mcp-server

Version:

Pure Node.js MCP server for uploading images to AWS S3 with high-performance validation using Sharp and file-type

57 lines 2.19 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ConfigManager = void 0; class ConfigManager { constructor() { this.config = this.loadConfig(); } static getInstance() { if (!ConfigManager.instance) { ConfigManager.instance = new ConfigManager(); } return ConfigManager.instance; } loadConfig() { const accessKeyId = process.env.AWS_ACCESS_KEY_ID; const secretAccessKey = process.env.AWS_SECRET_ACCESS_KEY; const region = process.env.AWS_DEFAULT_REGION || 'us-east-1'; const defaultBucket = process.env.S3_BUCKET_NAME; if (!accessKeyId || !secretAccessKey) { throw new Error('AWS credentials not found. Please set AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY environment variables.'); } return { accessKeyId, secretAccessKey, region, defaultBucket }; } getConfig() { return { ...this.config }; } getDefaultBucket() { return this.config.defaultBucket; } validateBucket(bucket) { const bucketName = bucket || this.config.defaultBucket; if (!bucketName) { throw new Error('No bucket specified. Provide bucket parameter or set S3_BUCKET_NAME environment variable.'); } // Validate bucket naming rules if (bucketName.length < 3 || bucketName.length > 63) { throw new Error('Bucket name must be between 3 and 63 characters long'); } const bucketNamePattern = /^[a-z0-9][a-z0-9.-]*[a-z0-9]$/; if (!bucketNamePattern.test(bucketName)) { throw new Error('Bucket name must start and end with alphanumeric character, contain only lowercase letters, numbers, dots, and hyphens'); } // Check if formatted as IP address const ipPattern = /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/; if (ipPattern.test(bucketName)) { throw new Error('Bucket name cannot be formatted as an IP address'); } return bucketName; } } exports.ConfigManager = ConfigManager; //# sourceMappingURL=config.js.map