Forge Test Mcp

io.github.vschernoff由 GitHub 账号 vschernoff 发布v0.1.0更新于 Oct 29, 2026

Runs Foundry tests and builds; returns compact, structured failures to AI coding agents

已验证STDIO仅桌面开发者工具安全与监控

概览

AI 生成的概览

为 AI 编程助手运行 Foundry 的 forge test 与 forge build,并返回精简、结构化的失败信息,含原因、调用轨迹和 fuzz 反例。

可以做什么
  • 运行 Foundry 测试,支持按测试名、合约、路径过滤,以及 fuzz 次数和轨迹选项,返回统计与每个失败的详情
  • 以高详细度重跑单个失败测试,返回原因、解码后的调用轨迹、回溯和日志
  • 编译项目,把编译器错误和警告以文件、行、列、代码的结构化条目返回
  • 在测试未真正运行时明确报错,例如编译失败、找不到 forge 或超时
适用场景
适合在 Foundry 项目中由助手修改 Solidity 后编译并运行测试,并诊断失败的单元测试、fuzz 测试或不变量测试,而无需粘贴冗长的终端输出。
运行要求
需要 Node.js 22 或更高版本,以及用户自行安装的 Foundry,forge 版本为 1.8.5 或更高的 1.8.x。由于服务器以离线模式运行 forge,需先在终端执行一次 forge build 以安装项目所用的编译器版本。需在 Foundry 项目目录中启动服务器;可选参数可设置根目录、forge 路径、超时、FFI 和严格版本检查。
安装前请注意
运行测试会以你的用户权限执行项目中的 Solidity 和 cheatcode,因此只应在你愿意在终端中自行测试的项目上使用。除非以 --allow-ffi 启动,FFI 默认关闭,但测试本身仍可能访问网络。forge 会加载项目的 .env,对疑似密钥的值的脱敏只是尽力而为,请勿在用于助手测试的项目中放置可花费资产的私钥。任何工具都不会发送交易、部署或签名。

安装

在 SourceWeft 中

  1. 打开 控制台中的 Forge Test Mcp,将其添加到工作区。
  2. 为需要使用其工具的对话启用该服务。

Desktop only,通过 STDIO。 STDIO 服务会启动本地进程,因此需要 SourceWeft 桌面宿主。

其他 MCP 客户端

参照 仓库 中的启动说明。

README

forge-test-mcp

An MCP server that runs Foundry's forge test and forge build and returns compact, structured results an AI coding agent can act on: for every failing test, its kind, the decoded reason, the fuzz counterexample or invariant call sequence, console logs and a short decoded trace. It speaks standard MCP over stdio and is meant for any MCP client (Claude Code, Codex, Cursor, Claude Desktop, Windsurf, …). So far it has been tested with an MCP test client, not yet inside each of those clients.

When forge did not run the tests (a compile error, no matching tests, a timeout, a missing or unsupported forge, …) the tool says so as an error. It never reports "0 failed" for tests that did not run.

Status: 0.1.0, the first release. See CHANGELOG.md for what is in it and what is not yet verified.

Before you use it

  • Running tests runs code. forge test executes the project's Solidity with your user's rights. Use this server only on projects you would test in a terminal yourself.
  • FFI is off unless you start the server with --allow-ffi, even when foundry.toml enables it. forge runs with --offline, but tests can still reach the network themselves, for example through fork cheatcodes.
  • No transactions. No tool sends transactions, deploys, signs or takes a key.
  • Passing tests do not prove a contract is secure.

Details in Security and trust.

Requirements

  • Node.js 22 or later.
  • Foundry with forge 1.8.5 or a later 1.8.x. You install it; this server never installs or updates anything. Newer versions run but are flagged as untested.
  • The project's compiler version installed once: run forge build in a terminal first. The server runs forge with --offline, so it cannot download solc itself.

Configure your MCP client

Start the server in your Foundry project (the directory with foundry.toml, or below it). Most clients accept this mcpServers entry:

json
{  "mcpServers": {    "forge-test": {      "command": "npx",      "args": ["-y", "[email protected]"]    }  }}

