MCP-ABI

MCP-ABI

Enables interaction with Ethereum-compatible smart contracts through their ABI, allowing both read operations (querying state) and write operations (executing transactions) dynamically based on the contract's interface.

Category
Visit Server

README

MCP-ABI: Model Context Protocol Server for Smart Contract ABI Interactions

This project implements a Model Context Protocol (MCP) server to interact with Ethereum-compatible smart contracts using their ABI (Application Binary Interface). It allows MCP-compatible clients (like AI assistants, IDE extensions, or custom applications) to dynamically generate and execute smart contract interactions based on contract ABIs.

This server is built using TypeScript and fastmcp.

Features (MCP Tools)

The server dynamically exposes tools based on the provided contract ABI. Each function in the ABI becomes an available MCP tool:

  • Read Functions (view/pure): Query contract state without sending transactions
    • Example: CONTRACT_BALANCE_OF, CONTRACT_TOTAL_SUPPLY, CONTRACT_NAME
    • Parameters: Function-specific parameters as defined in the ABI
  • Write Functions: Execute state-changing transactions on the contract
    • Example: CONTRACT_TRANSFER, CONTRACT_APPROVE, CONTRACT_MINT
    • Parameters: Function-specific parameters as defined in the ABI
    • Requires WALLET_PRIVATE_KEY in the environment

All tools are automatically prefixed with the contract name (e.g., ERC20_TRANSFER for an ERC20 contract).

Prerequisites

Installation

There are a few ways to use mcp-abi:

1. Using pnpm dlx (Recommended for most MCP client setups):

