generate_presigned_url
Create time-limited URLs for secure access to MinIO storage objects without authentication, enabling temporary sharing or uploads.
Instructions
生成预签名URL
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| bucketName | Yes | 存储桶名称 | |
| objectName | Yes | 对象名称 | |
| method | No | HTTP方法 | GET |
| expires | No | 过期时间(秒) |
Implementation Reference
- src/index.ts:522-539 (handler)Handler for the 'generate_presigned_url' tool that validates input parameters using Zod, calls the MinIO client's generatePresignedUrl method, and formats the response with the generated URL.case 'generate_presigned_url': { const { bucketName, objectName, method, expires } = z.object({ bucketName: z.string(), objectName: z.string(), method: z.enum(['GET', 'PUT', 'DELETE']).default('GET'), expires: z.number().default(3600) }).parse(args); const url = await this.minioClient.generatePresignedUrl(bucketName, objectName, method, { expires }); return { content: [ { type: 'text', text: `预签名URL (${method}, 有效期${expires}秒):\n${url}` } ] }; }
- src/index.ts:212-225 (registration)Registration of the 'generate_presigned_url' tool in the MCP server, including name, description, and input schema definition.{ name: 'generate_presigned_url', description: '生成预签名URL', inputSchema: { type: 'object', properties: { bucketName: { type: 'string', description: '存储桶名称' }, objectName: { type: 'string', description: '对象名称' }, method: { type: 'string', enum: ['GET', 'PUT', 'DELETE'], description: 'HTTP方法', default: 'GET' }, expires: { type: 'number', description: '过期时间(秒)', default: 3600 } }, required: ['bucketName', 'objectName'] } },
- src/minio-client.ts:215-230 (helper)Helper method in MinIOStorageClient that implements the presigned URL generation logic using the MinIO SDK's presigned methods for GET, PUT, and DELETE.async generatePresignedUrl(bucketName: string, objectName: string, method: 'GET' | 'PUT' | 'DELETE' = 'GET', options?: PresignedUrlOptions): Promise<string> { this.ensureConnected(); const expires = options?.expires || 3600; // 默认1小时 switch (method) { case 'GET': return await this.client!.presignedGetObject(bucketName, objectName, expires, options?.reqParams, options?.requestDate); case 'PUT': return await this.client!.presignedPutObject(bucketName, objectName, expires); case 'DELETE': return await this.client!.presignedUrl('DELETE', bucketName, objectName, expires, options?.reqParams, options?.requestDate); default: throw new Error(`不支持的HTTP方法: ${method}`); } }