compare_materials
Compare properties of multiple materials side by side to analyze differences and make informed material selection decisions.
Instructions
Compare properties of multiple materials side by side.
Args:
material_ids: List of Materials Project IDs (e.g., ["mp-149", "mp-66"])
Returns:
JSON table comparing key properties across materials
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| material_ids | Yes |
Implementation Reference
- src/mcp_materials/server.py:210-263 (handler)The main handler function for the 'compare_materials' tool, decorated with @mcp.tool() for automatic registration. Compares properties of multiple materials from Materials Project API.@mcp.tool() def compare_materials( material_ids: list[str], ) -> str: """ Compare properties of multiple materials side by side. Args: material_ids: List of Materials Project IDs (e.g., ["mp-149", "mp-66"]) Returns: JSON table comparing key properties across materials """ 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 comparison = [] with MPRester(key_or_error) as mpr: for mid in material_ids: try: doc = mpr.materials.summary.get_data_by_id(mid) crystal_system = None if doc.symmetry and doc.symmetry.crystal_system: crystal_system = str(doc.symmetry.crystal_system.value) if hasattr(doc.symmetry.crystal_system, 'value') else str(doc.symmetry.crystal_system) comparison.append({ "material_id": str(doc.material_id), "formula": doc.formula_pretty, "band_gap_eV": doc.band_gap, "formation_energy_eV": doc.formation_energy_per_atom, "energy_above_hull_eV": doc.energy_above_hull, "density_g_cm3": doc.density, "is_stable": doc.is_stable, "is_metal": doc.is_metal, "crystal_system": crystal_system, }) except Exception as e: comparison.append({ "material_id": mid, "error": str(e), }) return json.dumps({ "count": len(comparison), "comparison": comparison, }, indent=2) except Exception as e: return json.dumps({"error": str(e)})