Skip to main content
Glama
kukapay

blocknative-mcp

predict_gas_price

Predict gas prices for blockchain networks to estimate transaction costs. Provides base fee and detailed prediction data in a Markdown table for specified chain IDs.

Instructions

Predict gas prices for a specified chain, including base fee and detailed prediction data in a Markdown table.

Parameters:
- chain_id (int): The ID of the blockchain network (e.g., 1 for Ethereum Mainnet). Default: 1.
- ctx (Optional[Context]): The MCP context object. Default: None.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
chain_idNo
ctxNo

Implementation Reference

  • The handler function for the 'predict_gas_price' tool. It is decorated with @mcp.tool(), which registers it in the MCP server. Fetches gas prices from Blocknative API using the helper function and formats the response as a Markdown table with base fee and confidence-based predictions.
    @mcp.tool()
    async def predict_gas_price(chain_id: int = 1, ctx: Optional[Context] = None) -> str:
        """
        Predict gas prices for a specified chain, including base fee and detailed prediction data in a Markdown table.
    
        Parameters:
        - chain_id (int): The ID of the blockchain network (e.g., 1 for Ethereum Mainnet). Default: 1.
        - ctx (Optional[Context]): The MCP context object. Default: None.
        """
        data = await fetch_gas_prices(chain_id)
        if "error" in data:
            return data["error"]
        
        # Format base fee and metadata
        base_fee = data["baseFeePerGas"]
        output = f"Gas Price Predictions for Chain ID {chain_id} ({data['system']}/{data['network']}):\n"
        output += f"- Base Fee Per Gas: {base_fee} Gwei\n\n"
        
        # Format predictions as a Markdown table
        predictions = data["estimatedPrices"]
        if not predictions:
            output += "No prediction data available."
        else:
            output += "| Confidence | Price (Gwei) | Max Priority Fee (Gwei) | Max Fee (Gwei) |\n"
            output += "|------------|--------------|-------------------------|----------------|\n"
            for price in predictions:
                confidence = price.get("confidence", 0)
                price_value = price.get("price", 0)
                max_priority_fee = price.get("maxPriorityFeePerGas", 0)
                max_fee = price.get("maxFeePerGas", 0)
                output += (
                    f"| {confidence}% | {price_value} | {max_priority_fee} | {max_fee} |\n"
                )
        
        return output
  • Helper function to fetch raw gas price data from the Blocknative API, which is called by the predict_gas_price handler to retrieve the necessary data.
    async def fetch_gas_prices(chain_id: int = 1) -> Dict:
        """Fetch gas price predictions from Blocknative API for a given chain."""
        try:
            headers = {"Authorization": BLOCKNATIVE_API_KEY} if BLOCKNATIVE_API_KEY else {}
            async with httpx.AsyncClient() as client:
                response = await client.get(
                    BLOCKNATIVE_GAS_API_URL,
                    headers=headers,
                    params={"chainid": chain_id}
                )
                response.raise_for_status()
                data = response.json()
            
            # Extract relevant fields from the response
            block_prices = data.get("blockPrices", [])
            if not block_prices:
                return {"error": "No block prices found in API response"}
            
            # Use the first block's data
            first_block = block_prices[0]
            return {
                "baseFeePerGas": first_block.get("baseFeePerGas", 0),
                "estimatedPrices": first_block.get("estimatedPrices", []),
                "unit": data.get("unit", "gwei"),
                "system": data.get("system", "unknown"),
                "network": data.get("network", "unknown")
            }
        except httpx.HTTPError as e:
            return {"error": f"Failed to fetch gas prices for chain ID {chain_id}: {str(e)}"}
  • The @mcp.tool() decorator registers the predict_gas_price function as an MCP tool with the name derived from the function name.
    @mcp.tool()
  • The docstring provides the input schema description for the tool, including parameters chain_id and ctx.
    """
    Predict gas prices for a specified chain, including base fee and detailed prediction data in a Markdown table.
    
    Parameters:
    - chain_id (int): The ID of the blockchain network (e.g., 1 for Ethereum Mainnet). Default: 1.
    - ctx (Optional[Context]): The MCP context object. Default: None.
    """
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 output format ('Markdown table') but doesn't describe what the prediction entails (e.g., time horizon, confidence intervals, data sources), whether it's cached or real-time, potential rate limits, or error conditions. For a prediction 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 appropriately sized and front-loaded with the core purpose in the first sentence. The parameter section is clear but could be more integrated. There's minimal waste, though the 'ctx' explanation in the schema (not the description) suggests some context could be condensed if included in the description itself.

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

Completeness2/5

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

Given the complexity of a prediction tool with no annotations, no output schema, and 0% schema description coverage, the description is incomplete. It lacks details on prediction methodology, output structure beyond 'Markdown table', error handling, and differentiation from siblings. This makes it inadequate for reliable agent use without additional context.

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 provides basic semantics for 'chain_id' (ID of blockchain network with an example) and notes 'ctx' is optional with a default, but doesn't explain what 'Context' does or why it might be needed. The description adds some value but doesn't fully compensate for the schema coverage gap, especially for the 'ctx' parameter.

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: 'Predict gas prices for a specified chain, including base fee and detailed prediction data in a Markdown table.' This specifies the verb ('predict'), resource ('gas prices'), and output format ('Markdown table'). However, it doesn't explicitly differentiate from sibling tools like 'estimate_gas_cost' or 'get_supported_chains', 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 its siblings ('estimate_gas_cost' and 'get_supported_chains'). It mentions the chain_id parameter but doesn't explain when prediction is appropriate versus estimation or chain listing. There's no mention of prerequisites, limitations, or alternative scenarios.

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/kukapay/blocknative-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server