You can run the server directly using pnpm dlx without needing a global installation. pnpm dlx is a command that allows you to run packages without installing them globally. This is often the easiest way to integrate with MCP clients. See the "Running the Server with an MCP Client" section for examples. (pnpm dlx is pnpm's equivalent of npx)

2. Global Installation from npm (via pnpm):

Install the package globally to make the mcp-abi command available system-wide:

pnpm add -g @iqai/mcp-abi

If you install globally, you may need to set up environment variables for the mcp-abi command to be recognized system-wide.

3. Building from Source (for development or custom modifications):

  1. Clone the repository:

    git clone https://github.com/IQAIcom/mcp-abi.git
    cd mcp-abi
    
  2. Install dependencies:

    pnpm install
    
  3. Build the server: This compiles the TypeScript code to JavaScript in the dist directory.

    pnpm run build
    

    The prepare script also runs pnpm run build, so dependencies are built upon installation if you clone and run pnpm install.

Configuration (Environment Variables)

This MCP server requires certain environment variables to be set by the MCP client that runs it. These are typically configured in the client's MCP server definition (e.g., in a mcp.json file for Cursor, or similar for other clients).

  • WALLET_PRIVATE_KEY: (Required for write functions)

    • The private key of the wallet to be used for signing and sending transactions to the blockchain.
    • Security Note: Handle this private key with extreme care. Ensure it is stored securely and only provided to trusted MCP client configurations.
  • CONTRACT_ABI: (Required)

    • The JSON string representation of the contract's ABI.
    • This defines which functions will be available as MCP tools.
  • CONTRACT_ADDRESS: (Required)

    • The deployed contract address on the blockchain.
  • CONTRACT_NAME: (Optional, defaults to "CONTRACT")

    • A friendly name for the contract, used as a prefix for generated tool names.
  • CHAIN_ID: (Optional, defaults to Fraxtal (252))

    • The blockchain network chain ID to interact with.
  • RPC_URL: (Optional)

    • Custom RPC endpoint URL. If not provided, uses default RPC for the specified chain.

Running the Server with an MCP Client

MCP clients (like AI assistants, IDE extensions, etc.) will run this server as a background process. You need to configure the client to tell it how to start your server.

Below is an example configuration snippet that an MCP client might use (e.g., in a mcp_servers.json or similar configuration file). This example shows how to run the server using the published npm package via pnpm dlx. This configuration defines an MCP server named "smart-contract-abi" that executes the pnpm dlx @iqai/mcp-abi command with the specified environment variables.

{
  "mcpServers": {
    "smart-contract-abi": {
      "command": "pnpm",
      "args": ["dlx", "@iqai/mcp-abi"],
      "env": {
        "WALLET_PRIVATE_KEY": "your_wallet_private_key_here",
        "CONTRACT_ABI": "[{\"inputs\":[{\"internalType\":\"address\",\"name\":\"account\",\"type\":\"address\"}],\"name\":\"balanceOf\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"to\",\"type\":\"address\"},{\"internalType\":\"uint256\",\"name\":\"amount\",\"type\":\"uint256\"}],\"name\":\"transfer\",\"outputs\":[{\"internalType\":\"bool\",\"name\":\"\",\"type\":\"bool\"}],\"stateMutability\":\"nonpayable\",\"type\":\"function\"}]",
        "CONTRACT_ADDRESS": "0xaB195B090Cc60C1EFd4d1cEE94Bf441F5931C01b",
        "CONTRACT_NAME": "ERC20",
        "CHAIN_ID": "252",
        "RPC_URL": "https://rpc.frax.com"
      }
    }
  }
}

Alternative if Globally Installed:

If you have installed mcp-abi globally (pnpm add -g @iqai/mcp-abi), you can simplify the command and args. This configuration defines an MCP server named "smart-contract-abi" that executes the mcp-abi command with the specified environment variables.

{
  "mcpServers": {
    "smart-contract-abi": {
      "command": "mcp-abi",
      "args": [],
      "env": {
        "WALLET_PRIVATE_KEY": "your_wallet_private_key_here",
        "CONTRACT_ABI": "[{\"inputs\":[{\"name\":\"to\",\"type\":\"address\"},{\"name\":\"amount\",\"type\":\"uint256\"}],\"name\":\"transfer\",\"outputs\":[{\"name\":\"\",\"type\":\"bool\"}],\"stateMutability\":\"nonpayable\",\"type\":\"function\"}]",
        "CONTRACT_ADDRESS": "0xaB195B090Cc60C1EFd4d1cEE94Bf441F5931C01b",
        "CONTRACT_NAME": "ERC20",
        "CHAIN_ID": "252"
      }
    }
  }
}
  • command: The executable to run.
    • For pnpm dlx: "pnpm" (with "dlx" as the first arg)
    • For global install: "mcp-abi"
  • args: An array of arguments to pass to the command.
    • For pnpm dlx: ["dlx", "@iqai/mcp-abi"]
    • For global install: []
  • env: An object containing environment variables to be set when the server process starts. This is where you provide WALLET_PRIVATE_KEY, CONTRACT_ABI, CONTRACT_ADDRESS, and other configuration options.

Example Usage Scenarios

ERC20 Token Contract:

  • Check token balance: Use ERC20_BALANCE_OF tool with an address parameter
  • Transfer tokens: Use ERC20_TRANSFER tool with recipient address and amount
  • Check allowances: Use ERC20_ALLOWANCE tool with owner and spender addresses
  • Approve spending: Use ERC20_APPROVE tool with spender address and amount

NFT Contract (ERC721):

  • Check token ownership: Use NFT_OWNER_OF tool with token ID
  • Transfer NFT: Use NFT_TRANSFER_FROM tool with from address, to address, and token ID
  • Mint new token: Use NFT_MINT tool with recipient address and token metadata

Response Format

Read Functions:

āœ… Successfully called balanceOf
Result: "1000000000000000000"

Write Functions:

āœ… Successfully executed transfer
Transaction hash: 0x123abc...
You can view this transaction on the blockchain explorer.

Error Handling

The server provides comprehensive error handling for various blockchain interaction scenarios:

  • 🚨 Invalid function arguments - "āŒ Error parsing arguments: [specific error]"
  • šŸ”„ Transaction failures - "āŒ Error with [function]: [error message]"
  • šŸ”’ Access control errors - "āŒ Error with [function]: execution reverted"
  • 🌐 Network errors - "āŒ Error with [function]: network connection failed"
  • šŸ’² Insufficient funds - "āŒ Error with [function]: insufficient funds for gas"
  • šŸ“„ ABI parsing errors - "āŒ Invalid ABI format: [specific error]"
  • šŸ  Contract address errors - "āŒ Invalid contract address: [address]"

Security Considerations

  • Store private keys securely and never commit them to version control
  • Use environment variables for sensitive configuration
  • Validate all contract interactions before execution
  • Consider using hardware wallets or secure key management solutions for production use
  • Always test interactions on testnets before mainnet deployment

Recommended Servers

playwright-mcp

playwright-mcp

A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.

Official
Featured
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.

Official
Featured
Local
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.

Official
Featured
Local
TypeScript
VeyraX MCP

VeyraX MCP

Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.

Official
Featured
Local
Kagi MCP Server

Kagi MCP Server

An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.

Official
Featured
Python
graphlit-mcp-server

graphlit-mcp-server

The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.

Official
Featured
TypeScript
Qdrant Server

Qdrant Server

This repository is an example of how to create a MCP server for Qdrant, a vector search engine.

Official
Featured
Neon Database

Neon Database

MCP server for interacting with Neon Management API and databases

Official
Featured
Exa Search

Exa Search

A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.

Official
Featured
E2B

E2B

Using MCP to run code via e2b.

Official
Featured