get_safety_data
Retrieve GHS hazard classifications and safety information for chemical compounds using PubChem Compound ID to assess chemical risks and handling requirements.
Instructions
Get GHS hazard classifications and safety information
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| cid | Yes | PubChem Compound ID (CID) |
Implementation Reference
- src/index.ts:1160-1181 (handler)The handler function that validates the CID argument and fetches safety classification data from the PubChem API endpoint `/compound/cid/{cid}/classification/JSON`, returning the JSON response.private async handleGetSafetyData(args: any) { if (!isValidCidArgs(args)) { throw new McpError(ErrorCode.InvalidParams, 'Invalid CID arguments'); } try { const response = await this.apiClient.get(`/compound/cid/${args.cid}/classification/JSON`); return { content: [ { type: 'text', text: JSON.stringify(response.data, null, 2), }, ], }; } catch (error) { throw new McpError( ErrorCode.InternalError, `Failed to get safety data: ${error instanceof Error ? error.message : 'Unknown error'}` ); } }
- src/index.ts:639-649 (schema)The input schema definition for the 'get_safety_data' tool, specifying that a 'cid' (PubChem Compound ID) is required.{ name: 'get_safety_data', description: 'Get GHS hazard classifications and safety information', inputSchema: { type: 'object', properties: { cid: { type: ['number', 'string'], description: 'PubChem Compound ID (CID)' }, }, required: ['cid'], }, },
- src/index.ts:792-793 (registration)The switch case in the CallToolRequestSchema handler that dispatches calls to 'get_safety_data' to the handleGetSafetyData method.case 'get_safety_data': return await this.handleGetSafetyData(args);
- src/index.ts:639-649 (registration)Registration of the 'get_safety_data' tool in the ListToolsRequestSchema response, including name, description, and schema.{ name: 'get_safety_data', description: 'Get GHS hazard classifications and safety information', inputSchema: { type: 'object', properties: { cid: { type: ['number', 'string'], description: 'PubChem Compound ID (CID)' }, }, required: ['cid'], }, },
- src/index.ts:65-74 (helper)Type guard function used to validate arguments for get_safety_data (and other CID-based tools), checking for valid 'cid'.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)) ); };