Skip to main content
Glama
liueic

PubChem Chemical Safety MCP Server

by liueic

get_safety_info

Retrieve GHS safety classifications for chemical compounds from PubChem, including hazard statements, pictograms, and signal words using compound IDs.

Instructions

获取GHS安全分类信息

Args: cid: PubChem化合物ID

Returns: 包含信号词、GHS象形图、危害声明等安全信息的字典

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
cidYes

Implementation Reference

  • The handler function get_safety_info, which is registered as an MCP tool, orchestrates the retrieval of safety data by checking the cache and then querying the PubChem client if necessary.
    async def get_safety_info(ctx: Context, cid: int) -> Dict[str, Any]:
        """
        获取GHS安全分类信息
        
        Args:
            cid: PubChem化合物ID
            
        Returns:
            包含信号词、GHS象形图、危害声明等安全信息的字典
        """
        try:
            # 初始化缓存服务
            cache_service = CacheService()
            await cache_service.initialize()
            
            # 检查缓存
            cached_data = await cache_service.get_safety_info(cid)
            if cached_data:
                await cache_service.close()
                return {"cid": cid, **cached_data}
            
            # 从PubChem获取数据
            async with PubChemClient() as client:
                safety_data = await client.get_safety_info(cid)
                
                if "error" in safety_data:
                    await cache_service.close()
                    return {"cid": cid, "error": safety_data["error"]}
                
                # 缓存结果
                await cache_service.set_safety_info(cid, safety_data)
                await cache_service.close()
                
                return {"cid": cid, **safety_data}
                
        except Exception as e:
            logger.error(f"Error getting safety info for CID {cid}: {e}")
            return {"cid": cid, "error": str(e)}
  • The get_safety_info tool is registered using the @app.tool() decorator.
    @app.tool()

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/liueic/PubChem-MCP-Server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server