foundry-mcp

foundry-mcp

An MCP server providing 80+ tools for Foundry Ethereum development, enabling AI assistants to compile, test, deploy smart contracts, interact with EVM chains, and manage local nodes via Forge, Cast, Anvil, and Chisel.

Category
访问服务器

README

@maxencerb/foundry-mcp

A comprehensive Model Context Protocol (MCP) server for the Foundry Ethereum development toolkit. This server enables AI assistants like Claude to interact with Forge, Cast, Anvil, and Chisel directly.

Features

  • 80+ Tools covering all major Foundry commands
  • Resources for project configuration, ABIs, bytecode, and documentation
  • Prompts for common workflows (deployment, testing, security review)
  • Self-documenting with live --help integration and official docs fetching

Tools Overview

Category Tools Description
Forge 18 Build, test, deploy, verify contracts
Cast 38 Interact with EVM chains, encode/decode data
Anvil 16 Local node management, state manipulation
Chisel 6 Solidity REPL operations
Help 6 Live documentation from --help flags

Prerequisites

# Install Foundry
curl -L https://foundry.paradigm.xyz | bash
foundryup

Installation

# Using bun
bunx @maxencerb/foundry-mcp

# Or install globally
bun install -g @maxencerb/foundry-mcp

Usage

With Claude Code

Add the MCP server using the CLI:

# Add with environment variables
claude mcp add --transport stdio --env RPC_URL=http://localhost:8545 foundry -- bunx @maxencerb/foundry-mcp

# Or add project-scoped (creates .mcp.json)
claude mcp add --transport stdio --scope project foundry -- bunx @maxencerb/foundry-mcp

Or create a .mcp.json file in your project root:

{
  "mcpServers": {
    "foundry": {
      "command": "bunx",
      "args": ["@maxencerb/foundry-mcp"],
      "env": {
        "RPC_URL": "${RPC_URL:-http://localhost:8545}"
      }
    }
  }
}

With Claude Desktop

Add to your Claude Desktop configuration (~/Library/Application Support/Claude/claude_desktop_config.json on macOS):

{
  "mcpServers": {
    "foundry": {
      "command": "bunx",
      "args": ["@maxencerb/foundry-mcp"],
      "env": {
        "RPC_URL": "http://localhost:8545"
      }
    }
  }
}

With Other MCP Clients

# Run the server directly
bunx @maxencerb/foundry-mcp

# Or if installed globally
foundry-mcp

Environment Variables

Variable Description Default
RPC_URL Default RPC endpoint for chain interactions -
PRIVATE_KEY Default private key for transactions (⚠️ testing only) -
FOUNDRY_PROJECT Path to Foundry project Current directory

Available Tools

Forge Tools

Tool Description
forge_init Initialize a new Foundry project
forge_build Compile Solidity contracts
forge_test Run tests with filtering and forking
forge_coverage Generate test coverage reports
forge_script Execute deployment scripts
forge_create Deploy a single contract
forge_verify Verify contracts on block explorers
forge_inspect Inspect ABI, bytecode, storage layout
forge_flatten Flatten contract sources
forge_remappings Show import remappings
forge_tree Show dependency tree
forge_clean Remove build artifacts
forge_install Install dependencies
forge_update Update dependencies
forge_fmt Format Solidity code
forge_snapshot Generate gas snapshots
forge_doc Generate documentation
forge_selectors List function selectors

Cast Tools

Chain & Block: cast_block, cast_block_number, cast_chain, cast_chain_id, cast_client, cast_gas_price, cast_base_fee

Account: cast_balance, cast_nonce, cast_code, cast_storage

Transactions: cast_call, cast_send, cast_publish, cast_tx, cast_receipt, cast_run, cast_estimate, cast_logs

Encoding/Decoding: cast_abi_encode, cast_abi_decode, cast_calldata, cast_calldata_decode, cast_sig, cast_sig_event, cast_4byte, cast_4byte_decode

Utilities: cast_to_wei, cast_from_wei, cast_to_hex, cast_to_dec, cast_to_base, cast_keccak, cast_resolve_name, cast_lookup_address, cast_compute_address, cast_create2, cast_interface, cast_age, cast_wallet_new, cast_wallet_address, cast_wallet_sign, cast_format_bytes32, cast_parse_bytes32, cast_concat_hex

Anvil Tools

Tool Description
anvil_start Start a local Ethereum node
anvil_stop Stop a running node
anvil_status Check node status
anvil_mine Mine blocks
anvil_setBalance Set account balance
anvil_setCode Set contract bytecode
anvil_setStorageAt Set storage slot value
anvil_impersonateAccount Impersonate an account
anvil_stopImpersonatingAccount Stop impersonating
anvil_snapshot Create state snapshot
anvil_revert Revert to snapshot
anvil_setNextBlockTimestamp Set next block timestamp
anvil_increaseTime Increase block time
anvil_setAutomine Toggle auto-mining
anvil_reset Reset fork state
anvil_getAccounts List dev accounts

Chisel Tools

Tool Description
chisel_eval Evaluate Solidity expression
chisel_run Run Solidity statements
chisel_list List saved sessions
chisel_load Load a session
chisel_view View session source
chisel_clear_cache Clear cache

Help Tools

Tool Description
forge_help Get forge CLI help (supports subcommands)
cast_help Get cast CLI help (supports subcommands)
anvil_help Get anvil CLI help
chisel_help Get chisel CLI help
foundry_version Get installed Foundry versions
foundry_list_commands List available commands for a tool

Available Resources

Resource URI Description
Config foundry://config Project's foundry.toml
Remappings foundry://remappings Import remappings
Contracts foundry://contracts List of .sol files
ABI foundry://abi/{contract} Contract ABI
Bytecode foundry://bytecode/{contract} Contract bytecode
Storage Layout foundry://storage-layout/{contract} Storage layout
Method IDs foundry://method-identifiers/{contract} Function selectors
Gas Estimates foundry://gas-estimates/{contract} Gas estimates
Documentation foundry://docs Official Foundry docs
Doc Links foundry://docs/links Documentation URLs

Available Prompts

Prompt Description
deploy_contract Guide for deploying a contract
debug_test Help debug a failing test
write_test Generate tests for a contract
explain_storage Explain storage layout
gas_optimization Review for gas optimization
security_review Security review checklist
fork_test Test against forked state
create_script Create deployment script
lookup_docs Look up command documentation

Development

# Clone the repository
git clone https://github.com/maxencerb/foundry-mcp.git
cd foundry-mcp

# Install dependencies
bun install

# Run in development mode
bun run dev

# Type check
bun run typecheck

# Test with MCP Inspector
bun run inspect

Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Add a changeset: bunx changeset
  4. Submit a pull request

Security Notice

⚠️ Never use private keys with real funds when using this MCP server. LLMs can make mistakes and send unintended transactions. Use only for testing and development with test accounts.

Documentation

License

MIT

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选