write_file
Create or update files on Windows systems by specifying file path and content for automated file management tasks.
Instructions
写入文件内容
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| path | Yes | 文件路径 | |
| content | Yes | 文件内容 |
Input Schema (JSON Schema)
{
"properties": {
"content": {
"description": "文件内容",
"type": "string"
},
"path": {
"description": "文件路径",
"type": "string"
}
},
"required": [
"path",
"content"
],
"type": "object"
}
Implementation Reference
- src/tools/filesystem.js:147-154 (handler)The core handler function for the write_file tool, which writes the provided content to the specified file path using fs.writeFile and returns success/error status.async writeFile(filePath, content) { try { await fs.writeFile(filePath, content, 'utf-8'); return { success: true, path: filePath, message: '文件写入成功' }; } catch (error) { return { success: false, error: error.message }; } }
- src/tools/filesystem.js:25-36 (schema)Schema definition for the write_file tool, including input parameters 'path' and 'content' with their types and descriptions.{ name: 'write_file', description: '写入文件内容', inputSchema: { type: 'object', properties: { path: { type: 'string', description: '文件路径' }, content: { type: 'string', description: '文件内容' }, }, required: ['path', 'content'], }, },
- src/tools/filesystem.js:119-120 (registration)Registration and dispatch logic in the executeTool method's switch statement, which routes 'write_file' calls to the writeFile handler.case 'write_file': return await this.writeFile(args.path, args.content);
- src/tools/filesystem.js:110-113 (registration)Tool registration check in canHandle method, listing 'write_file' among supported tools.const tools = ['read_file', 'write_file', 'list_directory', 'create_directory', 'delete_file', 'copy_file', 'move_file', 'search_files']; return tools.includes(toolName); }