get_compound_synonyms
Retrieve all names and synonyms for a chemical compound by providing its PubChem Compound ID (CID). Enhances search and identification in chemical databases.
Instructions
Get all names and synonyms for a compound
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| cid | Yes | PubChem Compound ID (CID) |
Implementation Reference
- src/index.ts:958-979 (handler)The main handler function that validates the input CID, calls the PubChem API to retrieve synonyms, and returns the JSON response as text content.private async handleGetCompoundSynonyms(args: any) { if (!isValidCidArgs(args)) { throw new McpError(ErrorCode.InvalidParams, 'Invalid CID arguments'); } try { const response = await this.apiClient.get(`/compound/cid/${args.cid}/synonyms/JSON`); return { content: [ { type: 'text', text: JSON.stringify(response.data, null, 2), }, ], }; } catch (error) { throw new McpError( ErrorCode.InternalError, `Failed to get compound synonyms: ${error instanceof Error ? error.message : 'Unknown error'}` ); } }
- src/index.ts:431-437 (schema)Input schema definition for the tool, specifying that 'cid' is required as a number or string.inputSchema: { type: 'object', properties: { cid: { type: ['number', 'string'], description: 'PubChem Compound ID (CID)' }, }, required: ['cid'], },
- src/index.ts:428-438 (registration)Tool registration in the tools list provided to MCP server.setRequestHandler(ListToolsRequestSchema), including name, description, and schema.{ name: 'get_compound_synonyms', description: 'Get all names and synonyms for a compound', inputSchema: { type: 'object', properties: { cid: { type: ['number', 'string'], description: 'PubChem Compound ID (CID)' }, }, required: ['cid'], }, },
- src/index.ts:750-751 (registration)Dispatcher case in the CallToolRequestSchema handler that routes calls to the specific handler function.case 'get_compound_synonyms': return await this.handleGetCompoundSynonyms(args);
- src/index.ts:65-74 (helper)Type guard function used for input validation in the handler, checking for valid 'cid' (number or string). Note: format check is extra but harmless.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)) ); };