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.
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
- Example:
- 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_KEYin the environment
- Example:
All tools are automatically prefixed with the contract name (e.g., ERC20_TRANSFER for an ERC20 contract).
Prerequisites
- Node.js (v18 or newer recommended)
- pnpm (See https://pnpm.io/installation)
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):
-
Clone the repository:
git clone https://github.com/IQAIcom/mcp-abi.git cd mcp-abi -
Install dependencies:
pnpm install -
Build the server: This compiles the TypeScript code to JavaScript in the
distdirectory.pnpm run buildThe
preparescript also runspnpm run build, so dependencies are built upon installation if you clone and runpnpm 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"
- For
args: An array of arguments to pass to the command.- For
pnpm dlx:["dlx", "@iqai/mcp-abi"] - For global install:
[]
- For
env: An object containing environment variables to be set when the server process starts. This is where you provideWALLET_PRIVATE_KEY,CONTRACT_ABI,CONTRACT_ADDRESS, and other configuration options.
Example Usage Scenarios
ERC20 Token Contract:
- Check token balance: Use
ERC20_BALANCE_OFtool with an address parameter - Transfer tokens: Use
ERC20_TRANSFERtool with recipient address and amount - Check allowances: Use
ERC20_ALLOWANCEtool with owner and spender addresses - Approve spending: Use
ERC20_APPROVEtool with spender address and amount
NFT Contract (ERC721):
- Check token ownership: Use
NFT_OWNER_OFtool with token ID - Transfer NFT: Use
NFT_TRANSFER_FROMtool with from address, to address, and token ID - Mint new token: Use
NFT_MINTtool 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
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。