Skip to main content
Glama
lienhage

Blockchain MCP Server

by lienhage

abi decode

abi-decode

Decode ABI-encoded data by specifying parameter types and input hexadecimal data, simplifying Ethereum blockchain interactions for developers and users.

Instructions

decode abi encoded data

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
dataYeshexadecimal data to decode
typesYesparameter types array, e.g. ['uint256', 'address', 'bool']

Implementation Reference

  • Handler function that cleans input data, decodes using ethers.AbiCoder.decode(types, data), formats decoded values, and returns formatted text response or error.
    async ({ types, data }) => {
      try {
        const cleanData = data.startsWith('0x') ? data : `0x${data}`;
        const decoded = ethers.AbiCoder.defaultAbiCoder().decode(types, cleanData);
        
        const decodedValues = types.map((type, index) => {
          const value = decoded[index];
          return `  ${type}: ${this.formatDecodedValue(value, type)}`;
        }).join('\n');
    
        return {
          content: [{
            type: "text",
            text: `abi decode result:\n\nšŸ“Š original data: ${cleanData}\nšŸ“‹ parameter types: (${types.join(',')})\n\nšŸ“ decoded values:\n${decodedValues}`
          }]
        };
      } catch (error) {
        return {
          content: [{
            type: "text",
            text: `error: ${error instanceof Error ? error.message : String(error)}`
          }],
          isError: true
        };
      }
    }
  • Zod schema for tool inputs: array of ABI types and hex data string.
    inputSchema: {
      types: z.array(z.string()).describe("parameter types array, e.g. ['uint256', 'address', 'bool']"),
      data: z.string().describe("hexadecimal data to decode")
    }
  • Direct registration of the 'abi-decode' tool on the MCP server with schema and handler.
    server.registerTool(
      "abi-decode",
      {
        title: "abi decode",
        description: "decode abi encoded data",
        inputSchema: {
          types: z.array(z.string()).describe("parameter types array, e.g. ['uint256', 'address', 'bool']"),
          data: z.string().describe("hexadecimal data to decode")
        }
      },
      async ({ types, data }) => {
        try {
          const cleanData = data.startsWith('0x') ? data : `0x${data}`;
          const decoded = ethers.AbiCoder.defaultAbiCoder().decode(types, cleanData);
          
          const decodedValues = types.map((type, index) => {
            const value = decoded[index];
            return `  ${type}: ${this.formatDecodedValue(value, type)}`;
          }).join('\n');
    
          return {
            content: [{
              type: "text",
              text: `abi decode result:\n\nšŸ“Š original data: ${cleanData}\nšŸ“‹ parameter types: (${types.join(',')})\n\nšŸ“ decoded values:\n${decodedValues}`
            }]
          };
        } catch (error) {
          return {
            content: [{
              type: "text",
              text: `error: ${error instanceof Error ? error.message : String(error)}`
            }],
            isError: true
          };
        }
      }
    );
  • Helper method used by the handler to format decoded values for display based on ABI type.
    private formatDecodedValue(value: any, type: string): string {
      if (typeof value === 'bigint') {
        return value.toString();
      }
      
      if (type === 'address') {
        return value.toString();
      }
      
      if (type === 'bool') {
        return value ? 'true' : 'false';
      }
      
      if (type.startsWith('bytes')) {
        return value.toString();
      }
      
      if (typeof value === 'string') {
        return `"${value}"`;
      }
      
      return String(value);
    }
  • Registration call in CastCommands that triggers abi-encoder tool registrations including abi-decode.
    this.abiEncoder.registerWithServer(server);
Behavior1/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 but offers no information about the tool's behavior. It doesn't describe what the tool returns (e.g., decoded values in a specific format), error conditions, performance characteristics, or any side effects. The description is too minimal to guide an agent effectively.

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 extremely concise at just three words, with zero wasted language. It's front-loaded with the core purpose, though this brevity comes at the cost of completeness. Every word earns its place by directly addressing the tool's function.

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 ABI decoding (a technical operation with specific input/output expectations), no annotations, and no output schema, the description is insufficiently complete. It doesn't explain what decoded results look like, how errors are handled, or provide examples that would help an agent use the tool correctly in context with sibling tools.

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?

Schema description coverage is 100%, with clear descriptions for both parameters ('data' as hexadecimal data to decode, 'types' as parameter types array). The description adds no additional parameter semantics beyond what the schema provides, but the schema documentation is comprehensive, meeting the baseline for adequate coverage.

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

Purpose2/5

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

The description 'decode abi encoded data' is essentially a tautology that restates the tool name 'abi-decode' with minimal additional information. While it identifies the action (decode) and target (ABI encoded data), it lacks specificity about what ABI decoding entails or what distinguishes it from sibling tools like '4byte-decode' or 'abi-encode'.

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

Usage Guidelines1/5

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

The description provides no guidance on when to use this tool versus alternatives. It doesn't mention sibling tools like '4byte-decode' (which might handle different encoding formats) or 'abi-encode' (the inverse operation), nor does it specify prerequisites or appropriate contexts for ABI decoding.

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

Related 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/lienhage/blockchain-mcp'

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