Skip to main content
Glama

getChainById

Retrieve blockchain details by chain ID. Input a numeric chain identifier to get name, native currency, RPC endpoints, and explorers in Markdown format.

Instructions

Retrieve information about a blockchain by its chain ID, returned as Markdown.

**Parameters**:
- `chain_id` (integer): The unique identifier of the blockchain (e.g., 1 for Ethereum Mainnet).

**Returns**:
- A Markdown-formatted string containing the chain's details (Name, Chain ID, Native Currency, TVL, RPC Endpoints, Explorers) or an error message if no chain is found.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
chain_idYes

Implementation Reference

  • main.py:67-81 (handler)
    The main handler function for the 'getChainById' tool, decorated with @mcp.tool() for registration. It fetches chain data, searches for the chain by ID, formats the details as Markdown using helper functions, or returns an error if not found. The docstring provides the input schema (chain_id: int) and output description.
    async def getChainById(chain_id: int) -> str:
        """
        Retrieve information about a blockchain by its chain ID, returned as Markdown.
    
        **Parameters**:
        - `chain_id` (integer): The unique identifier of the blockchain (e.g., 1 for Ethereum Mainnet).
    
        **Returns**:
        - A Markdown-formatted string containing the chain's details (Name, Chain ID, Native Currency, TVL, RPC Endpoints, Explorers) or an error message if no chain is found.
        """
        chains = await fetch_chain_data()
        for chain in chains:
            if chain.get("chainId") == chain_id:
                return format_chain_as_markdown(chain)
        return f"**Error**: No chain found with ID {chain_id}"
  • main.py:14-22 (helper)
    Helper function to fetch and cache the list of all chains from the Chainlist API, used by getChainById.
    async def fetch_chain_data() -> list[Dict[str, Any]]:
        """Fetch and cache chain data from Chainlist API."""
        global chain_data
        if chain_data is None:
            async with httpx.AsyncClient() as client:
                response = await client.get("https://chainlist.org/rpcs.json")
                response.raise_for_status()
                chain_data = response.json()
        return chain_data
  • main.py:24-64 (helper)
    Helper function to format a single chain's data into a Markdown string with tables for RPC endpoints and explorers, used by getChainById.
    def format_chain_as_markdown(chain: Dict[str, Any]) -> str:
        """
        Format a single chain's details as Markdown, extracting specified fields with RPC and Explorers as tables.
        """
        # Extract required fields
        name = chain.get('name', 'N/A')
        chain_id = chain.get('chainId', 'N/A')
        native_currency = chain.get('nativeCurrency', {})
        tvl = chain.get('tvl', 'N/A')
        rpc_list = chain.get('rpc', [])
        explorers_list = chain.get('explorers', [])
    
        # Format native currency
        currency_info = f"{native_currency.get('name', 'N/A')} ({native_currency.get('symbol', 'N/A')}, {native_currency.get('decimals', 'N/A')} decimals)" if native_currency else 'N/A'
    
        # Format RPC list as a table
        rpc_data = [[rpc.get('url', 'N/A'), rpc.get('tracking', 'N/A')] for rpc in rpc_list]
        rpc_output = "**RPC Endpoints**:\n"
        if rpc_data:
            rpc_output += tabulate(rpc_data, headers=["URL", "Tracking"], tablefmt="pipe")
        else:
            rpc_output += "None"
    
        # Format explorers list as a table
        explorers_data = [[explorer.get('name', 'N/A'), explorer.get('url', 'N/A'), explorer.get('standard', 'N/A')] for explorer in explorers_list]
        explorers_output = "**Explorers**:\n"
        if explorers_data:
            explorers_output += tabulate(explorers_data, headers=["Name", "URL", "Standard"], tablefmt="pipe")
        else:
            explorers_output += "None"
    
        # Combine all fields
        return f"""**Chain Details**
    - **Name**: {name}
    - **Chain ID**: {chain_id}
    - **Native Currency**: {currency_info}
    - **TVL**: {tvl}
    {rpc_output}
    
    {explorers_output}
    """
Behavior4/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 effectively describes the tool's behavior: it retrieves information, returns Markdown-formatted details or an error message if not found, and lists the specific details included (Name, Chain ID, etc.). However, it doesn't mention potential rate limits, authentication needs, or performance characteristics.

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 well-structured and front-loaded with the core purpose, followed by clearly labeled sections for parameters and returns. Every sentence adds value, with no redundant or unnecessary information, making it efficient and easy to parse.

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

Completeness5/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 (single parameter, no output schema, no annotations), the description is complete. It explains what the tool does, when to use it, parameter details, return format, and error handling. No additional information is needed for effective use.

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 schema description coverage is 0%, so the description must fully compensate. It provides comprehensive parameter semantics: it names the parameter ('chain_id'), specifies its type ('integer'), gives a clear example ('1 for Ethereum Mainnet'), and explains its purpose ('unique identifier of the blockchain'). This adds significant value beyond the bare schema.

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 ('Retrieve information about a blockchain') and resource ('by its chain ID'), distinguishing it from the sibling tool 'getChainsByKeyword' which searches by keyword rather than ID. The purpose is unambiguous and well-defined.

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 ('by its chain ID') and implies an alternative with the sibling tool name 'getChainsByKeyword', suggesting that tool should be used for keyword-based searches. This provides clear guidance on 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/kukapay/chainlist-mcp'

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