Browse documentation

add_member

[refactoring]

Inserts a C# member into an existing type and returns a diff.

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
containerNamestringYesThe type to add the member to. A stable symbolKey (preferred) or a name (simple or fully qualified).
memberCodestringYesThe full C# source of the member to insert.
filePathstringNoFor a partial type, the file whose part receives the member. Absolute or loaded-root-relative. Defaults to the largest non-generated part.
projectNamestringNoOptional project name to limit search when finding the type by name.
applyChangesbooleanNoIf true (default), applies changes to disk. If false, returns a preview diff. Default: true
failOnErrorsbooleanNoIf true, do not write when the edit introduces a compile error; the response reports the diagnostics. Default: false
includeDiffbooleanNoInclude unified diff in response. Default is true. Default: true
maxDiffCharsnumberNoMax diff characters. Use 0 for unlimited. Default is 50000. Default: 50000
includePerFileDiffbooleanNoInclude diffs in changedFiles independently of includeDiff. File paths and counts remain available when false. Development builds after 13.4.0 default to false; released 13.4.0 defaults to true. Follow the installed schema. 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.

Preview adding a method to a class

Arguments
{
  "containerName": "OrderService",
  "memberCode": "public decimal Total() => 0m;",
  "applyChanges": false
}
Full MCP request
Full MCP request
{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "tools/call",
  "params": {
    "name": "add_member",
    "arguments": {
      "containerName": "OrderService",
      "memberCode": "public decimal Total() => 0m;",
      "applyChanges": false
    }
  }
}
Illustrative response
{
  "success": true,
  "containerName": "MyProject.OrderService",
  "memberName": "Total",
  "memberKind": "Method",
  "filePath": "/path/to/OrderService.cs",
  "filesChanged": 1,
  "applied": false,
  "message": null,
  "diagnostics": {
    "errorCount": 0,
    "warningCount": 0,
    "items": []
  },
  "unifiedDiff": "...",
  "changedFiles": [
    {
      "filePath": "/path/to/OrderService.cs",
      "changeCount": 1
    }
  ]
}

Preview insertion into a discovered type

Arguments
{
  "containerName": "<type key from find_code>",
  "memberCode": "public decimal Total() => 0m;",
  "applyChanges": false
}
Full MCP request
Full MCP request
{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "tools/call",
  "params": {
    "name": "add_member",
    "arguments": {
      "containerName": "<type key from find_code>",
      "memberCode": "public decimal Total() => 0m;",
      "applyChanges": false
    }
  }
}

Response Notes

The member text is parsed and validated before it is inserted, and only the inserted code is formatted, so the change lands indented in the body without reformatting the rest of the file. For a partial type, filePath chooses which part receives the member; by default the largest non-generated part is used.

Returns a unified diff of the insertion. containerName, memberName, and memberKind identify what was added, and filePath names the file that received it (the chosen part for a partial type). diagnostics reports the compile errors and warnings the inserted member introduces; when failOnErrors is true and it introduces an error, applied is false and message explains why. When the file is linked into several projects or targets, the check spans all of them.

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.

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.