Skip to main content
Glama
HeshamFS

MCP Materials Server

by HeshamFS

get_phase_diagram

Generate phase diagrams for chemical systems to identify stable phases, formation energies, and decomposition products using Materials Project data.

Instructions

Get phase diagram data for a chemical system.

Args:
    elements: List of elements defining the system (e.g., ["Li", "Fe", "O"] for Li-Fe-O system)

Returns:
    JSON with phase diagram entries including stable phases, formation energies, and decomposition products

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
elementsYes

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • The main handler function for the 'get_phase_diagram' tool. It uses the Materials Project API to retrieve phase diagram data for a given list of elements, constructs a PhaseDiagram object, and returns JSON with stable and unstable phases including formation energies and decomposition information.
    @mcp.tool()
    def get_phase_diagram(
        elements: list[str],
    ) -> str:
        """
        Get phase diagram data for a chemical system.
    
        Args:
            elements: List of elements defining the system (e.g., ["Li", "Fe", "O"] for Li-Fe-O system)
    
        Returns:
            JSON with phase diagram entries including stable phases, formation energies, and decomposition products
        """
        has_key, key_or_error = check_api_key()
        if not has_key:
            return json.dumps({"error": key_or_error})
    
        try:
            from mp_api.client import MPRester
            from pymatgen.analysis.phase_diagram import PhaseDiagram
    
            with MPRester(key_or_error) as mpr:
                # Get all entries in the chemical system
                chemsys = "-".join(sorted(elements))
                entries = mpr.get_entries_in_chemsys(elements)
    
                if not entries:
                    return json.dumps({
                        "error": f"No entries found for chemical system: {chemsys}",
                        "chemical_system": chemsys,
                    })
    
                # Build phase diagram
                pd = PhaseDiagram(entries)
    
                # Get stable entries
                stable_entries = []
                for entry in pd.stable_entries:
                    stable_entries.append({
                        "material_id": str(entry.entry_id) if hasattr(entry, 'entry_id') else None,
                        "formula": entry.composition.reduced_formula,
                        "energy_per_atom_eV": entry.energy_per_atom,
                        "formation_energy_per_atom_eV": pd.get_form_energy_per_atom(entry),
                    })
    
                # Get unstable entries with decomposition info
                unstable_entries = []
                for entry in pd.unstable_entries:
                    decomp, e_above_hull = pd.get_decomp_and_e_above_hull(entry)
                    decomp_products = [p.composition.reduced_formula for p in decomp.keys()]
                    unstable_entries.append({
                        "material_id": str(entry.entry_id) if hasattr(entry, 'entry_id') else None,
                        "formula": entry.composition.reduced_formula,
                        "energy_above_hull_eV": e_above_hull,
                        "decomposes_to": decomp_products,
                    })
    
                return json.dumps({
                    "chemical_system": chemsys,
                    "num_elements": len(elements),
                    "total_entries": len(entries),
                    "stable_phases": {
                        "count": len(stable_entries),
                        "entries": stable_entries,
                    },
                    "unstable_phases": {
                        "count": len(unstable_entries),
                        "entries": unstable_entries[:20],  # Limit to first 20
                    },
                }, indent=2)
    
        except ImportError:
            return json.dumps({"error": "mp-api or pymatgen not installed"})
        except Exception as e:
            return json.dumps({"error": str(e)})
  • The @mcp.tool() decorator registers the get_phase_diagram function as an MCP tool.
    @mcp.tool()
  • Input schema defined by function signature (elements: list[str]) and comprehensive docstring describing parameters and return format.
    def get_phase_diagram(
        elements: list[str],
    ) -> str:
        """
        Get phase diagram data for a chemical system.
    
        Args:
            elements: List of elements defining the system (e.g., ["Li", "Fe", "O"] for Li-Fe-O system)
    
        Returns:
            JSON with phase diagram entries including stable phases, formation energies, and decomposition products
        """
  • Helper function check_api_key() used by get_phase_diagram to validate Materials Project API key presence.
    def check_api_key() -> tuple[bool, str]:
        """Check if API key is configured."""
        key = get_mp_api_key()
        if not key:
            return False, "MP_API_KEY environment variable not set. Get your key at https://materialsproject.org/api"
        return True, key
Behavior2/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure. It states it 'Get phase diagram data' but doesn't describe if this is a read-only operation, requires authentication, has rate limits, or what happens on errors. For a tool with zero annotation coverage, this is a significant gap in behavioral context.

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

Conciseness5/5

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

The description is appropriately sized and well-structured, with clear sections for Args and Returns. Each sentence adds value without redundancy, making it easy to parse and understand quickly.

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

Completeness4/5

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

Given the tool's complexity (chemical system analysis), the description is reasonably complete: it explains the purpose, parameter semantics, and return values. With an output schema present, it doesn't need to detail return values further, but could improve by adding usage guidelines and behavioral transparency.

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

Parameters4/5

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

The description adds meaningful context beyond the input schema, which has 0% description coverage. It explains that 'elements' is a 'List of elements defining the system' and provides an example (['Li', 'Fe', 'O'] for Li-Fe-O system), clarifying the parameter's purpose and format effectively.

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

Purpose4/5

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

The description clearly states the tool's purpose with a specific verb ('Get') and resource ('phase diagram data for a chemical system'), making it easy to understand what it does. However, it doesn't explicitly differentiate from sibling tools like 'search_by_elements' or 'get_properties', which might also involve chemical systems, so it misses full sibling distinction.

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?

The description provides no guidance on when to use this tool versus alternatives. It doesn't mention prerequisites, exclusions, or compare to sibling tools like 'search_by_elements' or 'get_properties', leaving the agent without context for tool selection.

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/HeshamFS/mcp-materials-server'

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