[refactoring]
Creates a new top-level type in a new file from C# source, and returns a diff. The source may include using directives and a single namespace. Chooses the project that owns the target path, infers the namespace from a sibling file when it is not given, and formats the created file. The target file must not already exist. For a partial type, an existing type of the same name is rejected.
C# refactors are semantic operations, not search-and-replace operations.
The model can preview or apply semantic changes while preserving symbol identity across overloads, files, and projects.
Try it locally in the Glider playground
| Name | Type | Required | Description |
|---|---|---|---|
| typeCode | string | Yes | The full C# source of the type. May include using directives and one namespace. |
| filePath | string | Yes | The file to create. Absolute or loaded-root-relative. Must not already exist. |
| targetNamespace | string | No | The namespace for the type. If omitted, taken from the source or inferred from a sibling file. |
| projectName | string | No | Optional project name when the target directory is under more than one project. |
| applyChanges | boolean | No | If true (default), applies changes to disk. If false, returns a preview diff. |
| failOnErrors | boolean | No | If true, do not write when the edit introduces a compile error; the response reports the diagnostics. |
| includeDiff | boolean | No | Include unified diff in response. Default is true. |
| maxDiffChars | number | No | Max diff characters. Use 0 for unlimited. Default is 50000. |
| includePerFileDiff | boolean | No | Include per-file diffs in changedFiles. Default is true. |
| pathStyle | string | No | Path style: 'absolute' (default) or 'relative' (to solution root). |
Preview creating a new class
{
"jsonrpc": "2.0",
"id": 1,
"method": "tools/call",
"params": {
"name": "add_type",
"arguments": {
"typeCode": "public class OrderService { }",
"filePath": "src/Orders/OrderService.cs",
"targetNamespace": "MyProject.Orders",
"applyChanges": false
}
}
}{
"success": true,
"data": {
"typeName": "OrderService",
"typeKind": "class",
"namespace": "MyProject.Orders",
"namespaceSource": "explicit",
"filePath": "/path/to/OrderService.cs",
"filesChanged": 1,
"filesCreated": 1,
"applied": false,
"message": null,
"diagnostics": {
"errorCount": 0,
"warningCount": 0,
"items": []
},
"unifiedDiff": "...",
"changedFiles": [
{
"filePath": "/path/to/OrderService.cs",
"changeCount": 3,
"diff": "..."
}
],
"workspaceUpdate": null
},
"error": null
}Returns a unified diff of the created file (and any project-file edit). typeName, typeKind, namespace, and namespaceSource identify what was created and how the namespace was chosen. workspaceUpdate reports whether the workspace compiles the new file, and is null when nothing was created. diagnostics reports the compile errors and warnings the new file introduces; when failOnErrors is true and it introduces an error, applied is false and message explains why. In a multi-targeted project the check spans every target.