get_file_url
Generate a secure, time-limited download URL for files stored in Supabase Storage buckets to enable controlled access to private files.
Instructions
Generate signed download URL for secure file access
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| bucket_name | Yes | Source bucket | |
| expires_in | No | URL expiration in seconds (default: 7200) | |
| storage_path | Yes | Full file path in storage |
Implementation Reference
- src/index.ts:762-803 (handler)The handler function that implements the core logic of the 'get_file_url' tool. It extracts parameters, generates a secure hash for auditing, creates a signed URL using Supabase storage API, handles errors, audits the request, and returns the signed URL with expiration and metadata.async function handleGetFileUrl(args: any, requestId: string, startTime: number) { const { bucket_name, storage_path, expires_in = 7200 } = args; const inputHash = generateSecureHash(JSON.stringify({ bucket_name, storage_path, expires_in })); try { const { data, error } = await supabase.storage .from(bucket_name) .createSignedUrl(storage_path, expires_in); if (error) { throw new Error(`Failed to create signed URL: ${error.message}`); } const expiresAt = new Date(Date.now() + expires_in * 1000).toISOString(); auditRequest('get_file_url', true, inputHash); const result: SignedUrlResult = { signedUrl: data.signedUrl, expiresAt, fileSize: 0, // Would need additional call to get file info mimeType: 'unknown' // Would need additional call to get file info }; return { content: [ { type: 'text', text: JSON.stringify({ ...result, request_id: requestId, processing_time: Date.now() - startTime }, null, 2) } ] }; } catch (error) { auditRequest('get_file_url', false, inputHash, getErrorMessage(error)); throw error; } }
- src/index.ts:205-233 (schema)The input schema and metadata definition for the 'get_file_url' tool, registered in the ListToolsRequestSchema handler. Defines parameters, validation rules, and description.{ name: 'get_file_url', description: 'Generate signed download URL for secure file access', inputSchema: { type: 'object', properties: { bucket_name: { type: 'string', description: 'Source bucket', minLength: 3, maxLength: 63 }, storage_path: { type: 'string', description: 'Full file path in storage', maxLength: 1024 }, expires_in: { type: 'number', description: 'URL expiration in seconds (default: 7200)', minimum: 60, maximum: 604800, default: 7200 } }, required: ['bucket_name', 'storage_path'], additionalProperties: false } },
- src/index.ts:476-477 (registration)The dispatch/registration point in the main CallToolRequestSchema handler switch statement that routes calls to the 'get_file_url' tool to its handler function.case 'get_file_url': return await handleGetFileUrl(args, requestId, startTime);