batch_download
Download multiple protein structure files in bulk (PDB or CIF formats) using UniProt IDs, streamlining access to AlphaFold MCP Server data for efficient research workflows.
Instructions
Download multiple structure files
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| format | No | File format (default: pdb) | |
| uniprotIds | Yes | Array of UniProt accessions (max 20) |
Implementation Reference
- src/index.ts:1183-1244 (handler)The handler function that executes the batch_download tool. It validates input, loops over uniprotIds, fetches structure predictions from AlphaFold API, downloads the specified format file (PDB or CIF), and returns results with content or errors per ID.private async handleBatchDownload(args: any) { if (!isValidBatchArgs(args)) { throw new McpError(ErrorCode.InvalidParams, 'Invalid batch download arguments'); } try { const results = []; const format = args.format || 'pdb'; for (const uniprotId of args.uniprotIds) { try { const response = await this.apiClient.get(`/prediction/${uniprotId}`); const structures = response.data; if (structures && structures.length > 0) { const structure = structures[0]; const url = format === 'pdb' ? structure.pdbUrl : format === 'cif' ? structure.cifUrl : structure.pdbUrl; const fileResponse = await axios.get(url); results.push({ uniprotId, success: true, format, content: fileResponse.data, }); } else { results.push({ uniprotId, success: false, error: 'No structure found', }); } } catch (error) { results.push({ uniprotId, success: false, error: error instanceof Error ? error.message : 'Unknown error', }); } } return { content: [ { type: 'text', text: JSON.stringify({ batchDownloads: results }, null, 2), }, ], }; } catch (error) { return { content: [ { type: 'text', text: `Error in batch download: ${error instanceof Error ? error.message : 'Unknown error'}`, }, ], isError: true, }; } }
- src/index.ts:467-478 (schema)The input schema for the batch_download tool as registered in ListToolsRequestHandler, defining parameters uniprotIds (array 1-20) and optional format.{ name: 'batch_download', description: 'Download multiple structure files', inputSchema: { type: 'object', properties: { uniprotIds: { type: 'array', items: { type: 'string' }, description: 'Array of UniProt accessions (max 20)', minItems: 1, maxItems: 20 }, format: { type: 'string', enum: ['pdb', 'cif'], description: 'File format (default: pdb)' }, }, required: ['uniprotIds'], }, },
- src/index.ts:602-603 (registration)Dispatch case in CallToolRequestHandler switch statement that routes batch_download calls to the handleBatchDownload method.case 'batch_download': return this.handleBatchDownload(args);
- src/index.ts:83-95 (helper)Type guard and validation helper function for batch_download arguments, used in the handler to validate input before processing.const isValidBatchArgs = ( args: any ): args is { uniprotIds: string[]; format?: string } => { return ( typeof args === 'object' && args !== null && Array.isArray(args.uniprotIds) && args.uniprotIds.length > 0 && args.uniprotIds.length <= 50 && args.uniprotIds.every((id: any) => typeof id === 'string' && id.length > 0) && (args.format === undefined || ['pdb', 'cif', 'bcif', 'json'].includes(args.format)) ); };