Skip to main content
Glama
HeshamFS

MCP Materials Server

by HeshamFS

get_structure

Retrieve crystal structure data from Materials Project by material ID. Supports CIF, POSCAR, and JSON formats for materials science analysis.

Instructions

Get the crystal structure for a material from Materials Project.

Args:
    material_id: Materials Project ID (e.g., "mp-149" for Silicon)
    format: Output format - "cif", "poscar", or "json" (default: "cif")

Returns:
    Crystal structure in the requested format

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
material_idYes
formatNocif

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • The main handler function for the 'get_structure' tool, decorated with @mcp.tool() for automatic registration and schema generation from type hints and docstring. Fetches crystal structure data from Materials Project API and returns in CIF, POSCAR, or JSON format.
    @mcp.tool()
    def get_structure(
        material_id: str,
        format: str = "cif",
    ) -> str:
        """
        Get the crystal structure for a material from Materials Project.
    
        Args:
            material_id: Materials Project ID (e.g., "mp-149" for Silicon)
            format: Output format - "cif", "poscar", or "json" (default: "cif")
    
        Returns:
            Crystal structure in the requested format
        """
        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
    
            with MPRester(key_or_error) as mpr:
                structure = mpr.get_structure_by_material_id(material_id)
    
                if format.lower() == "cif":
                    from pymatgen.io.cif import CifWriter
                    return CifWriter(structure).__str__()
                elif format.lower() == "poscar":
                    from pymatgen.io.vasp import Poscar
                    return Poscar(structure).get_str()
                elif format.lower() == "json":
                    return structure.to_json()
                else:
                    return json.dumps({"error": f"Unknown format: {format}. Use 'cif', 'poscar', or 'json'"})
    
        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_structure function as an MCP tool.
    @mcp.tool()
  • Input schema defined by function parameters (material_id: str, format: str = 'cif') and comprehensive docstring describing args and return value. Output is str (structure file content or JSON error).
    def get_structure(
        material_id: str,
        format: str = "cif",
    ) -> str:
        """
        Get the crystal structure for a material from Materials Project.
    
        Args:
            material_id: Materials Project ID (e.g., "mp-149" for Silicon)
            format: Output format - "cif", "poscar", or "json" (default: "cif")
    
        Returns:
            Crystal structure in the requested format
        """
Behavior3/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 describes the tool's function and output format options, but lacks details on rate limits, authentication needs, error handling, or data freshness. It adequately covers basic behavior but misses advanced operational 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 front-loaded with the core purpose, followed by clear sections for arguments and returns. Every sentence adds value—no redundancy or fluff—making it efficiently structured and easy to parse.

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 moderate complexity (2 parameters, no annotations, but with an output schema), the description is mostly complete. It explains parameters and return values well, but could improve by addressing behavioral aspects like rate limits or errors, though the output schema reduces the need for detailed return value explanations.

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

Parameters5/5

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

The description adds significant meaning beyond the input schema, which has 0% description coverage. It explains that 'material_id' is a Materials Project ID with an example ('mp-149' for Silicon) and defines 'format' options ('cif', 'poscar', 'json') with a default, fully compensating for the schema's lack of documentation.

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

Purpose5/5

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

The description clearly states the specific action ('Get the crystal structure') and resource ('for a material from Materials Project'), distinguishing it from sibling tools that focus on properties, comparisons, or searches rather than retrieving structural data.

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

Usage Guidelines3/5

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

The description implies usage by specifying the tool's purpose and parameters, but does not explicitly state when to use this tool versus alternatives like 'get_similar_structures' or 'search_by_elements', nor does it mention prerequisites or exclusions.

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