Skip to main content
Glama

getGasPrice

Retrieve current gas prices in slow, normal, and fast tiers with Gwei and estimated USD costs for EVM chains.

Instructions

현재 가스비를 slow/normal/fast 3단계로 조회합니다 (Gwei + USD 예상 비용)

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
chainNoEVM 체인ethereum

Implementation Reference

  • The core handler function that fetches gas estimates from the RPC client and calculates gas costs.
    async function handler(args: z.infer<typeof inputSchema>): Promise<ToolResult<GasPriceData>> {
      const { chain } = args;
    
      const cacheKey = `gas:${chain}`;
      const cached = cache.get<GasPriceData>(cacheKey);
      if (cached.hit) return makeSuccess(chain, cached.data, true);
    
      try {
        const client = getClient(chain);
    
        const [block, maxPriorityFee] = await Promise.all([
          client.getBlock({ blockTag: "latest" }),
          client.estimateMaxPriorityFeePerGas(),
        ]);
    
        const baseFee = block.baseFeePerGas ?? 0n;
    
        const prioritySlow = maxPriorityFee * 80n / 100n;
        const priorityNormal = maxPriorityFee;
        const priorityFast = maxPriorityFee * 150n / 100n;
    
        const maxFeeSlow = baseFee + prioritySlow;
        const maxFeeNormal = baseFee + priorityNormal;
        const maxFeeFast = baseFee + priorityFast;
    
        let ethPriceUsd = 0;
        try {
          const nativeCoingeckoId = getNativeCoingeckoId(chain);
          if (nativeCoingeckoId) {
            const priceData = await getPrice(nativeCoingeckoId);
            ethPriceUsd = priceData.priceUsd;
          }
        } catch {
          // 가격 조회 실패해도 가스비 자체는 반환
        }
    
        function calcCostUsd(maxFeeGwei: bigint): number {
          if (ethPriceUsd === 0) return 0;
          const costWei = maxFeeGwei * STANDARD_GAS;
          const costEth = Number(costWei) / 1e18;
          return Math.round(costEth * ethPriceUsd * 10000) / 10000;
        }
    
        const data: GasPriceData = {
          slow: {
            maxFeePerGas: formatGwei(maxFeeSlow),
            maxPriorityFeePerGas: formatGwei(prioritySlow),
            estimatedCostUsd: calcCostUsd(maxFeeSlow),
          },
          normal: {
            maxFeePerGas: formatGwei(maxFeeNormal),
            maxPriorityFeePerGas: formatGwei(priorityNormal),
            estimatedCostUsd: calcCostUsd(maxFeeNormal),
          },
          fast: {
            maxFeePerGas: formatGwei(maxFeeFast),
            maxPriorityFeePerGas: formatGwei(priorityFast),
            estimatedCostUsd: calcCostUsd(maxFeeFast),
          },
          baseFee: formatGwei(baseFee),
          lastBlock: Number(block.number),
        };
    
        cache.set(cacheKey, data, GAS_CACHE_TTL);
        return makeSuccess(chain, data, false);
      } catch (err) {
        const message = sanitizeError(err);
        return makeError(`Failed to fetch gas price: ${message}`, "RPC_ERROR");
      }
    }
  • Input validation schema for the getGasPrice tool.
    const inputSchema = z.object({
      chain: z.enum(SUPPORTED_CHAINS).default("ethereum").describe("EVM 체인"),
    });
  • Tool registration for getGasPrice in the MCP server.
    export function register(server: McpServer) {
      server.tool(
        "getGasPrice",
        "현재 가스비를 slow/normal/fast 3단계로 조회합니다 (Gwei + USD 예상 비용)",
        inputSchema.shape,
        async (args) => {
          const result = await handler(args as z.infer<typeof inputSchema>);
          return { content: [{ type: "text" as const, text: JSON.stringify(result, null, 2) }] };
        },
      );
    }
Behavior4/5

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

With no annotations provided, the description carries the full disclosure burden. It successfully compensates by detailing the response structure (3-tier speed levels) and units (Gwei plus USD conversion), giving the agent clear expectations of what data structure will be returned despite the lack of output schema.

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?

Single sentence with parenthetical clarification is optimally efficient. Every element earns its place: verb (조회합니다), resource (가스비), granularity (3단계), and output format (Gwei + USD). No redundant words.

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?

For a simple single-parameter read operation, the description adequately compensates for the missing output schema by describing the expected return structure (three speed tiers with dual currency units). Given the tool's simplicity, this level of detail is sufficient.

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?

Input schema has 100% coverage with the 'chain' parameter well-documented as 'EVM 체인'. The description does not mention the parameter, but with complete schema coverage, the baseline score of 3 is appropriate as no compensation is needed.

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?

Description clearly states the tool retrieves (조회합니다) current gas prices using specific tiers (slow/normal/fast) and output format (Gwei + USD). However, it does not explicitly distinguish from sibling tool 'compareGas', which likely serves a similar but distinct purpose.

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?

No guidance provided on when to use this tool versus alternatives like 'compareGas', nor are there any prerequisites or conditions mentioned. The user must infer appropriate usage from the tool name alone.

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/calintzy/evmscope'

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