format_document

[codefix]

Formats a C# document according to the project's formatting rules and returns diff output.

Why this tool exists

Small code fixes, using-directive cleanup, and formatting keep generated patches reviewable.

How it helps the agent

The model can separate behavioral edits from mechanical cleanup and keep diffs closer to the project style.

Parameters

NameTypeRequiredDescription
filePathstringYesFile path to format.
projectNamestringNoOptional project name filter.
applyChangesbooleanNoIf true (default), applies changes to disk. If false, returns preview only.
includeDiffbooleanNoInclude unified diff in response. Default is true.
maxDiffCharsnumberNoMax diff characters. Use 0 for unlimited. Default is 50000.
pathStylestringNoPath style: 'absolute' (default) or 'relative' (to solution root).

Examples

Preview formatting a file

Request
{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "tools/call",
  "params": {
    "name": "format_document",
    "arguments": {
      "filePath": "/Users/dev/MyProject/Program.cs",
      "applyChanges": false
    }
  }
}
Response
{
  "success": true,
  "data": {
    "filePath": "/path/to/File.cs",
    "changed": true,
    "applied": false,
    "filesChanged": 1,
    "unifiedDiff": "...",
    "changedFiles": [
      {
        "filePath": "/path/to/File.cs",
        "changeCount": 1,
        "diff": "..."
      }
    ]
  },
  "error": null
}

Response Notes

Returns diff output for the formatting operation

↑/↓ NavigateEnter OpenSpace Expand