Skip to main content
Glama
HeshamFS

MCP Materials Server

by HeshamFS

search_by_band_gap

Find materials with specific electronic properties by searching within a defined band gap range, including options for direct band gaps and result limits.

Instructions

Search for materials by band gap range.

Args:
    min_gap: Minimum band gap in eV (default: 0)
    max_gap: Maximum band gap in eV (default: 10)
    direct_gap_only: Only return materials with direct band gaps
    max_results: Maximum number of results (default: 10)

Returns:
    JSON with materials in the specified band gap range

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
min_gapNo
max_gapNo
direct_gap_onlyNo
max_resultsNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • The handler function for the 'search_by_band_gap' MCP tool. Decorated with @mcp.tool(), it queries the Materials Project database for materials within a specified band gap range (min_gap to max_gap), optionally filtering for direct band gaps only. Returns JSON with matching materials including material_id, formula, band_gap, stability, etc.
    @mcp.tool()
    def search_by_band_gap(
        min_gap: float = 0.0,
        max_gap: float = 10.0,
        direct_gap_only: bool = False,
        max_results: int = 10,
    ) -> str:
        """
        Search for materials by band gap range.
    
        Args:
            min_gap: Minimum band gap in eV (default: 0)
            max_gap: Maximum band gap in eV (default: 10)
            direct_gap_only: Only return materials with direct band gaps
            max_results: Maximum number of results (default: 10)
    
        Returns:
            JSON with materials in the specified band gap range
        """
        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:
                search_kwargs: dict[str, Any] = {
                    "band_gap": (min_gap, max_gap),
                    "fields": [
                        "material_id",
                        "formula_pretty",
                        "band_gap",
                        "is_gap_direct",
                        "energy_above_hull",
                        "is_stable",
                    ],
                    "num_chunks": 1,
                    "chunk_size": max_results * 2,  # Get extra in case we filter
                }
    
                if direct_gap_only:
                    search_kwargs["is_gap_direct"] = True
    
                docs = mpr.materials.summary.search(**search_kwargs)
    
                results = []
                for doc in docs:
                    if len(results) >= max_results:
                        break
                    results.append({
                        "material_id": str(doc.material_id),
                        "formula": doc.formula_pretty,
                        "band_gap_eV": doc.band_gap,
                        "is_direct_gap": doc.is_gap_direct,
                        "energy_above_hull_eV": doc.energy_above_hull,
                        "is_stable": doc.is_stable,
                    })
    
                return json.dumps({
                    "query": {
                        "band_gap_range_eV": [min_gap, max_gap],
                        "direct_gap_only": direct_gap_only,
                    },
                    "count": len(results),
                    "materials": results,
                }, indent=2)
    
        except Exception as e:
            return json.dumps({"error": str(e)})
Behavior2/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure. It mentions the tool returns JSON with materials, but lacks details on permissions, rate limits, error handling, or whether this is a read-only operation. For a search tool with zero annotation coverage, this leaves significant gaps in understanding its behavior.

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 well-structured with clear sections for Args and Returns, making it easy to scan. It's appropriately sized with no wasted sentences, though the 'Returns' section could be slightly more detailed (e.g., format of materials data). Overall, it's efficient and front-loaded with the core purpose.

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 the tool's moderate complexity (4 parameters, no annotations, but has output schema), the description is reasonably complete. It covers the purpose, all parameters, and return type. The output schema existence means it doesn't need to detail return values, but it could benefit from more behavioral context (e.g., search scope or limitations).

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

Parameters5/5

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

The description adds substantial meaning beyond the input schema, which has 0% description coverage. It explains all four parameters: 'min_gap' and 'max_gap' are defined with units (eV) and defaults, 'direct_gap_only' clarifies its filter effect, and 'max_results' specifies its purpose. This fully compensates for the schema's lack of descriptions.

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: 'Search for materials by band gap range.' This specifies the verb ('search') and resource ('materials') with the key criterion ('band gap range'). However, it doesn't explicitly differentiate from sibling tools like 'search_by_elements' or 'search_by_elastic_properties,' which prevents a perfect score.

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 sibling tools or contexts where band gap searching is appropriate versus other search methods. The only implied usage is for materials with specific band gap properties, but this is too vague for effective tool selection.

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