Skip to main content
Glama
HeshamFS

MCP Materials Server

by HeshamFS

get_similar_structures

Find materials with similar crystal structures by providing a Materials Project ID. Returns JSON data of structurally comparable materials for analysis and research.

Instructions

Find materials with similar crystal structures.

Args:
    material_id: Materials Project ID to find similar structures for
    max_results: Maximum number of similar structures (default: 5)

Returns:
    JSON with structurally similar materials

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
material_idYes
max_resultsNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • The primary handler function for the 'get_similar_structures' tool. Decorated with @mcp.tool() for automatic schema generation from type hints/docstring and registration with the MCP server. Retrieves the space group of the input material and searches for other materials with the same space group using the Materials Project API, excluding the reference material itself.
    @mcp.tool()
    def get_similar_structures(
        material_id: str,
        max_results: int = 5,
    ) -> str:
        """
        Find materials with similar crystal structures.
    
        Args:
            material_id: Materials Project ID to find similar structures for
            max_results: Maximum number of similar structures (default: 5)
    
        Returns:
            JSON with structurally similar 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
    
            with MPRester(key_or_error) as mpr:
                # Get the reference material
                ref_doc = mpr.materials.summary.get_data_by_id(material_id)
                space_group = ref_doc.symmetry.number if ref_doc.symmetry else None
    
                if not space_group:
                    return json.dumps({"error": "Could not determine space group for reference material"})
    
                # Search for materials with same space group
                docs = mpr.materials.summary.search(
                    spacegroup_number=space_group,
                    fields=[
                        "material_id",
                        "formula_pretty",
                        "symmetry",
                        "nsites",
                        "volume",
                    ],
                    num_chunks=1,
                    chunk_size=max_results + 1,  # +1 to exclude self
                )
    
                results = []
                for doc in docs:
                    if str(doc.material_id) == material_id:
                        continue
                    if len(results) >= max_results:
                        break
                    results.append({
                        "material_id": str(doc.material_id),
                        "formula": doc.formula_pretty,
                        "space_group": doc.symmetry.symbol if doc.symmetry else None,
                        "nsites": doc.nsites,
                        "volume_A3": doc.volume,
                    })
    
                return json.dumps({
                    "reference": {
                        "material_id": material_id,
                        "formula": ref_doc.formula_pretty,
                        "space_group": ref_doc.symmetry.symbol if ref_doc.symmetry else None,
                    },
                    "similar_structures": results,
                }, indent=2)
    
        except Exception as e:
            return json.dumps({"error": str(e)})
  • The docstring and function signature provide the input schema (material_id: str, max_results: int=5) and output description (JSON with reference and similar_structures list), used by FastMCP to generate JSON Schema for the tool.
    """
    Find materials with similar crystal structures.
    
    Args:
        material_id: Materials Project ID to find similar structures for
        max_results: Maximum number of similar structures (default: 5)
    
    Returns:
        JSON with structurally similar materials
  • The @mcp.tool() decorator registers the function as an MCP tool, handling tool exposure to clients.
    @mcp.tool()
  • An MCP prompt template that recommends using the get_similar_structures tool as part of material analysis workflow.
    @mcp.prompt()
    def analyze_material(material_id: str) -> str:
        """Generate a prompt for comprehensive material analysis."""
        return f"""Analyze the material with ID {material_id} from the Materials Project database.
    
    Please:
    1. First, use the get_properties tool to retrieve all properties for {material_id}
    2. Summarize the key characteristics (composition, structure, stability)
    3. Discuss the electronic properties (band gap, metallic/insulating)
    4. Assess thermodynamic stability based on energy above hull
    5. Suggest potential applications based on the properties
    6. Recommend similar materials to compare using get_similar_structures
    
    Provide a comprehensive analysis suitable for a materials scientist."""
Behavior2/5

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

No annotations are provided, so the description carries the full burden. It mentions the tool 'finds' similar structures and returns JSON, but lacks details on behavioral traits such as rate limits, error handling, authentication needs, or what 'similar' means (e.g., similarity metrics or thresholds). This is inadequate for a tool with potential computational complexity.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is appropriately sized and front-loaded, starting with the core purpose. The Args and Returns sections are structured clearly, but the 'Returns' line is somewhat vague ('JSON with structurally similar materials') and could be more specific. Overall, it's efficient with minimal waste.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool has an output schema, the description doesn't need to detail return values. However, with no annotations, 0% schema coverage, and two parameters, it should provide more context on usage and behavior. It covers basics but lacks depth for a tool that might involve complex structural analysis.

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

Parameters3/5

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

Schema description coverage is 0%, so the description must compensate. It adds meaning by explaining 'material_id' as 'Materials Project ID to find similar structures for' and 'max_results' as 'Maximum number of similar structures (default: 5)', which clarifies beyond the schema's basic types. However, it doesn't cover constraints like ID formats or result limits, leaving gaps.

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: 'Find materials with similar crystal structures.' It specifies the verb ('Find') and resource ('materials with similar crystal structures'), making it understandable. However, it doesn't explicitly differentiate from sibling tools like 'compare_materials' or 'search_by_elements,' which might also involve structural comparisons, leaving some ambiguity about uniqueness.

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. It doesn't mention prerequisites, exclusions, or compare it to siblings like 'compare_materials' or 'search_by_elements,' which could be relevant for structural queries. Usage is implied through the parameters but not explicitly stated.

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