|
1 | | -# foundry-mcp-server |
| 1 | +# Foundry MCP Server |
2 | 2 |
|
3 | | -To install dependencies: |
| 3 | +A simple, lightweight and fast MCP (Model Context Protocol) server that provides Solidity development capabilities using the Foundry toolchain (Forge, Cast, and Anvil). |
4 | 4 |
|
5 | | -```bash |
6 | | -bun install |
7 | | -``` |
| 5 | +## Overview |
| 6 | + |
| 7 | +This server connects LLM assistants to the Foundry ecosystem, enabling them to: |
| 8 | + |
| 9 | +- Interact with nodes (local Anvil instances or remote RPC endpoints) |
| 10 | +- Analyze smart contracts and blockchain data |
| 11 | +- Perform common EVM operations using Cast |
| 12 | +- Manage, deploy, and execute Solidity code and scripts |
| 13 | +- Work with a persistent Forge workspace |
| 14 | + |
| 15 | +## Features |
| 16 | + |
| 17 | +### Network Interaction |
| 18 | + |
| 19 | +- Start and manage local Anvil instances |
| 20 | +- Connect to any remote network (just specify the RPC) |
| 21 | +- Get network/chain information |
| 22 | + |
| 23 | +### Contract Interaction |
| 24 | + |
| 25 | +- Call contract functions (read-only) |
| 26 | +- Send transactions to contracts (if `PRIVATE_KEY` is configured) |
| 27 | +- Get transaction receipts |
| 28 | +- Read contract storage |
| 29 | +- Analyze transaction traces |
| 30 | +- Retrieve contract ABIs and sources from block explorers |
| 31 | + |
| 32 | +### Solidity Development |
| 33 | + |
| 34 | +- Maintain a dedicated Forge workspace |
| 35 | +- Create and edit Solidity files |
| 36 | +- Install dependencies |
| 37 | +- Run Forge scripts |
| 38 | +- Deploy contracts |
| 39 | + |
| 40 | +### Utility Functions |
| 41 | + |
| 42 | +- Calculate contract addresses |
| 43 | +- Check contract bytecode size |
| 44 | +- Estimate gas costs |
| 45 | +- Convert between units (hex to decimals, etc.,) |
| 46 | +- Generate wallets |
| 47 | +- Get event logs |
| 48 | +- Lookup function and event signatures |
| 49 | + |
| 50 | +## Usage |
| 51 | + |
| 52 | +The server is designed to be used as an MCP tool provider for MCP Clients. When connected to a client, it enables the clients(claude desktop, cursor, client, etc.,) to perform Solidity and onchain operations directly. |
| 53 | + |
| 54 | + |
| 55 | +#### Requirements |
| 56 | + |
| 57 | +- Node.js v18+ |
| 58 | +- Foundry toolchain (Forge, Cast, Anvil) |
| 59 | + |
| 60 | +### Setup |
8 | 61 |
|
9 | | -To run: |
| 62 | +1. Ensure Foundry tools (Forge, Cast, Anvil) are installed on your system: |
| 63 | + ``` |
| 64 | + curl -L https://foundry.paradigm.xyz | bash |
| 65 | + foundryup |
| 66 | + ``` |
| 67 | +2. Clone and build the server. |
10 | 68 |
|
11 | | -```bash |
12 | | -bun run index.ts |
| 69 | + ```sh |
| 70 | + bun build |
| 71 | + ``` |
| 72 | + |
| 73 | +3. Update your client config: |
| 74 | + |
| 75 | +```json |
| 76 | + "mcpServers": { |
| 77 | + "foundry": { |
| 78 | + "command": "node", |
| 79 | + "args": [ |
| 80 | + "path/to/foundry-mcp-server/dist/index.js" |
| 81 | + ], |
| 82 | + "env" :{ |
| 83 | + "PRIVATE_KEY": "0x1234", |
| 84 | + } |
| 85 | + } |
| 86 | + } |
13 | 87 | ``` |
14 | 88 |
|
15 | | -This project was created using `bun init` in bun v1.1.26. [Bun](https://bun.sh) is a fast all-in-one JavaScript runtime. |
| 89 | +#### Configuration |
| 90 | + |
| 91 | +The server supports the following environment variables: |
| 92 | + |
| 93 | +- `RPC_URL`: Default RPC URL to use when none is specified (optional) |
| 94 | +- `PRIVATE_KEY`: Private key to use for transactions (optional) |
| 95 | + |
| 96 | +### Workspace |
| 97 | + |
| 98 | +The server maintains a persistent Forge workspace at `~/.mcp-foundry-workspace` for all Solidity files, scripts, and dependencies. |
| 99 | + |
| 100 | +## Tools |
| 101 | + |
| 102 | +### Anvil (Local EVM Node) |
| 103 | + |
| 104 | +- `anvil_start`: Start a new Anvil instance |
| 105 | +- `anvil_stop`: Stop a running Anvil instance |
| 106 | +- `anvil_status`: Check if Anvil is running and get its status |
| 107 | + |
| 108 | +### Cast (Onchain Operations) |
| 109 | + |
| 110 | +- `cast_call`: Call a contract function (read-only) |
| 111 | +- `cast_send`: Send a transaction to a contract function |
| 112 | +- `cast_balance`: Check the ETH balance of an address |
| 113 | +- `cast_receipt`: Get the transaction receipt |
| 114 | +- `cast_storage`: Read contract storage at a specific slot |
| 115 | +- `cast_run`: Run a published transaction in a local environment |
| 116 | +- `cast_logs`: Get logs by signature or topic |
| 117 | +- `cast_sig`: Get the selector for a function or event signature |
| 118 | +- `cast_4byte`: Lookup function or event signature from the 4byte directory |
| 119 | +- `cast_chain`: Get information about the current chain |
| 120 | + |
| 121 | +### Forge (Development Operations) |
| 122 | + |
| 123 | +- `forge_script`: Run a Forge script from the workspace |
| 124 | +- `install_dependency`: Install a dependency for the Forge workspace |
| 125 | + |
| 126 | +### File Management |
| 127 | + |
| 128 | +- `create_solidity_file`: Create or update a Solidity file in the workspace |
| 129 | +- `read_file`: Read the content of a file from the workspace |
| 130 | +- `list_files`: List files in the workspace |
| 131 | + |
| 132 | +### Utilities |
| 133 | + |
| 134 | +- `convert_eth_units`: Convert between EVM units (wei, gwei, hex) |
| 135 | +- `generate_wallet`: Generate a new EVM wallet |
| 136 | +- `compute_address`: Compute the address of a contract that would be deployed |
| 137 | +- `contract_size`: Get the bytecode size of a deployed contract |
| 138 | +- `estimate_gas`: Estimate the gas cost of a transaction |
| 139 | + |
0 commit comments