batch_compound_lookup
Look up multiple ChEMBL compound IDs simultaneously to retrieve chemical data efficiently. Process up to 50 IDs in a single request.
Instructions
Process multiple ChEMBL IDs efficiently
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| chembl_ids | Yes | Array of ChEMBL compound IDs (1-50) |
Implementation Reference
- src/index.ts:1817-1837 (handler)The primary handler function that implements the batch_compound_lookup tool logic. It validates the input arguments, iterates over the provided ChEMBL IDs (limited to 10 for demo), fetches compound data from the ChEMBL API for each, and compiles results including success status and any errors.private async handleBatchCompoundLookup(args: any) { if (!isValidBatchArgs(args)) { throw new McpError(ErrorCode.InvalidParams, 'Invalid batch arguments'); } try { const results = []; for (const chemblId of args.chembl_ids.slice(0, 10)) { // Limit to 10 for demo try { const response = await this.apiClient.get(`/molecule/${chemblId}.json`); results.push({ chembl_id: chemblId, data: response.data, success: true }); } catch (error) { results.push({ chembl_id: chemblId, 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:697-707 (registration)Tool registration entry in the ListTools response, defining the tool name, description, and JSON input schema for validation.{ name: 'batch_compound_lookup', description: 'Process multiple ChEMBL IDs efficiently', inputSchema: { type: 'object', properties: { chembl_ids: { type: 'array', items: { type: 'string' }, description: 'Array of ChEMBL compound IDs (1-50)', minItems: 1, maxItems: 50 }, }, required: ['chembl_ids'], }, },
- src/index.ts:798-799 (registration)Dispatch registration in the CallToolRequestSchema switch statement that routes calls to the handler function.case 'batch_compound_lookup': return await this.handleBatchCompoundLookup(args);
- src/index.ts:165-176 (schema)Type guard and validation function specifically for batch_compound_lookup input arguments, ensuring chembl_ids is a valid array of 1-50 non-empty strings.const isValidBatchArgs = ( args: any ): args is { chembl_ids: string[] } => { return ( typeof args === 'object' && args !== null && Array.isArray(args.chembl_ids) && args.chembl_ids.length > 0 && args.chembl_ids.length <= 50 && args.chembl_ids.every((id: any) => typeof id === 'string' && id.length > 0) ); };
- src/index.ts:1835-1836 (helper)Error handling within the batch handler, but primarily covered in handler. Additional helper note.throw new McpError(ErrorCode.InternalError, `Batch lookup failed: ${error instanceof Error ? error.message : 'Unknown error'}`); }