download_structure
Download protein structure coordinates from the Protein Data Bank in PDB, mmCIF, MMTF, or XML formats for analysis and visualization.
Instructions
Download structure coordinates in various formats
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| pdb_id | Yes | PDB ID (4-character code) | |
| format | No | File format (default: pdb) | |
| assembly_id | No | Biological assembly ID (optional) |
Implementation Reference
- src/index.ts:477-517 (handler)The handler function for the 'download_structure' tool. Validates input arguments, constructs the appropriate download URL for the PDB structure (handling formats like PDB, mmCIF, MMTF, XML and optional biological assemblies), fetches the file using axios, and returns the content wrapped in MCP tool response format.private async handleDownloadStructure(args: any) { if (!isValidDownloadArgs(args)) { throw new McpError(ErrorCode.InvalidParams, 'Invalid download structure arguments'); } try { const pdbId = args.pdb_id.toLowerCase(); const format = args.format || 'pdb'; const assemblyId = args.assembly_id; let url: string; if (assemblyId) { const extension = format === 'mmcif' ? 'cif' : format; url = `https://files.rcsb.org/download/${pdbId}-assembly${assemblyId}.${extension}`; } else { const extension = format === 'mmcif' ? 'cif' : format; url = `https://files.rcsb.org/download/${pdbId}.${extension}`; } const response = await axios.get(url); return { content: [ { type: 'text', text: `Structure file for ${args.pdb_id} (${format.toUpperCase()} format)${assemblyId ? ` - Assembly ${assemblyId}` : ''}:\n\n${response.data}`, }, ], }; } catch (error) { return { content: [ { type: 'text', text: `Error downloading structure: ${error instanceof Error ? error.message : 'Unknown error'}`, }, ], isError: true, }; } }
- src/index.ts:268-280 (registration)Registration of the 'download_structure' tool in the ListToolsRequestSchema response, including name, description, and JSON input schema definition.{ name: 'download_structure', description: 'Download structure coordinates in various formats', inputSchema: { type: 'object', properties: { pdb_id: { type: 'string', description: 'PDB ID (4-character code)' }, format: { type: 'string', enum: ['pdb', 'mmcif', 'mmtf', 'xml'], description: 'File format (default: pdb)' }, assembly_id: { type: 'string', description: 'Biological assembly ID (optional)' }, }, required: ['pdb_id'], }, },
- src/index.ts:51-63 (schema)Type guard function (input validation schema) specifically for 'download_structure' tool arguments, enforcing PDB ID format and allowed formats/assembly_id.const isValidDownloadArgs = ( args: any ): args is { pdb_id: string; format?: 'pdb' | 'mmcif' | 'mmtf' | 'xml'; assembly_id?: string } => { return ( typeof args === 'object' && args !== null && typeof args.pdb_id === 'string' && args.pdb_id.length === 4 && /^[0-9][a-zA-Z0-9]{3}$/i.test(args.pdb_id) && (args.format === undefined || ['pdb', 'mmcif', 'mmtf', 'xml'].includes(args.format)) && (args.assembly_id === undefined || typeof args.assembly_id === 'string') ); };
- src/index.ts:315-316 (registration)Dispatcher case in CallToolRequestSchema handler that routes 'download_structure' calls to the handleDownloadStructure method.case 'download_structure': return this.handleDownloadStructure(args);