[solution]
Writes a .cs file under the loaded root, then updates or reloads the workspace. Set applyChanges=false for a preview that writes no file.
File writes should be previewable and synchronized with the loaded workspace when possible.
The model can propose/apply edits and immediately know how the semantic workspace was updated.
Try it locally in the Glider playground
| Name | Type | Required | Description |
|---|---|---|---|
| filePath | string | Yes | File path to write. Can be absolute or relative to the loaded root. Writes take the path exactly as given. The repository-relative form the read tools accept does not apply here. |
| content | string | Yes | Full file contents to write. |
| applyChanges | boolean | No | If true, writes the file to disk. If false, returns a preview only. Default is true. |
| createIfMissing | boolean | No | If true, creates a new file when it does not already exist. Default is false. |
| includeDiff | boolean | No | Include unified diff output in the response. Default is true. |
| maxDiffChars | number | No | Maximum diff characters to return. Use 0 for unlimited. Default is 50000. |
| pathStyle | string | No | Path style: 'absolute' (default) or 'relative' (to solution root). |
Write a file edit
{
"jsonrpc": "2.0",
"id": 1,
"method": "tools/call",
"params": {
"name": "write_file",
"arguments": {
"filePath": "/Users/dev/MyProject/Program.cs",
"content": "namespace MyProject;\n\npublic class Program { }"
}
}
}{
"success": true,
"data": {
"filePath": "/Users/dev/MyProject/Program.cs",
"preview": false,
"applied": true,
"changed": true,
"created": false,
"filesChanged": 1,
"unifiedDiff": "--- /Users/dev/MyProject/Program.cs\n+++ /Users/dev/MyProject/Program.cs\n@@ ...",
"changedFiles": [
{
"filePath": "/Users/dev/MyProject/Program.cs",
"changeCount": 1,
"diff": "--- /Users/dev/MyProject/Program.cs\n+++ /Users/dev/MyProject/Program.cs\n@@ ..."
}
],
"workspaceUpdate": {
"kind": "applied",
"updated": true,
"inWorkspaceBefore": true,
"inWorkspaceAfter": true,
"message": null
}
},
"meta": {
"durationMs": 112,
"cancelled": false,
"timedOut": false,
"timeoutMs": 1200000
},
"error": null
}Preview a file edit without writing
{
"jsonrpc": "2.0",
"id": 1,
"method": "tools/call",
"params": {
"name": "write_file",
"arguments": {
"filePath": "/Users/dev/MyProject/Program.cs",
"content": "namespace MyProject;\n\npublic class Program { }",
"applyChanges": false
}
}
}{
"success": true,
"data": {
"filePath": "/Users/dev/MyProject/Program.cs",
"preview": false,
"applied": true,
"changed": true,
"created": false,
"filesChanged": 1,
"unifiedDiff": "--- /Users/dev/MyProject/Program.cs\n+++ /Users/dev/MyProject/Program.cs\n@@ ...",
"changedFiles": [
{
"filePath": "/Users/dev/MyProject/Program.cs",
"changeCount": 1,
"diff": "--- /Users/dev/MyProject/Program.cs\n+++ /Users/dev/MyProject/Program.cs\n@@ ..."
}
],
"workspaceUpdate": {
"kind": "applied",
"updated": true,
"inWorkspaceBefore": true,
"inWorkspaceAfter": true,
"message": null
}
},
"meta": {
"durationMs": 112,
"cancelled": false,
"timedOut": false,
"timeoutMs": 1200000
},
"error": null
}Create a new file
{
"jsonrpc": "2.0",
"id": 1,
"method": "tools/call",
"params": {
"name": "write_file",
"arguments": {
"filePath": "src/NewType.cs",
"content": "namespace MyProject;\n\npublic class NewType { }",
"createIfMissing": true,
"pathStyle": "relative"
}
}
}{
"success": true,
"data": {
"filePath": "/Users/dev/MyProject/Program.cs",
"preview": false,
"applied": true,
"changed": true,
"created": false,
"filesChanged": 1,
"unifiedDiff": "--- /Users/dev/MyProject/Program.cs\n+++ /Users/dev/MyProject/Program.cs\n@@ ...",
"changedFiles": [
{
"filePath": "/Users/dev/MyProject/Program.cs",
"changeCount": 1,
"diff": "--- /Users/dev/MyProject/Program.cs\n+++ /Users/dev/MyProject/Program.cs\n@@ ..."
}
],
"workspaceUpdate": {
"kind": "applied",
"updated": true,
"inWorkspaceBefore": true,
"inWorkspaceAfter": true,
"message": null
}
},
"meta": {
"durationMs": 112,
"cancelled": false,
"timedOut": false,
"timeoutMs": 1200000
},
"error": null
}Returns diff output plus workspace update status. A preview (applyChanges=false) leads with preview:true and reports wouldChange/wouldCreate/filesThatWouldChange instead of the past-tense counts below.