get_compound_properties
Retrieve molecular properties such as MW, logP, and TPSA by specifying a PubChem Compound ID (CID) and optional desired properties via the PubChem MCP Server.
Instructions
Get molecular properties (MW, logP, TPSA, etc.)
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| cid | Yes | PubChem Compound ID (CID) | |
| properties | No | Specific properties to retrieve (optional) |
Implementation Reference
- src/index.ts:1075-1102 (handler)Executes the tool logic: validates input using isValidPropertiesArgs, fetches specified molecular properties from PubChem API via GET request, returns formatted JSON response or throws error.private async handleGetCompoundProperties(args: any) { if (!isValidPropertiesArgs(args)) { throw new McpError(ErrorCode.InvalidParams, 'Invalid compound properties arguments'); } try { const properties = args.properties || [ 'MolecularWeight', 'XLogP', 'TPSA', 'HBondDonorCount', 'HBondAcceptorCount', 'RotatableBondCount', 'Complexity', 'HeavyAtomCount', 'Charge' ]; const response = await this.apiClient.get(`/compound/cid/${args.cid}/property/${properties.join(',')}/JSON`); return { content: [ { type: 'text', text: JSON.stringify(response.data, null, 2), }, ], }; } catch (error) { throw new McpError( ErrorCode.InternalError, `Failed to get compound properties: ${error instanceof Error ? error.message : 'Unknown error'}` ); } }
- src/index.ts:506-513 (schema)Defines the input schema for the tool: requires 'cid' as number or string, optional 'properties' array of strings.inputSchema: { type: 'object', properties: { cid: { type: ['number', 'string'], description: 'PubChem Compound ID (CID)' }, properties: { type: 'array', items: { type: 'string' }, description: 'Specific properties to retrieve (optional)' }, }, required: ['cid'], },
- src/index.ts:503-514 (registration)Registers the tool in the ListToolsRequestSchema handler with name, description, and input schema.{ name: 'get_compound_properties', description: 'Get molecular properties (MW, logP, TPSA, etc.)', inputSchema: { type: 'object', properties: { cid: { type: ['number', 'string'], description: 'PubChem Compound ID (CID)' }, properties: { type: 'array', items: { type: 'string' }, description: 'Specific properties to retrieve (optional)' }, }, required: ['cid'], }, },
- src/index.ts:766-767 (registration)Dispatches tool calls to the handler in the CallToolRequestSchema switch statement.case 'get_compound_properties': return await this.handleGetCompoundProperties(args);
- src/index.ts:114-123 (helper)Validates input arguments for the get_compound_properties tool, checking cid type and properties array.const isValidPropertiesArgs = ( args: any ): args is { cid: number | string; properties?: string[] } => { return ( typeof args === 'object' && args !== null && (typeof args.cid === 'number' || typeof args.cid === 'string') && (args.properties === undefined || (Array.isArray(args.properties) && args.properties.every((p: any) => typeof p === 'string'))) ); };