This implementation adds comprehensive support for executing Foundry and Hardhat commands through the Remix MCP Server, allowing AI agents to interact with these development frameworks.
-
Added method:
runCommand(commandArgs: string)- Executes any Foundry command (forge, cast, anvil)
- Validates commands to ensure they start with allowed tools
- Captures stdout and stderr
- Logs output to Remix terminal
- Returns exit code and output
-
Updated methods list: Added
'runCommand'to the profile
-
Added method:
runCommand(commandArgs: string)- Executes any Hardhat command
- Validates commands to ensure they are Hardhat commands
- Captures stdout and stderr
- Logs output to Remix terminal
- Returns exit code and output
-
Updated methods list: Added
'runCommand'to the profile
FoundryRunCommandHandler
- Tool name:
foundry_run_command - Executes any Foundry command (forge, cast, anvil)
- Validates command format
- Returns execution results including stdout, stderr, and exit code
HardhatRunCommandHandler
- Tool name:
hardhat_run_command - Executes any Hardhat command
- Validates command format (must be hardhat or npx hardhat)
- Returns execution results including stdout, stderr, and exit code
GetFoundryHardhatInfoHandler
- Added comprehensive information about command execution tools
- Included example commands for various operations:
- Testing (forge test, npx hardhat test)
- Deployment scripts (forge script, npx hardhat run)
- Contract interaction (cast commands)
- Local nodes (anvil, npx hardhat node)
Updated createFoundryHardhatTools() to include:
foundry_run_command- Execute any Foundry commandhardhat_run_command- Execute any Hardhat command
Total tools: 7 (up from 5)
Testing:
forge test- Run all testsforge test -vvv- Verbose test outputforge test --match-test testName- Run specific testforge test --match-contract ContractName- Run tests for specific contract
Scripts:
forge script scripts/Deploy.s.sol- Run deployment scriptforge script scripts/Deploy.s.sol --rpc-url $URL --broadcast- Deploy and broadcast
Contract Interaction (Cast):
cast call <address> "method(args)" <params>- Call contract methodcast send <address> "method(args)" <params>- Send transactioncast balance <address>- Check balance
Development:
anvil- Start local Ethereum nodeforge build- Build contractsforge clean- Clean build artifacts
Testing:
npx hardhat test- Run all testsnpx hardhat test --grep "pattern"- Run specific testsnpx hardhat coverage- Generate coverage report
Deployment:
npx hardhat run scripts/deploy.js- Run deployment scriptnpx hardhat run scripts/deploy.js --network <network>- Deploy to specific network
Verification:
npx hardhat verify --network <network> <address> <args>- Verify contract
Development:
npx hardhat node- Start local Hardhat nodenpx hardhat console- Interactive consolenpx hardhat accounts- List accountsnpx hardhat compile- Compile contractsnpx hardhat clean- Clean artifacts
Foundry:
- Commands MUST start with:
forge,cast, oranvil - Validation occurs at both handler and plugin level
- Invalid commands are rejected with clear error messages
Hardhat:
- Commands MUST be Hardhat commands
- Must start with
hardhatornpx hardhat - Validation occurs at both handler and plugin level
- Invalid commands are rejected with clear error messages
- Commands execute in the current working directory only
- stdout and stderr are captured and logged
- Exit codes are returned for error handling
- No arbitrary shell commands allowed
- Shell execution is scoped to validated framework commands
Foundry:
{
"name": "foundry_run_command",
"arguments": {
"command": "forge test -vvv"
}
}Hardhat:
{
"name": "hardhat_run_command",
"arguments": {
"command": "npx hardhat test --grep 'MyTest'"
}
}Foundry:
{
"name": "foundry_run_command",
"arguments": {
"command": "forge script scripts/Deploy.s.sol --rpc-url http://localhost:8545 --broadcast"
}
}Hardhat:
{
"name": "hardhat_run_command",
"arguments": {
"command": "npx hardhat run scripts/deploy.js --network localhost"
}
}{
"name": "foundry_run_command",
"arguments": {
"command": "cast call 0x123... \"balanceOf(address)\" 0xabc..."
}
}Foundry (Anvil):
{
"name": "foundry_run_command",
"arguments": {
"command": "anvil"
}
}Hardhat:
{
"name": "hardhat_run_command",
"arguments": {
"command": "npx hardhat node"
}
}Success response includes:
success: true/falsemessage: Description of what was executedcommand: The command that was runexitCode: Exit code from the commandstdout: Standard outputstderr: Standard error output
Example:
{
"success": true,
"message": "Foundry command executed successfully: forge test",
"command": "forge test",
"exitCode": 0,
"stdout": "Running 10 tests...\nAll tests passed!",
"stderr": ""
}libs/remix-ai-core/src/remix-mcp-server/handlers/FoundryHardhatHandler.ts(initial creation in previous PR)libs/remix-ai-core/src/remix-mcp-server/handlers/FoundryHardhatHandler.README.mdFOUNDRY_HARDHAT_COMMAND_IMPLEMENTATION.md(this file)
-
apps/remixdesktop/src/plugins/foundryPlugin.ts- Added
runCommandmethod - Updated profile methods list
- Added
-
apps/remixdesktop/src/plugins/hardhatPlugin.ts- Added
runCommandmethod - Updated profile methods list
- Added
-
libs/remix-ai-core/src/remix-mcp-server/handlers/FoundryHardhatHandler.ts- Added
FoundryRunCommandHandlerclass - Added
HardhatRunCommandHandlerclass - Updated
GetFoundryHardhatInfoHandlerto include command execution info - Updated
createFoundryHardhatTools()to register new handlers
- Added
-
libs/remix-ai-core/src/remix-mcp-server/handlers/FoundryHardhatHandler.README.md- Added documentation for new command handlers
- Added security section
- Added usage examples
- Flexibility: AI agents can now execute any Foundry or Hardhat command, not just compile
- Testing: Full test suite execution with custom flags and filters
- Deployment: Run deployment scripts with network configurations
- Contract Interaction: Use Cast to interact with deployed contracts
- Development: Start local nodes, run console, and more
- Security: Command validation prevents arbitrary code execution
- Observability: All output is logged to Remix terminal for visibility
The implementation seamlessly integrates with Remix IDE:
- Terminal output shows command execution in real-time
- File watchers sync compilation artifacts automatically
- Working directory context maintained across commands
- Plugin architecture ensures clean separation of concerns
Potential improvements:
- Add timeout configuration for long-running commands
- Support for command cancellation
- Better handling of interactive commands
- Command history and replay functionality
- Preset command templates for common operations