Pin an exact version, as above. Client shortcuts, from each vendor's documentation (checked 2026-10-23, not yet verified by running each client):

  • Claude Code: put the JSON above in .mcp.json at the project root. In interactive sessions Claude Code asks you to approve project servers the first time.

  • Cursor: put it in .cursor/mcp.json, adding "type": "stdio" to the server entry.

  • Codex: in .codex/config.toml (loaded for trusted projects only) or ~/.codex/config.toml:

    toml
    [mcp_servers.forge-test]command = "npx"args = ["-y", "[email protected]"]

Docker

The image contains the server and forge 1.8.6, the official static Alpine build. The build checks the download against pinned SHA-256 digests; those digests were taken from the release's provenance attestation and verified when they were pinned. Mount the project at /project and a cache volume at /cache, where forge keeps the compiler:

bash
docker build -t forge-test-mcp .docker run --rm -v "$PWD":/project -v forge-test-mcp-cache:/cache --entrypoint forge forge-test-mcp build

The second command installs the project's solc once, online. Then configure the client to run docker with ["run", "-i", "--rm", "-v", "<project>:/project", "-v", "forge-test-mcp-cache:/cache", "forge-test-mcp"]. forge writes out/ and cache/ into the project, so on Linux add --user "$(id -u):$(id -g)" to both commands.

Options

Options go after the package name in args. Only the user sets them; no tool argument can.

OptionMeaning
--root <dir>Project directory (default: where the client starts the server).
--forge <path>The forge executable (default: forge on PATH).
--timeout <seconds>Stop a forge run after this long (default 300).
--allow-ffiLet tests use FFI cheatcodes when foundry.toml enables them. Off by default; see below.
--strict-versionRefuse forge versions newer than the tested range instead of flagging them.

Tools

ToolWhat it does
run_testsRuns forge test. Filters: match_test, match_contract, match_path; fuzz_runs; traces (default true); max_bytes (default 8192).
explain_failureRe-runs one test at high verbosity and returns only that test: reason, counterexample, logs, backtrace and the decoded trace. Pass the name as run_tests prints it, e.g. "BankTest.test_transfer()".
buildRuns forge build and returns compiler errors and warnings with file, line, column and code. force: true recompiles everything.

None of them sends transactions, deploys, signs or accepts keys.

A failing run_tests result looks like this:

json
{  "status": "failed",  "forge": "1.8.6",  "summary": { "suites": 1, "passed": 1, "failed": 1, "skipped": 0 },  "ffi": "disabled",  "fuzzRuns": { "configured": 256, "used": 256 },  "notRun": [],  "failures": [    {      "test": "SupplyInvariantTest.invariant_supplyMatches()",      "file": "test/Supply.t.sol",      "kind": "invariant",      "reason": "supply mismatch: 6683 != 6355",      "sequence": {        "calls": [          { "call": "Handler.mint(uint256)", "args": "6683", "sender": "0x…022f" },          { "call": "Handler.burnFrom(uint256)", "args": "328", "sender": "0x…054e" }        ],        "shrunkFrom": 4      },      "trace": [        "[21670] SupplyInvariantTest::invariant_supplyMatches()",        "  ├─ [0] VM::assertEq(6683, 6355, \"supply mismatch\") [staticcall]",        "  │   └─ ← [Revert] supply mismatch: 6683 != 6355",        "  └─ ← [Revert] supply mismatch: 6683 != 6355"      ],      "traceLinesOmitted": 16    }  ],  "truncated": null}

Responses stay within the size budget. When there is more than fits, traces and logs go first, then whole failures, and truncated says exactly how many were left out.

When the tests did not run

The result is an MCP error (isError: true) with a code, a message and a hint:

CodeCause
COMPILE_FAILEDThe project does not compile (the first compiler errors are included).
NO_TESTS_RANNo test matched the filters, or every matched test was skipped.
NOT_A_FOUNDRY_PROJECTNo foundry.toml here or above it in the repository.
FORGE_NOT_FOUND, UNSUPPORTED_FORGE_VERSIONforge is missing, or older than 1.8.5.
SOLC_MISSINGRun forge build once in a terminal so forge can install the compiler.
TIMEOUTThe run took longer than --timeout; forge reports nothing until it finishes.
CONFIG_ERROR, INVALID_ARGUMENTS, FORGE_CRASHED, FORGE_FAILED, UNPARSEABLE_OUTPUT, INCONSISTENT_RESULT, OUTPUT_TOO_LARGE, FFI_OVERRIDE_FAILEDforge could not produce a trustworthy report; the message and stderr say why.

