batch_compound_lookup
Retrieve chemical properties, synonyms, classifications, or descriptions for multiple PubChem compounds simultaneously. Process up to 200 compound IDs in a single operation to access comprehensive chemical data efficiently.
Instructions
Process multiple compound IDs efficiently
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| cids | Yes | Array of PubChem CIDs (1-200) | |
| operation | No | Operation to perform (default: property) |
Implementation Reference
- src/index.ts:1207-1227 (handler)Main handler function for batch_compound_lookup tool. Validates input, fetches properties (MolecularWeight, CanonicalSMILES, IUPACName) for up to 10 CIDs from PubChem API, collects results with error handling per CID, returns JSON-formatted batch results.private async handleBatchCompoundLookup(args: any) { if (!isValidBatchArgs(args)) { throw new McpError(ErrorCode.InvalidParams, 'Invalid batch arguments'); } try { const results = []; for (const cid of args.cids.slice(0, 10)) { try { const response = await this.apiClient.get(`/compound/cid/${cid}/property/MolecularWeight,CanonicalSMILES,IUPACName/JSON`); results.push({ cid, data: response.data, success: true }); } catch (error) { results.push({ cid, error: error instanceof Error ? error.message : 'Unknown error', success: false }); } } return { content: [{ type: 'text', text: JSON.stringify({ batch_results: results }, null, 2) }] }; } catch (error) { throw new McpError(ErrorCode.InternalError, `Batch lookup failed: ${error instanceof Error ? error.message : 'Unknown error'}`); } }
- src/index.ts:722-729 (schema)Input JSON schema for the batch_compound_lookup tool defining required cids array and optional operation.inputSchema: { type: 'object', properties: { cids: { type: 'array', items: { type: 'number' }, description: 'Array of PubChem CIDs (1-200)', minItems: 1, maxItems: 200 }, operation: { type: 'string', enum: ['property', 'synonyms', 'classification', 'description'], description: 'Operation to perform (default: property)' }, }, required: ['cids'], },
- src/index.ts:719-730 (registration)Tool registration entry in the ListToolsRequestSchema handler, specifying name, description, and input schema.{ name: 'batch_compound_lookup', description: 'Process multiple compound IDs efficiently', inputSchema: { type: 'object', properties: { cids: { type: 'array', items: { type: 'number' }, description: 'Array of PubChem CIDs (1-200)', minItems: 1, maxItems: 200 }, operation: { type: 'string', enum: ['property', 'synonyms', 'classification', 'description'], description: 'Operation to perform (default: property)' }, }, required: ['cids'], }, },
- src/index.ts:89-101 (helper)Helper type guard function for validating batch_compound_lookup arguments: checks cids is array of 1-200 positive numbers, operation is valid enum or undefined.const isValidBatchArgs = ( args: any ): args is { cids: number[]; operation?: string } => { return ( typeof args === 'object' && args !== null && Array.isArray(args.cids) && args.cids.length > 0 && args.cids.length <= 200 && args.cids.every((cid: any) => typeof cid === 'number' && cid > 0) && (args.operation === undefined || ['property', 'synonyms', 'classification', 'description'].includes(args.operation)) ); };