Skip to main content
Glama
HeshamFS

MCP Materials Server

by HeshamFS

compare_materials

Compare properties of multiple materials side by side to analyze differences and identify optimal selections for specific applications.

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
NameRequiredDescriptionDefault
material_idsYes

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • The core handler function for the 'compare_materials' tool. It fetches material summaries from Materials Project API using MPRester, compares key properties like formula, band gap, stability, etc., and returns a JSON-formatted comparison table. Includes error handling for invalid IDs and API issues.
    @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)})
  • The @mcp.tool() decorator registers the compare_materials function as an MCP tool, automatically generating schema from type hints and docstring.
    @mcp.tool()
  • Input schema defined by type hint 'material_ids: list[str]' and comprehensive docstring describing parameters and return format (JSON comparison table).
    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
        """
  • Shared helper function used by compare_materials (and other tools) to validate Materials Project API key presence before making API calls.
    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
  • The main() function initializes and runs the FastMCP server instance (created at line 19), which scans and registers all @mcp.tool() decorated functions including compare_materials.
    def main():
        """Run the MCP server."""
        mcp.run()
Behavior2/5

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

With no annotations provided, the description carries full burden for behavioral disclosure. While it states what the tool does (comparison) and the return format (JSON table), it lacks important behavioral context such as whether this is a read-only operation, what authentication might be required, rate limits, what specific 'key properties' are included, or how many materials can be compared at once.

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 perfectly structured and concise. It begins with a clear purpose statement, then provides an 'Args:' section with parameter explanation, followed by a 'Returns:' section. Every sentence earns its place, and the information is front-loaded with the most important purpose statement first.

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 that there's an output schema (though not provided in the context), the description doesn't need to fully explain return values. The description covers the essential purpose, parameter semantics, and return format. However, for a comparison tool with no annotations, it could benefit from more behavioral context about what 'key properties' means or limitations of the comparison.

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 significant value beyond the input schema, which has 0% description coverage. It explains that 'material_ids' should be 'List of Materials Project IDs' and provides concrete examples (["mp-149", "mp-66"]). This transforms a generic array parameter into a specific, meaningful input requirement that the schema alone doesn't convey.

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: 'Compare properties of multiple materials side by side.' This specifies the verb (compare) and resource (materials properties) with the scope of side-by-side comparison. However, it doesn't explicitly differentiate from sibling tools like 'get_properties' or 'search_by_band_gap' that might also provide material property information.

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. There are multiple sibling tools that deal with material properties (get_properties, search_by_band_gap, search_by_elastic_properties, etc.), but the description offers no context about when this comparison tool is preferable to those individual property retrieval tools.

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