Report a problem or suggest an improvement

  • Problem or wrong result: open an issue. Include the version, your client, what was run and the output. Don't include keys, .env contents, RPC URLs with API keys, or code you can't share.
  • Security problem: report it privately, see SECURITY.md.
  • You can ask your coding agent to draft the report from your session. Read it before you post it: nothing is sent unless you send it. This project collects no telemetry.

Security and trust

Running tests runs code. forge test executes the project's Solidity and cheatcodes with your user's rights, just as it does in a terminal. Only use this server on projects you would test in a terminal yourself. It cannot make an untrusted repository safe.

What the server does to reduce that risk:

  • FFI is off unless you opt in. FFI cheatcodes run arbitrary shell commands. forge ignores FOUNDRY_FFI in the environment, so when foundry.toml sets ffi = true the server runs forge with a copy of the resolved configuration that has ffi = false, and checks through forge that it took effect before running anything. Start the server with --allow-ffi if you want FFI.
  • No downloads. forge always runs with --offline, so forge itself makes no network lookups. Tests can still reach the network on their own, for example fork tests through vm.createSelectFork and RPC endpoints.
  • No shell. forge is started with an argument list. Tool arguments are validated and passed as single --flag=value arguments.
  • Secrets. forge loads the project's .env itself, so tests can read and print those values. The server replaces the exact values of variables named like *PRIVATE_KEY*, *MNEMONIC*, *SECRET*, *TOKEN*, *API_KEY* and *RPC_URL* (RPC URLs often embed an API key), from its environment and .env, with [redacted:NAME]. A hex value such as a private key is also caught without 0x, in either case, without leading zeros, and in decimal (as vm.envUint and console.log print it). It cannot catch a secret printed in any other form. Keep spendable keys out of projects you test with an agent.
  • No transactions. No tool broadcasts, deploys, signs or takes a key.

To report a vulnerability, see SECURITY.md.

Passing tests do not prove a contract is secure. They show the tests you wrote pass. Contracts that will hold value need an independent audit.

Foundry compatibility

Tested in CI against forge 1.8.5 and 1.8.6 on Linux, macOS and Windows. Supported range: >=1.8.5 <1.9.0. Older versions are refused. Newer ones run with a forgeUntested note (or are refused with --strict-version).

Development

npm test runs the unit tests. With FORGE_BIN=/path/to/forge it also runs the integration tests against a real forge. npm run lint checks style. Requirement IDs in code and tests (FR-, NFR-, D-) refer to the project's internal specification.

License

MIT © Vitaliy Chernov. See NOTICE for the licences of the dependencies.

来源:README.md,提交 aa4f6e3

工具

3

run_tests

Run `forge test` and return a compact summary: counts, and for each failing test its kind (unit, fuzz, invariant, setup), decoded reason, fuzz counterexample or invariant call sequence, and console logs. isError means the tests did not run (compile error, no matching tests, timeout, missing forge, …); never report that as passing.

输入参数tracesfuzz_runsmax_bytesmatch_pathmatch_testmatch_contract

explain_failure

Re-run one test at high verbosity and return only that test: its reason, decoded call trace (trimmed to the path to the revert when long), backtrace, logs and, for fuzz or invariant tests, the counterexample. Pass the test name as run_tests reports it, e.g. "BankTest.test_transfer()".

输入参数test必填contractmax_bytes

build

Compile the project with `forge build` and return compiler errors and warnings as structured items (file, line, column, code, message). Unchanged files are not recompiled and forge does not repeat their warnings; pass force: true to recompile everything.

输入参数forcemax_bytes

版本历史

1
  1. v0.1.0最新Oct 26, 2026

评分

已满足适用检查项的 90%

该评分衡量此收录条目的完整程度,依据注册中心条目、端点与公开来源计算得出。它不是对服务器本身的评价,也不表示服务器安全或当前可用:可连通性是带日期的检查结果,评分也不包含安装量或用户评价。

  • 近 30 天内可连通25 分
  • 已声明认证方式10 分

    请在注册中心条目中声明凭据请求头,或保持端点能够响应探测,以便判定其认证方式。

  • 已列出工具必需15 分
  • 描述必需15 分
  • 图标10 分
  • 文档15 分
  • 许可证10 分