get_compound_synonyms
Retrieve all names and synonyms for a specific compound using its PubChem CID. This tool helps streamline chemical identification and data lookup within the Unofficial PubChem MCP Server.
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 core handler function for the "get_compound_synonyms" tool. Validates input using isValidCidArgs, calls PubChem API to retrieve synonyms for the given CID, and returns the response as JSON-formatted text.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:428-438 (schema)The tool definition including name, description, and input schema requiring a 'cid' parameter (number or string). This is used in server.setTools() for registration.{ 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)Switch case in the tool request handler that dispatches "get_compound_synonyms" calls to the specific handler function.case 'get_compound_synonyms': return await this.handleGetCompoundSynonyms(args);
- src/index.ts:65-74 (helper)Type guard helper function for validating CID arguments, used in the handler and other tools.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)) ); };