Skip to main content
Glama
liueic

PubChem Chemical Safety MCP Server

by liueic

get_compound_info

Retrieve compound properties like CID, molecular formula, and weight from PubChem for chemical safety research and analysis.

Instructions

获取化合物基础信息

Args: name: 化合物名称

Returns: 包含CID、分子式、分子量等基础信息的字典

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
nameYes

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • The main handler function for the `get_compound_info` tool in the MCP server. It manages cache checking, PubChem API interaction via `PubChemClient`, and result parsing.
    @app.tool()
    async def get_compound_info(ctx: Context, name: str) -> Dict[str, Any]:
        """
        获取化合物基础信息
        
        Args:
            name: 化合物名称
            
        Returns:
            包含CID、分子式、分子量等基础信息的字典
        """
        try:
            # 初始化缓存服务
            cache_service = CacheService()
            await cache_service.initialize()
            
            # 检查缓存
            cached_data = await cache_service.get_compound_info(name)
            if cached_data:
                await cache_service.close()
                return cached_data
            
            # 从PubChem获取数据
            async with PubChemClient() as client:
                # 获取CID
                cid = await client.get_compound_cid(name)
                if not cid:
                    await cache_service.close()
                    return {"name": name, "error": "Compound not found"}
                
                # 获取基础信息
                compound_data = await client.get_compound_by_name(name)
                
                if "error" in compound_data:
                    await cache_service.close()
                    return {"name": name, "error": compound_data["error"]}
                
                # 解析数据
                info = _parse_compound_data(name, cid, compound_data)
                
                # 缓存结果
                await cache_service.set_compound_info(name, info.model_dump())
                await cache_service.close()
                
                return info.model_dump()
                
        except Exception as e:
            logger.error(f"Error getting compound info for {name}: {e}")
            return {"name": name, "error": str(e)}
  • The `get_compound_info` tool is registered here using the `@app.tool()` decorator from the `FastMCP` framework.
    @app.tool()
  • A helper function `_parse_compound_data` used by `get_compound_info` to transform raw PubChem API responses into the structured `CompoundInfo` model.
    def _parse_compound_data(name: str, cid: int, data: Dict[str, Any]) -> CompoundInfo:
        """解析化合物数据"""
        try:
            properties = data.get("PropertyTable", {}).get("Properties", [])
            if not properties:
                return CompoundInfo(name=name, cid=cid)
            
            props = properties[0]
            
            return CompoundInfo(
                cid=cid,
                name=name,
                molecular_formula=props.get("MolecularFormula"),
                molecular_weight=props.get("MolecularWeight"),
                iupac_name=props.get("IUPACName"),
                smiles=props.get("IsomericSMILES"),
                inchi_key=props.get("InChIKey"),
                synonyms=[]  # 需要额外API调用获取
            )
        except Exception as e:
            logger.error(f"Error parsing compound data: {e}")
            return CompoundInfo(name=name, cid=cid)
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries full burden. It mentions returning a dictionary with CID, molecular formula, and molecular weight, which adds some behavioral context about output format. However, it lacks details on permissions, rate limits, error handling, or whether it's a read-only operation, which is insufficient for a tool with no annotation coverage.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is concise with a clear purpose statement followed by Args and Returns sections. However, the Args section is redundant with the input schema (repeating 'name' without added value), and the structure could be more front-loaded by integrating parameter hints into the main description.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool has an output schema (which should cover return values), the description's mention of return format is somewhat redundant. It provides minimal context for a simple lookup tool but lacks guidance on usage versus siblings and behavioral details, making it incomplete despite the output schema support.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 0%, so the description must compensate. It adds that the 'name' parameter is a compound name, providing basic semantics beyond the schema's generic 'Name' title. However, it doesn't specify format constraints (e.g., IUPAC name, common name) or examples, leaving gaps in parameter understanding.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose3/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description states the tool '获取化合物基础信息' (get compound basic information), which is a clear verb+resource combination. However, it doesn't differentiate from sibling tools like get_safety_info or get_toxicity_data, leaving the scope ambiguous about what distinguishes 'basic information' from safety or toxicity data.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

No guidance is provided on when to use this tool versus alternatives like get_safety_info or get_toxicity_data. The description implies it's for basic compound information but doesn't specify use cases, prerequisites, or exclusions, leaving the agent to guess based on tool names alone.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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