Skip to main content
Glama

batch_compound_lookup

Retrieve compound properties, synonyms, classifications, or descriptions for multiple PubChem CIDs (1-200) in a single query to streamline chemical data analysis.

Instructions

Process multiple compound IDs efficiently

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
cidsYesArray of PubChem CIDs (1-200)
operationNoOperation to perform (default: property)

Implementation Reference

  • Core implementation of the batch_compound_lookup tool handler. Validates args with isValidBatchArgs, fetches properties (MolecularWeight, CanonicalSMILES, IUPACName) for up to 10 CIDs from PubChem API via batch requests, handles individual errors, returns JSON with results array.
    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:719-730 (registration)
    Tool registration in the ListTools response, defining name, description, and input schema for batch_compound_lookup.
    { 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'], }, },
  • JSON Schema defining the input parameters: required 'cids' array (1-200 numbers), optional 'operation' enum.
    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'],
  • Helper validation function (type guard) for batch_compound_lookup arguments, enforcing cids array constraints and operation enum.
    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)) ); };
  • src/index.ts:808-809 (registration)
    Dispatcher switch case in CallToolRequestSchema handler that routes 'batch_compound_lookup' calls to the handleBatchCompoundLookup method.
    case 'batch_compound_lookup': return await this.handleBatchCompoundLookup(args);

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/Augmented-Nature/PubChem-MCP-Server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server