Skip to main content
Glama
blockscout

Blockscout MCP Server

Official

get_latest_block

Read-only

Retrieve the most recent indexed blockchain block number and timestamp to establish a reference point for API calls and ensure data accuracy.

Instructions

Get the latest indexed block number and timestamp, which represents the most recent state of the blockchain. No transactions or token transfers can exist beyond this point, making it useful as a reference timestamp for other API calls.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
chain_idYesThe ID of the blockchain

Implementation Reference

  • The core handler function implementing the get_latest_block tool. Fetches latest block data from Blockscout API using chain_id, processes the response, and returns a ToolResponse with LatestBlockData.
    @log_tool_invocation
    async def get_latest_block(
        chain_id: Annotated[str, Field(description="The ID of the blockchain")], ctx: Context
    ) -> ToolResponse[LatestBlockData]:
        """
        Get the latest indexed block number and timestamp, which represents the most recent state of the blockchain.
        No transactions or token transfers can exist beyond this point, making it useful as a reference timestamp for other API calls.
        """  # noqa: E501
        api_path = "/api/v2/main-page/blocks"
    
        # Report start of operation
        await report_and_log_progress(
            ctx,
            progress=0.0,
            total=2.0,
            message=f"Starting to fetch latest block info on chain {chain_id}...",
        )
    
        base_url = await get_blockscout_base_url(chain_id)
    
        # Report progress after resolving Blockscout URL
        await report_and_log_progress(
            ctx,
            progress=1.0,
            total=2.0,
            message="Resolved Blockscout instance URL. Fetching latest block data...",
        )
    
        response_data = await make_blockscout_request(base_url=base_url, api_path=api_path)
    
        # Report completion
        await report_and_log_progress(
            ctx,
            progress=2.0,
            total=2.0,
            message="Successfully fetched latest block data.",
        )
    
        # The API returns a list. Extract data from the first item
        if response_data and isinstance(response_data, list) and len(response_data) > 0:
            first_block = response_data[0]
            # The main idea of this tool is to provide the latest block number of the chain.
            # The timestamp is provided to be used as a reference timestamp for other API calls.
            block_data = LatestBlockData(
                block_number=first_block.get("height"),
                timestamp=first_block.get("timestamp"),
            )
            return build_tool_response(data=block_data)
    
        # Handle cases with no data by raising an error
        raise ValueError("Could not retrieve latest block data from the API.")
  • Registration of the get_latest_block tool in the FastMCP server instance with annotations and structured_output=False.
    mcp.tool(
        structured_output=False,
        annotations=create_tool_annotations("Get Latest Block"),
    )(get_latest_block)
  • Pydantic model defining the structure of the latest block data payload returned by the tool.
    class LatestBlockData(BaseModel):
        """Represents the essential data for the latest block."""
    
        block_number: int = Field(description="The block number (height) in the blockchain")
        timestamp: str = Field(description="The timestamp when the block was mined (ISO format)")
Behavior4/5

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

Annotations already provide readOnlyHint=true, destructiveHint=false, and openWorldHint=true, covering safety and scope. The description adds valuable context beyond this: it clarifies that the data is 'indexed' (implying potential lag from real-time), specifies the return includes 'block number and timestamp,' and notes the limitation about transactions/token transfers. No contradiction with annotations.

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 two sentences, front-loaded with the core purpose, followed by usage context. Every sentence adds value: the first defines the tool, and the second explains its utility and limitations. No wasted words or redundancy.

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 low complexity (one parameter, read-only, no output schema), the description is largely complete. It covers purpose, usage, and behavioral context. However, it could slightly improve by hinting at the return format (e.g., structured data with fields) since there's no output schema, but the annotations and clarity mitigate this gap.

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 100%, with the parameter 'chain_id' fully documented in the schema as 'The ID of the blockchain.' The description does not add any additional meaning or clarification about this parameter beyond what the schema provides, so it meets the baseline for high coverage.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the specific action ('Get the latest indexed block number and timestamp') and resource ('blockchain'), distinguishing it from siblings like get_block_info (which retrieves details for a specific block) or get_chains_list (which lists available chains). It precisely defines what the tool returns.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines5/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description explicitly states when to use this tool: 'useful as a reference timestamp for other API calls.' It also implies when not to use it by noting 'No transactions or token transfers can exist beyond this point,' suggesting alternatives like get_transactions_by_address for transaction data beyond this reference.

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/blockscout/mcp-server'

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