Skip to main content
Glama
HeshamFS

MCP Materials Server

by HeshamFS

get_structure

Retrieve crystal structure data for materials from the Materials Project database in CIF, POSCAR, or JSON formats using material IDs.

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

Implementation Reference

  • The core handler function for the 'get_structure' tool, including registration via @mcp.tool() decorator, input schema from type annotations and docstring, and full implementation using Materials Project API to retrieve and format crystal structures.
    @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)})

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