Browse documentation

write_file

[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.

Before you use this tool

Writes files by default. An authorized, unambiguous edit with a clear scope can apply directly. Set applyChanges: false for a preview without file writes. Preview when the user requests inspection only, the scope is unclear, or a broad refactor needs inspection.

Try it locally in the Glider playground

Parameters

NameTypeRequiredDescription
filePathstringYesFile 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.
contentstringYesFull file contents to write.
applyChangesbooleanNoIf true, writes the file to disk. If false, returns a preview only. Default is true. Default: true
createIfMissingbooleanNoIf true, creates a new file when it does not already exist. Default is false. Default: false
includeDiffbooleanNoInclude unified diff output in the response. Default is true. Default: true
maxDiffCharsnumberNoMaximum diff characters to return. Use 0 for unlimited. Default is 50000. Default: 50000
includePerFileDiffbooleanNoInclude diffs in changedFiles independently of includeDiff. File paths and counts remain available when false. Unreleased: development builds after 13.4.0. Use only when the installed schema advertises this parameter. Default: false
pathStylestringNoPath style: 'absolute' (default) or 'relative' (to solution root). Default: "absolute"
responseDetailstringNocompact returns results and actionable state. full adds diagnostic metadata under responseDiagnostics. Default: "compact"

Examples

Replace sample paths and symbol keys with values from your workspace.

Write a file edit

Arguments
{
  "filePath": "/Users/dev/MyProject/Program.cs",
  "content": "namespace MyProject;\n\npublic class Program { }"
}
Full MCP request
Full MCP request
{
  "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 { }"
    }
  }
}
Illustrative response
{
  "success": true,
  "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
  }
}

Preview a file edit without writing

Arguments
{
  "filePath": "/Users/dev/MyProject/Program.cs",
  "content": "namespace MyProject;\n\npublic class Program { }",
  "applyChanges": false
}
Full MCP request
Full MCP request
{
  "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
    }
  }
}

Create a new file

Arguments
{
  "filePath": "src/NewType.cs",
  "content": "namespace MyProject;\n\npublic class NewType { }",
  "createIfMissing": true,
  "pathStyle": "relative"
}
Full MCP request
Full MCP request
{
  "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"
    }
  }
}

Response Notes

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.

Unreleased development builds after 13.4.0 return one unified diff by default; the example uses that contract. Follow the installed schema for supported parameters and defaults. Set includeDiff=false for compact output, with includePerFileDiff=false where supported. Set includePerFileDiff=true only when separate file diffs are needed; it works independently of includeDiff. These controls preserve application state, file metadata, counts, and any diagnostics, errors, conflicts, or limits the tool reports. Results use top-level fields with success. Compact is the default; full adds responseDiagnostics. Both modes retain errors, coverage, partial state, and recovery advice.