Skip to main content
Glama
blockscout

Blockscout MCP Server

Official

get_contract_abi

Read-only

Retrieve smart contract ABIs to format function calls and interpret blockchain data, enabling interaction with contracts on supported chains.

Instructions

Get smart contract ABI (Application Binary Interface). An ABI defines all functions, events, their parameters, and return types. The ABI is required to format function calls or interpret contract data.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
chain_idYesThe ID of the blockchain
addressYesSmart contract address

Implementation Reference

  • The core handler function that fetches the smart contract ABI from the Blockscout API using the provided chain_id and address. It reports progress, makes the API request, extracts the ABI, and returns a standardized ToolResponse.
    @log_tool_invocation
    async def get_contract_abi(
        chain_id: Annotated[str, Field(description="The ID of the blockchain")],
        address: Annotated[str, Field(description="Smart contract address")],
        ctx: Context,
    ) -> ToolResponse[ContractAbiData]:
        """
        Get smart contract ABI (Application Binary Interface).
        An ABI defines all functions, events, their parameters, and return types. The ABI is required to format function calls or interpret contract data.
        """  # noqa: E501
        api_path = f"/api/v2/smart-contracts/{address}"
    
        # Report start of operation
        await report_and_log_progress(
            ctx,
            progress=0.0,
            total=2.0,
            message=f"Starting to fetch contract ABI for {address} 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 contract ABI...",
        )
    
        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 contract ABI.",
        )
    
        # Extract the ABI from the API response as it is
        abi_data = ContractAbiData(abi=response_data.get("abi"))
    
        return build_tool_response(data=abi_data)
  • Pydantic model defining the output data structure for the get_contract_abi tool, containing the ABI as a list of dictionaries.
    # --- Model for get_contract_abi Data Payload ---
    class ContractAbiData(BaseModel):
        """A structured representation of a smart contract's ABI."""
    
        abi: list[dict[str, Any]] | None = Field(
            description="The Application Binary Interface (ABI) of the smart contract."
        )
  • MCP server registration of the get_contract_abi tool, including annotations for title, readOnlyHint, etc.
    mcp.tool(
        structured_output=False,
        annotations=create_tool_annotations("Get Contract ABI"),
    )(get_contract_abi)
Behavior4/5

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

Annotations already declare readOnlyHint=true and destructiveHint=false, indicating a safe read operation. The description adds valuable context by explaining what an ABI is and its purpose (formatting function calls, interpreting data), which helps the agent understand the tool's role beyond just being a read operation. It doesn't mention rate limits or authentication needs, but with annotations covering safety, this is acceptable.

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 front-loaded with the core purpose in the first sentence, followed by explanatory context that earns its place by clarifying the ABI's role. It uses three concise sentences with no redundant information, making it efficient and well-structured.

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 (2 parameters, read-only operation) and rich annotations (readOnlyHint, openWorldHint), the description is mostly complete. It explains the tool's purpose and the ABI's utility, though it doesn't detail output format or error cases, which is a minor gap since there's no output schema.

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 clear descriptions for both parameters ('chain_id' as blockchain ID, 'address' as smart contract address). The description doesn't add any parameter-specific details beyond what the schema provides, such as format examples or constraints, so it meets the baseline of 3 for high schema 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 smart contract ABI') and resource ('Application Binary Interface'), with additional explanation of what an ABI defines. It distinguishes this tool from siblings like 'inspect_contract_code' (which likely retrieves bytecode) and 'read_contract' (which likely executes contract functions).

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

Usage Guidelines3/5

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

The description implies usage by explaining that 'The ABI is required to format function calls or interpret contract data,' suggesting this tool is needed before using contract interaction tools. However, it doesn't explicitly state when to use this tool versus alternatives like 'inspect_contract_code' or provide clear exclusions.

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