Skip to main content
Glama

get_chains

Retrieve comprehensive blockchain network details including chain IDs, native tokens, stablecoins, and RPC configurations for EVM and Solana chains.

Instructions

List all supported chains (EVM + Solana) with their chain IDs, native tokens, stablecoins, and RPC configuration status.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • The complete get_chains tool implementation including registration, schema, and handler. The handler calls the API endpoint '/chains' and returns the JSON response containing supported chains with their IDs, native tokens, stablecoins, and RPC configuration status.
    server.tool(
      'get_chains',
      'List all supported chains (EVM + Solana) with their chain IDs, native tokens, ' +
        'stablecoins, and RPC configuration status.',
      {},
      async () => {
        const data = await api('/chains');
        return jsonResponse(data);
      },
    );
  • Helper function used by the get_chains handler to format the API response as MCP tool output with proper content structure.
    function jsonResponse(data: unknown) {
      return { content: [{ type: 'text' as const, text: JSON.stringify(data, null, 2) }] };
    }
  • Core API helper function used by the get_chains handler to make HTTP requests to the AgentWallet REST API. Handles authentication, error handling, and automatic x402 payment processing when needed.
    async function api(path: string, method = 'GET', body?: Record<string, unknown>, extraHeaders?: Record<string, string>): Promise<unknown> {
      const url = `${API_BASE}${path}`;
      const headers: Record<string, string> = {
        'Content-Type': 'application/json',
        ...extraHeaders,
      };
    
      if (API_USER && API_PASS) {
        headers['Authorization'] = 'Basic ' + Buffer.from(`${API_USER}:${API_PASS}`).toString('base64');
      }
    
      const options: RequestInit = { method, headers };
      if (body && method !== 'GET') {
        options.body = JSON.stringify(body);
      }
    
      const res = await fetch(url, options);
      const data = await res.json();
    
      // Handle 402 Payment Required — auto-pay if wallet configured
      if (res.status === 402 && X402_WALLET_ID && !extraHeaders?.['X-PAYMENT']) {
        return handleX402Payment(data as X402Response, path, method, body);
      }
    
      if (!res.ok) {
        const error = (data as { error?: string }).error || `HTTP ${res.status}`;
        throw new Error(error);
      }
    
      return data;
    }

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/hifriendbot/agentwallet-mcp'

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