Skip to main content
Glama

estimate-gas

Calculate transaction gas costs before execution to optimize fees and prevent failures in MetaMask MCP blockchain operations.

Instructions

Estimate the gas necessary to complete a transaction without submitting it to the network.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
toYesThe transaction recipient or contract address.
dataNoA contract hashed method call with encoded args.
valueNoValue in wei sent with this transaction.
maxFeePerGasNoTotal fee per gas in wei, inclusive of maxPriorityFeePerGas.
maxPriorityFeePerGasNoMax priority fee per gas in wei.
chainIdNoChain ID to validate against before sending transaction.

Implementation Reference

  • Handler function that executes the gas estimation logic using wagmi's estimateGas, returns the estimated gas as JSON, and handles TransactionExecutionError or other errors by returning error messages in MCP content format.
    execute: async (args) => {
      try {
        const result = await estimateGas(wagmiConfig, args);
        return {
          content: [
            {
              type: "text",
              text: JSONStringify({
                hash: result,
              }),
            },
          ],
        };
      }
      catch (error) {
        if (error instanceof TransactionExecutionError) {
          return {
            content: [
              {
                type: "text",
                text: error.cause.message,
              },
            ],
          };
        }
        return {
          content: [
            {
              type: "text",
              text: (error as Error).message,
            },
          ],
        };
      }
    },
  • Zod schema defining the input parameters for the estimate-gas tool including to, data, value, fee parameters, and chainId.
    parameters: z.object({
      to: Address.describe("The transaction recipient or contract address."),
      data: Address.optional().describe("A contract hashed method call with encoded args."),
      value: z.coerce.bigint().optional().describe("Value in wei sent with this transaction."),
      maxFeePerGas: z.coerce.bigint().optional().describe("Total fee per gas in wei, inclusive of maxPriorityFeePerGas."),
      maxPriorityFeePerGas: z.coerce.bigint().optional().describe("Max priority fee per gas in wei."),
      chainId: z.coerce.number().optional().describe("Chain ID to validate against before sending transaction."),
    }),
  • The server.addTool registration of the 'estimate-gas' tool, defining name, description, input schema, and execute handler.
    server.addTool({
      name: "estimate-gas",
      description: "Estimate the gas necessary to complete a transaction without submitting it to the network.",
      parameters: z.object({
        to: Address.describe("The transaction recipient or contract address."),
        data: Address.optional().describe("A contract hashed method call with encoded args."),
        value: z.coerce.bigint().optional().describe("Value in wei sent with this transaction."),
        maxFeePerGas: z.coerce.bigint().optional().describe("Total fee per gas in wei, inclusive of maxPriorityFeePerGas."),
        maxPriorityFeePerGas: z.coerce.bigint().optional().describe("Max priority fee per gas in wei."),
        chainId: z.coerce.number().optional().describe("Chain ID to validate against before sending transaction."),
      }),
      execute: async (args) => {
        try {
          const result = await estimateGas(wagmiConfig, args);
          return {
            content: [
              {
                type: "text",
                text: JSONStringify({
                  hash: result,
                }),
              },
            ],
          };
        }
        catch (error) {
          if (error instanceof TransactionExecutionError) {
            return {
              content: [
                {
                  type: "text",
                  text: error.cause.message,
                },
              ],
            };
          }
          return {
            content: [
              {
                type: "text",
                text: (error as Error).message,
              },
            ],
          };
        }
      },
    });
  • Call to registerEstimateGasTools function as part of the central registerTools, which registers the estimate-gas tool.
    registerEstimateGasTools(server, wagmiConfig);
Behavior2/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 states the tool estimates gas without submitting, which implies it's read-only and non-destructive, but doesn't mention potential limitations like network dependency, error conditions, or whether it requires specific permissions. For a tool with zero annotation coverage, this leaves significant gaps in understanding its behavior.

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 a single, efficient sentence that immediately conveys the core purpose without any wasted words. It's perfectly front-loaded with the essential information, making it easy for an AI agent to parse quickly.

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

Completeness3/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 (6 parameters, no output schema, no annotations), the description is minimally adequate. It explains what the tool does but lacks information about return values, error handling, or network requirements. Without annotations or output schema, the agent must infer behavioral details, making this description incomplete for optimal tool selection.

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?

The description adds no parameter-specific information beyond what's already in the schema, which has 100% coverage with detailed descriptions for all 6 parameters. According to the rules, when schema_description_coverage is high (>80%), the baseline is 3 even with no param info in the description, which applies here.

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 ('estimate the gas necessary') and resource ('to complete a transaction'), distinguishing it from siblings like 'send-transaction' (which submits) and 'estimate-fee-per-gas' (which estimates fees rather than total gas). It explicitly mentions 'without submitting it to the network', which clarifies its non-executive nature.

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

Usage Guidelines4/5

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

The description provides clear context for when to use this tool ('without submitting it to the network'), implying it's for pre-transaction planning. However, it doesn't explicitly state when not to use it or name alternatives like 'send-transaction' for actual execution, which would have earned a perfect score.

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/Xiawpohr/metamask-mcp'

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