This directory contains the MCP (Model Context Protocol) server implementation for Mythril, allowing clients to interact with Mythril's security analysis capabilities through the standardized MCP protocol.
MCP (Model Context Protocol) is an open protocol that standardizes how applications provide context to LLMs. It allows AI assistants and other clients to access tools and resources through a uniform interface.
- Install Mythril with MCP support:
pip install -e .This will install all dependencies including the mcp package and make the mythril2-mcp-server command available.
The MCP server runs locally and communicates via stdio (standard input/output). To start the server:
mythril2-mcp-serverThe server will start and listen for MCP protocol messages on stdin, responding on stdout.
To use the Mythril MCP server with MCP-compatible clients (like Claude Desktop, Cline, etc.), add it to your MCP client configuration.
Add this to your Claude Desktop configuration file (claude_desktop_config.json):
{
"mcpServers": {
"mythril2": {
"command": "mythril2-mcp-server",
"args": []
}
}
}In VS Code with Cline extension, add to your MCP settings:
{
"mythril2": {
"command": "mythril2-mcp-server"
}
}The Mythril MCP server exposes the following tools:
Analyzes a Solidity smart contract for security vulnerabilities.
Parameters:
contract_code(string, optional): Solidity source code or bytecode to analyzecontract_address(string, optional): Blockchain address to analyze (alternative to contract_code)solc_version(string, optional): Solidity compiler version (e.g., '0.8.0')max_depth(integer, optional): Maximum recursion depth for symbolic execution (default: 128)execution_timeout(integer, optional): Execution timeout in seconds (default: 86400)strategy(string, optional): Search strategy: 'dfs' or 'bfs' (default: 'dfs')enable_onchain_data(boolean, optional): Enable fetching onchain storage data (default: false)
Example:
{
"contract_code": "pragma solidity ^0.8.0; contract Test { ... }"
}Disassembles EVM bytecode into readable assembly instructions.
Parameters:
contract_code(string, optional): Solidity source code or bytecode to disassemblecontract_address(string, optional): Blockchain address to disassemble
Example:
{
"contract_code": "0x6060604052..."
}Lists all available security detection modules in Mythril.
Parameters: None
Once configured with an MCP client, you can use natural language to interact with Mythril:
- "Analyze this smart contract for security vulnerabilities: [paste contract code]"
- "Disassemble this bytecode: 0x6060604052..."
- "What security detectors are available in Mythril?"
The MCP server:
- Listens for JSON-RPC requests on stdin
- Processes requests using Mythril's core analysis engine
- Returns results via stdout in MCP protocol format
- Logs diagnostic information to stderr
Make sure you've installed the package:
pip install -e .Verify that:
- The
mythril2-mcp-servercommand is in your PATH - Your MCP client configuration uses the correct command
- Check stderr output for error messages
Common issues:
- Missing Solidity compiler: Install with
pip install py-solc-x - Invalid contract code: Ensure the code is valid Solidity or bytecode
- Timeout issues: Increase
execution_timeoutparameter
To modify the MCP server:
- Edit
/home/runner/work/mythril2.0/mythril2.0/mythril/mcp_server.py - Test your changes:
python -m mythril2.mcp_server
This server implements MCP protocol version 1.0 and supports:
- Tool listing and invocation
- Stdio transport
- Standard error handling
- The MCP server runs locally on your machine
- It has access to your local filesystem for reading contract files
- When
enable_onchain_datais true, it will connect to Ethereum nodes - All communication happens via local stdio (no network exposure)
Contributions are welcome! Please see the main CONTRIBUTING.md file for guidelines.
MIT License - see LICENSE file for details.