Skip to main content
Glama
PraneshASP

Foundry MCP Server

by PraneshASP
create.ts1.84 kB
import { z } from "zod"; import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js"; import * as fs from "fs/promises"; import * as path from "path"; import { ensureWorkspaceInitialized } from "../../utils/workspace.js"; export function registerCreateSolidityFileTool(server: McpServer): void { server.tool( "create_solidity_file", "Create or update a Solidity file in the workspace", { filePath: z.string().describe("Path to the file (e.g., 'src/MyContract.sol' or 'script/Deploy.s.sol')"), content: z.string().describe("File content"), overwrite: z.boolean().optional().describe("Overwrite existing file (default: false)") }, async ({ filePath, content, overwrite = false }) => { try { const workspace = await ensureWorkspaceInitialized(); const fullFilePath = path.join(workspace, filePath); const fileExists = await fs.access(fullFilePath).then(() => true).catch(() => false); if (fileExists && !overwrite) { return { content: [{ type: "text", text: `File already exists at ${fullFilePath}. Use overwrite=true to replace it.` }], isError: true }; } await fs.mkdir(path.dirname(fullFilePath), { recursive: true }); await fs.writeFile(fullFilePath, content); return { content: [{ type: "text", text: `File ${fileExists ? 'updated' : 'created'} successfully at ${fullFilePath}` }] }; } catch (error) { return { content: [{ type: "text", text: `Error managing file: ${error instanceof Error ? error.message : String(error)}` }], isError: 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/PraneshASP/foundry-mcp-server'

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