hardhat_project
Manage Hardhat project lifecycle for Hedera blockchain development. Initialize projects, compile contracts, run tests, and handle configuration for smart contract deployment.
Instructions
Manage Hardhat project lifecycle operations.
OPERATIONS:
init: Initialize new Hardhat project with Hedera configuration
compile: Compile Solidity contracts (with force option)
test: Run Mocha/Chai tests with filtering
clean: Clean artifacts and cache
flatten: Flatten contracts for verification
get_artifacts: Retrieve compiled ABI and bytecode
get_accounts: List available accounts with balances
config_network: Generate Hedera network config snippet
run_task: Execute custom Hardhat task
list_tasks: List all available tasks
USE FOR: Project setup, compilation, testing, and configuration management.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| operation | Yes | Project operation to perform | |
| directory | No | Absolute path to Hardhat project directory (required for all operations except init which creates it) | |
| networks | No | Networks to configure (for init) | |
| solidity | No | Solidity version (for init) | |
| typescript | No | Use TypeScript (for init) | |
| force | No | Force recompilation (for compile) | |
| testFiles | No | Test files to run (for test) | |
| grep | No | Test filter pattern (for test) | |
| network | No | Network name | |
| contractPath | No | Contract file path (for flatten) | |
| contractName | No | Contract name (for get_artifacts) | |
| task | No | Task name (for run_task) | |
| params | No | Task parameters (for run_task) |
Implementation Reference
- src/tools/composite.ts:647-733 (handler)Primary handler function that implements the 'hardhat_project' tool logic. Dispatches to Hardhat-specific operations (init, compile, test, etc.) using imported helpers from hardhat.ts.export async function hardhatProjectManage(args: { operation: 'init' | 'compile' | 'test' | 'clean' | 'flatten' | 'get_artifacts' | 'get_accounts' | 'config_network' | 'run_task' | 'list_tasks'; // Init-specific directory?: string; networks?: Array<'mainnet' | 'testnet' | 'previewnet' | 'local'>; solidity?: string; typescript?: boolean; // Compile-specific force?: boolean; // Test-specific testFiles?: string[]; grep?: string; network?: string; // Flatten-specific contractPath?: string; // Get artifacts-specific contractName?: string; // Run task-specific task?: string; params?: any; }): Promise<ToolResult> { try { logger.info('Hardhat project operation', { operation: args.operation }); switch (args.operation) { case 'init': return await hardhatTools.hardhatInit({ directory: args.directory, networks: args.networks, solidity: args.solidity, typescript: args.typescript, }); case 'compile': return await hardhatTools.hardhatCompile({ force: args.force, directory: args.directory }); case 'test': return await hardhatTools.hardhatTest({ testFiles: args.testFiles, grep: args.grep, network: args.network, directory: args.directory, }); case 'clean': return await hardhatTools.hardhatClean({ directory: args.directory }); case 'flatten': return await hardhatTools.hardhatFlatten({ files: args.contractPath ? [args.contractPath] : undefined, directory: args.directory }); case 'get_artifacts': return await hardhatTools.hardhatGetArtifacts({ contractName: args.contractName, directory: args.directory }); case 'get_accounts': return await hardhatTools.hardhatGetAccounts({ directory: args.directory }); case 'config_network': // Config network generates a config snippet, doesn't require all params return { success: true, data: { network: args.network || 'testnet', message: 'Use hardhat_contract with operation "deploy" and network parameter for actual deployment', }, }; case 'run_task': return await hardhatTools.hardhatRunTask({ task: args.task!, params: args.params, directory: args.directory, }); case 'list_tasks': return await hardhatTools.hardhatListTasks({ directory: args.directory }); default: throw new Error(`Unknown operation: ${args.operation}`); } } catch (error) { logger.error('Hardhat project operation failed', { operation: args.operation, error }); return { success: false, error: error instanceof Error ? error.message : 'Unknown error', }; } }
- src/tools/composite.ts:996-1040 (schema)Input schema and description definition for the 'hardhat_project' tool, exported in hardhatFoundryToolDefinitions array.{ name: 'hardhat_project', description: `Manage Hardhat project lifecycle operations. OPERATIONS: - init: Initialize new Hardhat project with Hedera configuration - compile: Compile Solidity contracts (with force option) - test: Run Mocha/Chai tests with filtering - clean: Clean artifacts and cache - flatten: Flatten contracts for verification - get_artifacts: Retrieve compiled ABI and bytecode - get_accounts: List available accounts with balances - config_network: Generate Hedera network config snippet - run_task: Execute custom Hardhat task - list_tasks: List all available tasks USE FOR: Project setup, compilation, testing, and configuration management.`, inputSchema: { type: 'object' as const, properties: { operation: { type: 'string', enum: ['init', 'compile', 'test', 'clean', 'flatten', 'get_artifacts', 'get_accounts', 'config_network', 'run_task', 'list_tasks'], description: 'Project operation to perform', }, directory: { type: 'string', description: 'Absolute path to Hardhat project directory (required for all operations except init which creates it)' }, networks: { type: 'array', items: { type: 'string', enum: ['mainnet', 'testnet', 'previewnet', 'local'] }, description: 'Networks to configure (for init)', }, solidity: { type: 'string', description: 'Solidity version (for init)' }, typescript: { type: 'boolean', description: 'Use TypeScript (for init)' }, force: { type: 'boolean', description: 'Force recompilation (for compile)' }, testFiles: { type: 'array', items: { type: 'string' }, description: 'Test files to run (for test)' }, grep: { type: 'string', description: 'Test filter pattern (for test)' }, network: { type: 'string', description: 'Network name' }, contractPath: { type: 'string', description: 'Contract file path (for flatten)' }, contractName: { type: 'string', description: 'Contract name (for get_artifacts)' }, task: { type: 'string', description: 'Task name (for run_task)' }, params: { type: 'object', description: 'Task parameters (for run_task)' }, }, required: ['operation'], }, },
- src/index.ts:647-649 (registration)Tool handler registration in the main MCP server request handler switch statement, mapping 'hardhat_project' calls to hardhatProjectManage function.case 'hardhat_project': result = await hardhatProjectManage(args as any); break;
- src/index.ts:524-524 (registration)Registration of the tool definition/schema by spreading hardhatFoundryToolDefinitions into optimizedToolDefinitions array used for ListTools....hardhatFoundryToolDefinitions,
- src/tools/composite.ts:640-733 (helper)Import of helper functions from hardhat.ts used by the hardhatProjectManage dispatcher (e.g., hardhatInit, hardhatCompile, etc.). Actual exec logic in src/tools/hardhat.ts (ID:24511902).import * as hardhatTools from './hardhat.js'; import * as foundryTools from './foundry.js'; /** * Composite Hardhat Project Management Tool * Consolidates project-level operations into 1 tool */ export async function hardhatProjectManage(args: { operation: 'init' | 'compile' | 'test' | 'clean' | 'flatten' | 'get_artifacts' | 'get_accounts' | 'config_network' | 'run_task' | 'list_tasks'; // Init-specific directory?: string; networks?: Array<'mainnet' | 'testnet' | 'previewnet' | 'local'>; solidity?: string; typescript?: boolean; // Compile-specific force?: boolean; // Test-specific testFiles?: string[]; grep?: string; network?: string; // Flatten-specific contractPath?: string; // Get artifacts-specific contractName?: string; // Run task-specific task?: string; params?: any; }): Promise<ToolResult> { try { logger.info('Hardhat project operation', { operation: args.operation }); switch (args.operation) { case 'init': return await hardhatTools.hardhatInit({ directory: args.directory, networks: args.networks, solidity: args.solidity, typescript: args.typescript, }); case 'compile': return await hardhatTools.hardhatCompile({ force: args.force, directory: args.directory }); case 'test': return await hardhatTools.hardhatTest({ testFiles: args.testFiles, grep: args.grep, network: args.network, directory: args.directory, }); case 'clean': return await hardhatTools.hardhatClean({ directory: args.directory }); case 'flatten': return await hardhatTools.hardhatFlatten({ files: args.contractPath ? [args.contractPath] : undefined, directory: args.directory }); case 'get_artifacts': return await hardhatTools.hardhatGetArtifacts({ contractName: args.contractName, directory: args.directory }); case 'get_accounts': return await hardhatTools.hardhatGetAccounts({ directory: args.directory }); case 'config_network': // Config network generates a config snippet, doesn't require all params return { success: true, data: { network: args.network || 'testnet', message: 'Use hardhat_contract with operation "deploy" and network parameter for actual deployment', }, }; case 'run_task': return await hardhatTools.hardhatRunTask({ task: args.task!, params: args.params, directory: args.directory, }); case 'list_tasks': return await hardhatTools.hardhatListTasks({ directory: args.directory }); default: throw new Error(`Unknown operation: ${args.operation}`); } } catch (error) { logger.error('Hardhat project operation failed', { operation: args.operation, error }); return { success: false, error: error instanceof Error ? error.message : 'Unknown error', }; } }