replace_member
[refactoring]
Replaces one C# member selected by its exact symbolKey.
Available in Glider 13.0.0. Check that the installed server advertises replace_member.
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
| Name | Type | Required | Description |
|---|---|---|---|
| symbolKey | string | Yes | Exact member key from symbol discovery. Names and fuzzy matches are unsupported. |
| expectedText | string | Yes | Exact current declaration without outer trivia. Read replacementSpans from get_symbol_info, then get_file_contents. |
| memberCode | string | Yes | One complete declaration of the same member category. Exclude outer comments and directives. |
| filePath | string | No | Exact declaration file for a partial member. Absolute or loaded-root-relative. |
| applyChanges | boolean | No | Apply to disk by default. Set false to preview. Default: true |
| failOnErrors | boolean | No | Refuse a write when the replacement has compiler errors or incomplete linked-target coverage. Default: false |
| includeDiff | boolean | No | Include the unified diff. Set false for compact output; diagnostics, errors, and application state remain available. 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.
Preview an exact member replacement
{
"symbolKey": "<member key from find_code>",
"expectedText": "public int Total() => 1;",
"memberCode": "public int Total() => 2;",
"applyChanges": false
}Full MCP request
{
"jsonrpc": "2.0",
"id": 1,
"method": "tools/call",
"params": {
"name": "replace_member",
"arguments": {
"symbolKey": "<member key from find_code>",
"expectedText": "public int Total() => 1;",
"memberCode": "public int Total() => 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": []
},
"uncheckedProjects": [],
"unifiedDiff": "..."
}Response Notes
Supply its current declaration as expectedText and one replacement declaration as memberCode. Surrounding code and outer comments remain unchanged. Use applyChanges=false for a preview.
Returns status, the original span, replacementSymbolKey, diagnostics, and a bounded diff. Span lines and UTF-16 columns are one-based, with exclusive ends; start/length are zero-based UTF-16 offsets. A conflict requires a fresh read. Compiler checks cover only the replacement; callers remain unchanged. uncheckedProjects reports incomplete coverage. Apply awaits sync across all linked targets without a full reload. A failed sync returns success=false and applied=true. If workspaceUpdate is failed, sync the file instead of repeating the write. Internal directives and multi-variable declarations are unsupported. Supported encodings are UTF-8 and UTF-16 with a BOM. Concurrent writer exclusion covers Windows and cooperating .NET clients on Unix. Results use top-level fields with success. Compact is the default; full adds responseDiagnostics. Both modes retain errors, coverage, partial state, and recovery advice.
For a failed symbol-key request, success=false includes errorCode, parameter, error, and suggestions in compact, full, and batch operation results. Batch keeps a bounded summary outside the requested detail budget. If the hard server limit omits details, failureDetailsOmitted or writeStateOmitted identifies the omission. errorCode is invalid_symbol_key, symbol_not_found, ambiguous_symbol_key, wrong_symbol_kind, source_unavailable, unsupported_symbol, or invalid_arguments. Follow the suggestions for the specific failure. Correct the named selector for invalid_arguments. For symbol_not_found, repeat discovery in the selected workspace and pass a returned key unchanged. An absent identity does not prove that a key is stale.