replace_range
[refactoring]
Replaces a nonempty contiguous range in a loaded C# document. Exact source guards reject stale edits. Use applyChanges=false for a preview. Prefer replace_member for complete member declarations.
Unreleased tool. Available in development builds after Glider 11.0.0.
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 | Existing loaded .cs file. Absolute or loaded-root-relative. |
| startLine | number | Yes | Inclusive start line, one-based. |
| startColumn | number | Yes | Inclusive start column, one-based UTF-16 units. |
| endLine | number | Yes | Exclusive end line, one-based. |
| endColumn | number | Yes | Exclusive end column, one-based UTF-16 units. |
| expectedText | string | Yes | Nonempty exact source, including whitespace and line endings. Read get_file_contents with includeRawContent=true. |
| replacementText | string | Yes | Exact replacement. Empty text deletes the range. No automatic formatting occurs. |
| applyChanges | boolean | No | Apply to disk by default. Set false to preview. Default: true |
| failOnErrors | boolean | No | Refuse any error in edited documents, including existing errors, or incomplete target checks. Default: false |
| includeDiff | boolean | No | Include the unified diff. Default: true |
| maxDiffChars | number | No | Maximum diff characters. Use 0 for unlimited. Default: 50000 |
| pathStyle | string | No | Path style: absolute or relative to the loaded 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.
Replace the digit in a line containing int x = 1;
{
"filePath": "Sample.cs",
"startLine": 1,
"startColumn": 9,
"endLine": 1,
"endColumn": 10,
"expectedText": "1",
"replacementText": "2",
"applyChanges": false
}Full MCP request
{
"jsonrpc": "2.0",
"id": 1,
"method": "tools/call",
"params": {
"name": "replace_range",
"arguments": {
"filePath": "Sample.cs",
"startLine": 1,
"startColumn": 9,
"endLine": 1,
"endColumn": 10,
"expectedText": "1",
"replacementText": "2",
"applyChanges": false
}
}
}{
"success": true,
"status": "preview",
"preview": true,
"applied": false,
"diskWriteAttempted": false,
"filesChanged": 0,
"wouldChange": true,
"filePath": "/project/OrderService.cs",
"workspaceUpdate": "unchanged",
"diagnostics": {
"errorCount": 0,
"warningCount": 0,
"items": []
},
"coverage": {
"complete": true,
"scope": "editedDocuments",
"targets": [
{
"projectId": "example-project-id",
"projectName": "Sample",
"checked": true,
"reason": null
}
]
},
"unifiedDiff": "..."
}Response Notes
Returns oldRange, newRange, diagnostics, target coverage, and disk and workspace outcomes. Coordinates use one-based lines and UTF-16 columns with exclusive ends. The complete edited document is checked in every linked project. These checks exclude other files and dependent projects. Check project diagnostics after imports, declarations, signatures, or directives change. Apply awaits one named-file sync without reload. Never repeat a completed or uncertain write. Read bounded get_file_contents with includeRawContent=true for exact whitespace and line endings, including the final returned line terminator. A null rawContent requires a smaller window. UTF-8 and BOM-marked UTF-16 encodings are supported. Empty ranges and boundaries inside CRLF or surrogate pairs are refused. Results use top-level fields with success. Compact is the default; full adds responseDiagnostics. Both modes retain errors, coverage, partial state, and recovery advice.