export_chemicals
Export chemical patent data in CSV or XML format using SureChEMBL chemical IDs. Process up to 100 chemical records per request to retrieve structured data from the patent database.
Instructions
Bulk export chemical data in CSV or XML format
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| chemical_ids | Yes | Array of SureChEMBL chemical IDs (1-100) | |
| output_type | No | Export format (default: csv) | |
| kind | No | ID type for export (default: cid) |
Implementation Reference
- src/index.ts:897-939 (handler)The handler function for the 'export_chemicals' tool. Validates input arguments using isValidExportArgs, constructs API parameters, calls the SureChEMBL /export/chemistry endpoint to fetch binary export data, encodes it as base64, and returns it embedded in a JSON response.private async handleExportChemicals(args: any) { if (!isValidExportArgs(args)) { throw new McpError(ErrorCode.InvalidParams, 'Invalid export arguments'); } try { const chemIDs = args.chemical_ids.join(','); const outputType = args.output_type || 'csv'; const kind = args.kind || 'cid'; const response = await this.apiClient.get('/export/chemistry', { params: { chemIDs: chemIDs, output_type: outputType, kind: kind }, responseType: 'arraybuffer' }); // Convert binary data to base64 for JSON response const base64Data = Buffer.from(response.data).toString('base64'); return { content: [ { type: 'text', text: JSON.stringify({ chemical_ids: args.chemical_ids, output_type: outputType, kind: kind, export_data: `data:application/zip;base64,${base64Data}`, message: `Successfully exported ${args.chemical_ids.length} chemicals in ${outputType} format` }, null, 2), }, ], }; } catch (error) { throw new McpError( ErrorCode.InternalError, `Failed to export chemicals: ${error instanceof Error ? error.message : 'Unknown error'}` ); } }
- src/index.ts:460-486 (schema)The input schema definition for the 'export_chemicals' tool, registered in the ListTools response. Specifies properties for chemical_ids (array 1-100), output_type (csv/xml), and kind (cid/smiles).{ name: 'export_chemicals', description: 'Bulk export chemical data in CSV or XML format', inputSchema: { type: 'object', properties: { chemical_ids: { type: 'array', items: { type: 'string' }, description: 'Array of SureChEMBL chemical IDs (1-100)', minItems: 1, maxItems: 100 }, output_type: { type: 'string', enum: ['csv', 'xml'], description: 'Export format (default: csv)' }, kind: { type: 'string', enum: ['cid', 'smiles'], description: 'ID type for export (default: cid)' }, }, required: ['chemical_ids'], }, },
- src/index.ts:567-568 (registration)The switch case in the CallToolRequestSchema handler that routes 'export_chemicals' calls to the handleExportChemicals method.case 'export_chemicals': return await this.handleExportChemicals(args);
- src/index.ts:142-155 (helper)Type guard function used to validate input arguments for the export_chemicals tool before execution.const isValidExportArgs = ( args: any ): args is { chemical_ids: string[]; output_type?: string; kind?: string } => { return ( typeof args === 'object' && args !== null && Array.isArray(args.chemical_ids) && args.chemical_ids.length > 0 && args.chemical_ids.length <= 100 && args.chemical_ids.every((id: any) => typeof id === 'string' && id.length > 0) && (args.output_type === undefined || ['csv', 'xml'].includes(args.output_type)) && (args.kind === undefined || ['cid', 'smiles'].includes(args.kind)) ); };