get_compound_info
Retrieve detailed chemical information for compounds using PubChem Compound IDs, including structure data, properties, bioactivity, and safety information.
Instructions
Get detailed information for a specific compound by PubChem CID
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| cid | Yes | PubChem Compound ID (CID) | |
| format | No | Output format (default: json) |
Implementation Reference
- src/index.ts:882-905 (handler)The handler function that implements the core logic of the 'get_compound_info' tool. It validates input arguments using isValidCidArgs, fetches compound data from the PubChem API based on the provided CID and optional format, and returns the response as text content.private async handleGetCompoundInfo(args: any) { if (!isValidCidArgs(args)) { throw new McpError(ErrorCode.InvalidParams, 'Invalid CID arguments'); } try { const format = args.format || 'json'; const response = await this.apiClient.get(`/compound/cid/${args.cid}/${format === 'json' ? 'JSON' : format}`); return { content: [ { type: 'text', text: format === 'json' ? JSON.stringify(response.data, null, 2) : String(response.data), }, ], }; } catch (error) { throw new McpError( ErrorCode.InternalError, `Failed to get compound info: ${error instanceof Error ? error.message : 'Unknown error'}` ); } }
- src/index.ts:383-394 (registration)The tool registration entry in the ListToolsRequestSchema handler, defining the name, description, and input schema for 'get_compound_info'.{ name: 'get_compound_info', description: 'Get detailed information for a specific compound by PubChem CID', inputSchema: { type: 'object', properties: { cid: { type: ['number', 'string'], description: 'PubChem Compound ID (CID)' }, format: { type: 'string', enum: ['json', 'sdf', 'xml', 'asnt', 'asnb'], description: 'Output format (default: json)' }, }, required: ['cid'], }, },
- src/index.ts:386-393 (schema)The input schema defining the expected parameters for the 'get_compound_info' tool: cid (required, number or string) and optional format.inputSchema: { type: 'object', properties: { cid: { type: ['number', 'string'], description: 'PubChem Compound ID (CID)' }, format: { type: 'string', enum: ['json', 'sdf', 'xml', 'asnt', 'asnb'], description: 'Output format (default: json)' }, }, required: ['cid'], },
- src/index.ts:65-74 (helper)Helper validation function isValidCidArgs used by the handler to validate input arguments for CID and optional format.const isValidCidArgs = ( args: any ): args is { cid: number | string; format?: string } => { return ( typeof args === 'object' && args !== null && (typeof args.cid === 'number' || typeof args.cid === 'string') && (args.format === undefined || ['json', 'sdf', 'xml', 'asnt', 'asnb'].includes(args.format)) ); };
- src/index.ts:742-743 (registration)Dispatch case in the CallToolRequestSchema handler that routes calls to 'get_compound_info' to the appropriate handler method.case 'get_compound_info': return await this.handleGetCompoundInfo(args);