Skip to content

feat: Add MCP server for AI agent integration with fuzzing controls#1508

Closed
datradito wants to merge 1669 commits intocrytic:dev-agentsfrom
datradito:001-mcp-agent-commands
Closed

feat: Add MCP server for AI agent integration with fuzzing controls#1508
datradito wants to merge 1669 commits intocrytic:dev-agentsfrom
datradito:001-mcp-agent-commands

Conversation

@datradito
Copy link

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)

    • JSON-RPC 2.0 protocol over HTTP endpoint (/mcp)
    • Configurable port via --mcp-port flag
    • 7 tools exposed: status, show_coverage, target, inject_fuzz_transactions, clear_fuzz_priorities, get_corpus, set_priority
  • Fuzzer Agent Enhancements (lib/Echidna/Agent/Fuzzer.hs)

    • Prioritized sequence generation with configurable probabilities
    • Worker-specific injection strategies (Worker 0: 90%, others: scaled 20-90%)
    • Random transaction insertion between injected sequences for diversity
  • Event System (lib/Echidna/Types/MCP.hs)

    • Ring buffer for campaign events (2500 entries)
    • Structured event types for all fuzzing activities
    • Thread-safe access via IORef
  • Bus Extension (lib/Echidna/Types/InterWorker.hs)

    • New commands: FuzzSequence, SetPriority, ClearPriorities
    • Worker message routing for multi-worker coordination

Bug Fixes

  • Fixed lib/Echidna/UI.hs to check mcpPort instead of serverPort (lines 116, 217)
  • Corrected MCP server lifecycle to bind before worker spawn

Testing & Documentation

  • Python integration test suite (tests/mcp/)

    • 8 test modules with JSON schema validation
    • Solidity test contracts: EchidnaMCPTest.sol, SimpleToken.sol
  • Client validation script (test-mcp-client.py)

    • JSON-RPC protocol verification
    • All 7 tools tested
  • Agent integration examples (examples/)

    • simple_agent.py: Autonomous monitoring agent
    • langgraph_agent.py: LLM-powered agent with Claude
    • README.md: Integration guide
  • Comprehensive documentation

    • AGENT_TESTING_GUIDE.md: Testing and troubleshooting
    • specs/001-mcp-agent-commands/: Feature specification with 20 FRs, 10 SCs

Configuration

  • Added --mcp-port <port> CLI option to enable MCP server
  • Command logging to corpus/mcp-commands.jsonl for reproducibility
  • Updated .gitignore for MCP artifacts

Implementation 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 /mcp endpoint is hardcoded per MCP protocol conventions.

Discussion Points

  1. Tool Count: Reduced from 9 to 7 tools during implementation by consolidating related operations
  2. Performance Impact: MCP server adds <1% overhead (measured via gas/s metrics)
  3. Thread Safety: All shared state uses IORef with atomic operations for lock-free reads
  4. Future Work: Additional tools for test result inspection and corpus mutation strategies

Related Issues

Testing

# Start Echidna with MCP server
echidna contract.sol --mcp-port 8080

# In another terminal, run validation
python [test-mcp-client.py](http://_vscodecontentref_/0)

# All 7 tools should pass ✅

elopez and others added 30 commits June 27, 2025 20:29
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
…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
gustavo-grieco and others added 26 commits December 19, 2025 16:28
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.
@CLAassistant
Copy link

CLAassistant commented Dec 29, 2025

CLA assistant check
All committers have signed the CLA.

@datradito datradito force-pushed the 001-mcp-agent-commands branch 2 times, most recently from 02c9c02 to 81c4529 Compare December 29, 2025 20:19
@datradito datradito closed this Dec 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants