format_document
[codefix]
Formats a C# document according to the project's formatting rules and returns diff output.
Before you use this tool
Writes files by default. Set applyChanges: false to preview the diff. Inspect the diff before application.
Try it locally in the Glider playground
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
| filePath | string | Yes | File path to format. Absolute, loaded-root-relative, or repository-relative. |
| projectName | string | No | Optional project name filter. |
| applyChanges | boolean | No | If true (default), applies changes to disk. If false, returns preview only. Default: true |
| includeDiff | boolean | No | Include unified diff in response. Default is true. Default: true |
| maxDiffChars | number | No | Max diff characters. Use 0 for unlimited. Default is 50000. Default: 50000 |
| pathStyle | string | No | Path style: 'absolute' (default) or 'relative' (to solution root). Default: "absolute" |
| responseDetail | string | No | compact 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.
Preview formatting a file
Arguments
{
"filePath": "/Users/dev/MyProject/Program.cs",
"applyChanges": false
}Full MCP request
Full MCP request
{
"jsonrpc": "2.0",
"id": 1,
"method": "tools/call",
"params": {
"name": "format_document",
"arguments": {
"filePath": "/Users/dev/MyProject/Program.cs",
"applyChanges": false
}
}
}Illustrative response
{
"success": true,
"filePath": "/path/to/File.cs",
"changed": true,
"applied": false,
"filesChanged": 1,
"unifiedDiff": "...",
"changedFiles": [
{
"filePath": "/path/to/File.cs",
"changeCount": 1,
"diff": "..."
}
]
}Response Notes
Returns diff output for the formatting operation Results use top-level fields with success. Compact is the default; full adds responseDiagnostics. Both modes retain errors, coverage, partial state, and recovery advice.