Skip to main content
Glama

write-contract

Execute write functions on blockchain contracts to modify state or trigger transactions using provided ABI, address, and arguments.

Instructions

Execute a write function on a contract

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
abiYes
addressYes
functionNameYes
argsYes

Implementation Reference

  • Handler function that executes the write-contract tool: parses ABI, calls wagmi's writeContract, returns transaction hash or error message.
    execute: async (_args) => {
      try {
        const abi = JSON.parse(_args.abi) as Abi
        const address = _args.abi as Address
        const functionName = _args.functionName
        const args = _args.args
        const result = await writeContract(wagmiConfig, {
          abi,
          address,
          functionName,
          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 write-contract tool: abi (string), address (string), functionName (string), args (array of strings).
    parameters: z.object({
      abi: z.string(),
      address: z.string(),
      functionName: z.string(),
      args: z.string().array()
    }),
  • Function that registers the write-contract tool on the FastMCP server, including name, description, schema, and handler.
    export function registerWriteContractTools(server: FastMCP): void {
      server.addTool({
        name: "write-contract",
        description: "Execute a write function on a contract",
        parameters: z.object({
          abi: z.string(),
          address: z.string(),
          functionName: z.string(),
          args: z.string().array()
        }),
        execute: async (_args) => {
          try {
            const abi = JSON.parse(_args.abi) as Abi
            const address = _args.abi as Address
            const functionName = _args.functionName
            const args = _args.args
            const result = await writeContract(wagmiConfig, {
              abi,
              address,
              functionName,
              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,
                }
              ]
            }
          }
        },
      });
    };
  • Invocation of the registration function in the main server setup file, adding the tool to the MetaMask MCP server.
    registerWriteContractTools(server);
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 mentions 'write function' which hints at mutation, but fails to detail critical aspects like gas costs, transaction confirmation, error handling, or blockchain effects. This leaves significant gaps in understanding the tool's behavior and risks.

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 with no wasted words, making it easy to parse. It's appropriately sized for a basic tool definition, though this conciseness comes at the cost of detail.

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

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the complexity of blockchain interactions, no annotations, no output schema, and 0% schema coverage, the description is inadequate. It lacks information on return values, error cases, and operational context, making it incomplete for safe and effective use in this environment.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters2/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 0%, so the description must compensate but adds no parameter details. It doesn't explain what 'abi', 'address', 'functionName', or 'args' represent or how to format them (e.g., ABI as JSON string, address as hex). This results in poor semantic support for the 4 required parameters.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose3/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description 'Execute a write function on a contract' states a verb ('execute') and resource ('contract'), but it's vague about what a 'write function' entails compared to siblings like 'read-contract' or 'send-transaction'. It doesn't specify that this modifies blockchain state or involves transactions, leaving the purpose somewhat ambiguous.

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 is provided on when to use this tool versus alternatives such as 'read-contract' (for read-only calls) or 'send-transaction' (for general transactions). The description implies usage for contract writes but doesn't clarify prerequisites, exclusions, or specific contexts, offering minimal practical direction.

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/mcpilot'

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