Skip to main content
Glama

Filesystem MCP Server

by QuantGeekDev
WriteFileTool.ts1.09 kB
import { MCPTool } from "mcp-framework"; import { z } from "zod"; import fs from "fs/promises"; interface WriteFileInput { path: string; content: string; } class WriteFileTool extends MCPTool<WriteFileInput> { name = "write_file"; description = "Create a new file or completely overwrite an existing file with new content. " + "Use with caution as it will overwrite existing files without warning. " + "Handles text content with proper encoding. Only works within allowed directories."; schema = { path: { type: z.string(), description: "Path where to write the file", }, content: { type: z.string(), description: "Content to write to the file", }, }; async execute(input: WriteFileInput) { try { await fs.writeFile(input.path, input.content, "utf-8"); return `Successfully wrote to ${input.path}`; } catch (error) { const errorMessage = error instanceof Error ? error.message : String(error); throw new Error(`Failed to write file: ${errorMessage}`); } } } export default WriteFileTool;

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/QuantGeekDev/mcp-filesystem'

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