Skip to main content
Glama

write_file

Write text to specified files within secure directories using the Simple MCP Server, ensuring controlled and authorized file operations.

Instructions

指定されたファイルにテキストを書き込みます(許可されたディレクトリのみ)

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
contentYes書き込む内容
filepathYes書き込むファイルのパス

Implementation Reference

  • The handler function for the 'write_file' tool. Validates the filepath using PathValidator, ensures allowed extension, creates directory if needed, writes content to file using fs.writeFile, and returns a success result.
    private async writeFile(filepath: string, content: string): Promise<CallToolResult> { try { const pathValidation = this.pathValidator.validatePath(filepath); if (!pathValidation.isValid) { throw new Error(pathValidation.error); } const extValidation = this.pathValidator.validateFileExtension(pathValidation.normalizedPath); if (!extValidation.isValid) { throw new Error(extValidation.error); } console.error(`Writing file: ${pathValidation.normalizedPath}`); // ディレクトリが存在しない場合は作成 const dir = path.dirname(pathValidation.normalizedPath); await fs.mkdir(dir, { recursive: true }); await fs.writeFile(pathValidation.normalizedPath, content, "utf-8"); return { content: [ { type: "text", text: `ファイル "${pathValidation.normalizedPath}" に正常に書き込みました`, }, ], isError: false, }; } catch (error) { throw new Error(`ファイルの書き込みに失敗: ${error}`); } }
  • The input schema definition for the 'write_file' tool, specifying required 'filepath' and 'content' string parameters.
    { name: "write_file", description: "指定されたファイルにテキストを書き込みます(許可されたディレクトリのみ)", inputSchema: { type: "object", properties: { filepath: { type: "string", description: "書き込むファイルのパス", }, content: { type: "string", description: "書き込む内容", }, }, required: ["filepath", "content"], }, },
  • src/index.ts:278-282 (registration)
    The dispatch/registration case in the CallToolRequestSchema handler that routes 'write_file' calls to the writeFile method.
    case "write_file": return await this.writeFile( args.filepath as string, args.content as string );

Other Tools

Related Tools

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/p-united/mcpSample'

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