get_materials_with_elements
Identify materials containing specific elements while optionally excluding unwanted elements using the Materials Project database, returning up to a defined number of records for targeted research.
Instructions
Find materials containing specific elements.
Args:
elements: List of elements that must be present in the material (e.g., ["Fe", "O"]).
exclude_elements: Optional list of elements that must not be present.
max_records: Maximum number of records to return (default: 10).
Returns:
List of materials containing the specified elements.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| elements | Yes | ||
| exclude_elements | No | ||
| max_records | No |
Implementation Reference
- src/materials_project_mcp/tools.py:14-62 (handler)The handler function implementing the get_materials_with_elements tool. It calls the API wrapper fetch_materials_by_elements and processes the results into a simplified format.def get_materials_with_elements( elements: List[str], exclude_elements: Optional[List[str]] = None, max_records: int = 10 ) -> List[Dict[str, Any]]: """ Find materials containing specific elements. Args: elements: List of elements that must be present in the material (e.g., ["Fe", "O"]). exclude_elements: Optional list of elements that must not be present. max_records: Maximum number of records to return (default: 10). Returns: List of materials containing the specified elements. """ properties = [ "material_id", "formula_pretty", "symmetry", "formation_energy_per_atom", "band_gap", "density", "is_stable" ] materials = fetch_materials_by_elements( elements=elements, exclude_elements=exclude_elements, max_records=max_records, properties=properties ) # Extract key properties for each material simplified_results = [] for material in materials: simplified_material = { "material_id": material.get("material_id"), "formula": material.get("formula_pretty"), "band_gap": material.get("band_gap"), "formation_energy": material.get("formation_energy_per_atom"), "crystal_system": material.get("symmetry", {}).get("crystal_system"), "space_group": material.get("symmetry", {}).get("symbol"), "density": material.get("density"), "is_stable": material.get("is_stable", False) } simplified_results.append(simplified_material) return simplified_results
- src/materials_project_mcp/main.py:20-20 (registration)Registers the get_materials_with_elements tool with the FastMCP instance.mcp.tool(get_materials_with_elements)