feat: Add MCP server for AI agent integration with fuzzing controls#1508
Closed
datradito wants to merge 1669 commits intocrytic:dev-agentsfrom
Closed
feat: Add MCP server for AI agent integration with fuzzing controls#1508datradito wants to merge 1669 commits intocrytic:dev-agentsfrom
datradito wants to merge 1669 commits intocrytic:dev-agentsfrom
Conversation
This also updates nixpkgs, secp256k1, and GHC to 9.8.4
Use `nix develop .#fuzz` to get a shell with Echidna, Slither, crytic-compile, Z3, and Foundry, and be ready to fuzz some projects.
This should allow the use of GHC 9.8 on Linux
This is now correctly managed by nixpkgs, see https://github.com/NixOS/nixpkgs/blob/eb7fd13a93f04e89405eb72dc8b6ddee44996bb3/pkgs/development/libraries/ncurses/default.nix#L42-L51
Update `hevm`, move to GHC 9.8
…18 (crytic#1393) Bumps [DeterminateSystems/nix-installer-action](https://github.com/determinatesystems/nix-installer-action) from 17 to 18. - [Release notes](https://github.com/determinatesystems/nix-installer-action/releases) - [Commits](DeterminateSystems/nix-installer-action@v17...v18) --- updated-dependencies: - dependency-name: DeterminateSystems/nix-installer-action dependency-version: '18' dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Update CHANGELOG, fix typos and grammar
The current shrinking implementation has a bug/limitation: it always tries to shrink the sender. In other words, if a transaction has a sender that is not minimal, Echidna will try to reduce it. However, the transaction might require a different sender to still cause the assertion failure, and the fact that Echidna will unconditionally try to lower it might cause the shrinking to get 'stuck'. This allows the sender shrinker to keep the transaction source the same with some probability, allowing the shrinking to proceed in such cases.
Allow address to stay the same during shrinking
Echidna was not accounting for the intrinsic cost of a transaction.
Ensures that gas is reasonable, accounting for the intrinsic gas cost
The property was set to less than the minimum intrinsic cost.
Improve contract address collection
Implements feature 001-mcp-agent-commands with 9 MCP tools: - 6 observability tools: read_logs, show_coverage, dump_lcov, get_corpus_size, inspect_corpus_transactions, find_transaction_in_corpus - 3 control tools: inject_transaction, prioritize_function, clear_priorities Key changes: - Fixed spawnMCPServer to properly call runMCPServer (CRITICAL) - Implemented 90% priority weighting in genInteractionsM (lib/Echidna/ABI.hs) - Created complete Python test suite with JSON schemas (tests/mcp/) - Added Haskell integration tests (src/test/Tests/Integration.hs) - Created Solidity test contracts (SimpleToken.sol, EchidnaMCPTest.sol) - Extended Bus with InjectTransaction and PrioritizeFunction commands - Added EventLog ring buffer (2500 entries) to Env - Implemented MCP command logging for reproducibility Design documentation: - specs/001-mcp-agent-commands/data-model.md (7 entities) - specs/001-mcp-agent-commands/plan.md (architecture & tech stack) - specs/001-mcp-agent-commands/quickstart.md (15-min integration guide) - specs/001-mcp-agent-commands/contracts/tool-schemas.md (JSON schemas) Progress: 68/76 tasks (89%) Status: Ready for build validation after C dependency installation See MCP_IMPLEMENTATION_STATUS.md for full technical documentation.
… features # Conflicts: # flake.nix # lib/Echidna.hs # lib/Echidna/Agent/Fuzzer.hs # lib/Echidna/Agent/Symbolic.hs # lib/Echidna/Execution.hs # lib/Echidna/MCP.hs # lib/Echidna/Transaction.hs # lib/Echidna/Types/Campaign.hs # lib/Echidna/Types/Config.hs # lib/Echidna/Types/InterWorker.hs # lib/Echidna/UI.hs # lib/Echidna/Worker.hs # stack.yaml
- Implemented EchidnaLangGraphAgent for autonomous fuzzing guidance. - Added methods for analyzing state, deciding actions, injecting transactions, and resetting priorities. - Created a decision graph for managing agent workflow. - Included example usage and connectivity checks in the main function. feat: Introduce simple AI agent for Echidna MCP server - Developed EchidnaMCPAgent for monitoring and guiding fuzzing campaigns. - Implemented methods for calling MCP tools, getting status, coverage, and injecting transactions. - Added autonomous monitoring loop with transaction injection on coverage stagnation. feat: Enhance MCP server with command logging functionality - Added logging for control commands in mcp-commands.jsonl for reproducibility. - Implemented log flushing mechanism to periodically save command logs. - Updated MCP server to handle logging for inject_fuzz_transactions and clear_fuzz_priorities tools. fix: Update MCP server and UI to use correct port configuration - Changed references from serverPort to mcpPort in UI and server initialization. - Ensured MCP server runs with correct logging and worker references. test: Add integration tests for MCP command logging - Created tests to verify logging of control commands and observability tools. - Ensured chronological order of logged commands and proper log file creation.
02c9c02 to
81c4529
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR adds a Model Context Protocol (MCP) server to Echidna, enabling AI agents to observe and control fuzzing campaigns in real-time. The server exposes 7 JSON-RPC tools over HTTP for monitoring coverage, inspecting corpus, and injecting targeted test cases.
Key Changes
Core Implementation
MCP Server (
lib/Echidna/MCP.hs)/mcp)--mcp-portflagFuzzer Agent Enhancements (
lib/Echidna/Agent/Fuzzer.hs)Event System (
lib/Echidna/Types/MCP.hs)Bus Extension (
lib/Echidna/Types/InterWorker.hs)FuzzSequence,SetPriority,ClearPrioritiesBug Fixes
lib/Echidna/UI.hsto checkmcpPortinstead ofserverPort(lines 116, 217)Testing & Documentation
Python integration test suite (
tests/mcp/)EchidnaMCPTest.sol,SimpleToken.solClient validation script (
test-mcp-client.py)Agent integration examples (
examples/)simple_agent.py: Autonomous monitoring agentlanggraph_agent.py: LLM-powered agent with ClaudeREADME.md: Integration guideComprehensive documentation
AGENT_TESTING_GUIDE.md: Testing and troubleshootingspecs/001-mcp-agent-commands/: Feature specification with 20 FRs, 10 SCsConfiguration
--mcp-port <port>CLI option to enable MCP servercorpus/mcp-commands.jsonlfor reproducibility.gitignorefor MCP artifactsImplementation Notes
Worker Probability Strategy
Worker 0 always injects at corpus position 0 with 90% probability for consistent exploration. Other workers use linearly scaled probabilities (20-90%) based on campaign size to balance coverage.
Server Lifecycle
The MCP server runs throughout the fuzzing campaign and shuts down when testing completes. This is by design - agents should spawn Echidna per test session rather than maintaining persistent connections.
Protocol Choice
Uses JSON-RPC 2.0 over HTTP (not WebSockets) for simplicity and firewall compatibility. The
/mcpendpoint is hardcoded per MCP protocol conventions.Discussion Points
IORefwith atomic operations for lock-free readsRelated Issues
Testing