Skip to main content
Glama

foundry_project

Manage Foundry project lifecycle operations including setup, dependencies, compilation, and gas optimization for smart contract development.

Instructions

Manage Foundry project lifecycle operations.

OPERATIONS:

  • init: Initialize new Foundry project with templates

  • install: Install git submodule dependency (e.g., forge-std)

  • update: Update all dependencies

  • remove: Remove a dependency

  • clean: Clean build artifacts

  • build: Compile contracts with optimization options

  • fmt: Format Solidity code

  • inspect: Inspect contract artifacts (ABI, bytecode, storage-layout)

  • get_artifacts: Retrieve compiled artifacts

  • snapshot: Create gas usage snapshot for optimization

USE FOR: Project setup, dependencies, compilation, and gas optimization.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
operationYesProject operation to perform
directoryNoAbsolute path to Foundry project directory (required for all operations except init which creates it)
templateNoProject template (for init)
dependencyNoDependency name (for install/remove)
optimizeNoEnable optimizer (for build)
optimizerRunsNoOptimizer runs (for build)
viaIrNoUse IR pipeline (for build)
contractNameNoContract name (for inspect/get_artifacts)
fieldNoInspection field (for inspect)

Implementation Reference

  • Primary handler function for the 'foundry_project' tool. Dispatches to specific Foundry operations (init, build, test, etc.) based on the 'operation' argument.
    export async function foundryProjectManage(args: { operation: 'init' | 'install' | 'update' | 'remove' | 'clean' | 'build' | 'fmt' | 'inspect' | 'get_artifacts' | 'snapshot'; // Init-specific directory?: string; template?: string; // Install/Remove-specific dependency?: string; // Build-specific optimize?: boolean; optimizerRuns?: number; viaIr?: boolean; // Inspect-specific contractName?: string; field?: 'abi' | 'bytecode' | 'assembly' | 'storage-layout'; }): Promise<ToolResult> { try { logger.info('Foundry project operation', { operation: args.operation }); switch (args.operation) { case 'init': return await foundryTools.foundryInit({ directory: args.directory, template: args.template as 'basic' | 'advanced' | undefined, }); case 'install': return await foundryTools.foundryInstall({ dependency: args.dependency! }); case 'update': return await foundryTools.foundryUpdate(); case 'remove': return await foundryTools.foundryRemove({ dependency: args.dependency! }); case 'clean': return await foundryTools.foundryClean({ directory: args.directory }); case 'build': return await foundryTools.foundryBuild({ optimize: args.optimize, optimizerRuns: args.optimizerRuns, viaIr: args.viaIr, directory: args.directory, }); case 'fmt': return await foundryTools.foundryFmt({ directory: args.directory }); case 'inspect': return await foundryTools.foundryInspect({ contractName: args.contractName!, field: args.field || 'abi', }); case 'get_artifacts': return await foundryTools.foundryGetArtifacts({ contractName: args.contractName, directory: args.directory }); case 'snapshot': return await foundryTools.foundrySnapshot({ directory: args.directory }); default: throw new Error(`Unknown operation: ${args.operation}`); } } catch (error) { logger.error('Foundry project operation failed', { operation: args.operation, error }); return { success: false, error: error instanceof Error ? error.message : 'Unknown error', }; } }
  • Tool definition object for 'foundry_project' including name, description, and inputSchema for validation.
    { name: 'foundry_project', description: `Manage Foundry project lifecycle operations. OPERATIONS: - init: Initialize new Foundry project with templates - install: Install git submodule dependency (e.g., forge-std) - update: Update all dependencies - remove: Remove a dependency - clean: Clean build artifacts - build: Compile contracts with optimization options - fmt: Format Solidity code - inspect: Inspect contract artifacts (ABI, bytecode, storage-layout) - get_artifacts: Retrieve compiled artifacts - snapshot: Create gas usage snapshot for optimization USE FOR: Project setup, dependencies, compilation, and gas optimization.`, inputSchema: { type: 'object' as const, properties: { operation: { type: 'string', enum: ['init', 'install', 'update', 'remove', 'clean', 'build', 'fmt', 'inspect', 'get_artifacts', 'snapshot'], description: 'Project operation to perform', }, directory: { type: 'string', description: 'Absolute path to Foundry project directory (required for all operations except init which creates it)' }, template: { type: 'string', description: 'Project template (for init)' }, dependency: { type: 'string', description: 'Dependency name (for install/remove)' }, optimize: { type: 'boolean', description: 'Enable optimizer (for build)' }, optimizerRuns: { type: 'number', description: 'Optimizer runs (for build)' }, viaIr: { type: 'boolean', description: 'Use IR pipeline (for build)' }, contractName: { type: 'string', description: 'Contract name (for inspect/get_artifacts)' }, field: { type: 'string', enum: ['abi', 'bytecode', 'assembly', 'storage-layout'], description: 'Inspection field (for inspect)', }, }, required: ['operation'], }, },
  • src/index.ts:653-655 (registration)
    Tool registration in the main request handler switch statement, mapping 'foundry_project' calls to the foundryProjectManage handler.
    case 'foundry_project': result = await foundryProjectManage(args as any); break;
  • Example helper function foundryInit called by the main handler for 'init' operation. Other operations have similar helpers in this file.
    export async function foundryInit(args: { directory?: string; networks?: Array<'mainnet' | 'testnet' | 'previewnet' | 'local'>; solidity?: string; template?: 'basic' | 'advanced'; }): Promise<ToolResult> { try { const directory = args.directory || process.cwd(); const networks = args.networks || ['testnet', 'local']; const solidity = args.solidity || '0.8.20'; logger.info('Initializing Foundry project', { directory, networks, solidity }); // Create directory if it doesn't exist await fs.mkdir(directory, { recursive: true }); // Create directory structure await fs.mkdir(path.join(directory, 'src'), { recursive: true }); await fs.mkdir(path.join(directory, 'test'), { recursive: true }); await fs.mkdir(path.join(directory, 'script'), { recursive: true }); await fs.mkdir(path.join(directory, 'lib'), { recursive: true });

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/justmert/hashpilot'

If you have feedback or need assistance with the MCP directory API, please join our Discord server