The Problem with Text-Based Code Editing Most AI systems edit source code the same way a novice reads a blueprint — by scanning raw text, counting brackets, and guessing at structure. This approach ignores a far more powerful resource that is already available: the compiler's complete semantic model of the code. Consider an analogy: you have access to a building's full architectural blueprints — every wall, pipe, and electrical circuit precisely mapped — yet instead of using them, you hand a contractor a photograph of the facade and say "figure it out." That is precisely what happens when AI manipulates raw text while Roslyn already holds the complete, typed, resolved syntax tree in memory. The Roslyn MCP Server eliminates this disconnect. It exposes Roslyn's structured model directly to AI, replacing fragile text operations with precise, semantic transformations.
What AI Gets Access To The server grants AI three distinct layers of access to the Visual Studio environment:
Layer API / Technology What It Enables Semantic Model VisualStudioWorkspace (Roslyn) The same model that powers IntelliSense — full type resolution, symbol lookup, and dependency graphs IDE Control DTE2 Build, debug, set breakpoints, read local variables, step through execution UI Automation System.Windows.Automation Interact with Visual Studio's desktop interface programmatically
Semantic Code Navigation On solution load, Roslyn indexes every symbol across the entire project graph. Navigation is compiler-resolved — not a text search, not a regex match, but a true semantic lookup against the type system.
Navigation Direction What You Can Traverse Upward (toward abstractions) Base types, implemented interfaces, all call sites (callers) Downward (toward implementations) Derived types, concrete implementations, all callees Lateral (within a type) All members: fields, properties, methods, nested types Cross-project Any symbol in any referenced assembly or project in the solution
Example: find every class that implements ITaskRepository across the solution:
// MCP tool call — semantic, not textual find_implementations({ symbol: "ITaskRepository", scope: "solution" })
// Returns structured JSON: // [ // { class: "SqlTaskRepository", file: "Data/SqlTaskRepository.cs", line: 14 }, // { class: "InMemoryTaskRepository", file: "Tests/Fakes.cs", line: 7 } // ]
Structured Code Editing AI does not edit raw text. Instead, it requests a JSON representation of a class's structure — fields, methods, return types, access modifiers — then targets specific members by name. Roslyn generates the updated syntax, applies formatting, and returns any compiler diagnostics in the same response.
Class Structure as JSON // AI requests structure of TaskService get_class_structure({ class: "TaskService" })
// Roslyn returns: { "name": "TaskService", "namespace": "App.Services", "baseType": "BaseService", "interfaces": ["ITaskService"], "fields": [ { "name": "_repository", "type": "ITaskRepository", "modifier": "private readonly" } ], "methods": [ { "name": "AddTask", "returnType": "Task", "params": ["TaskDto dto"] }, { "name": "DeleteTask", "returnType": "Task", "params": ["int id"] } ] }
Block-Level Path Addressing Any nested control-flow block can be addressed by a structured path, allowing surgical edits without touching surrounding code:
// Target a specific else-branch inside AddTask edit_block({ path: "TaskService.AddTask.if[0].else", replacement: "throw new InvalidOperationException("Duplicate task detected.");" })
Path Segment Meaning TaskService Class name AddTask Method name if[0] First if-statement in the method body else The else branch of that if-statement for[1].body Body of the second for-loop try.catch[0] First catch clause of a try block
AI-Driven Debugger Integration Via the DTE2 API, the AI has full control over the Visual Studio debugger at runtime — not limited to static analysis of source files.
// 1. Set a breakpoint on a specific line set_breakpoint({ file: "Services/TaskService.cs", line: 42 })
// 2. Start debugging start_debug()
// 3. When breakpoint is hit, read local variables read_locals() // Returns: { dto: { Title: "Buy milk", Priority: 2 }, _repository: "SqlTaskRepository" }
// 4. Step into the next method call step_into()
// 5. Inspect a specific expression evaluate_expression({ expr: "dto.Priority > 0" }) // Returns: true
Debugger Capability DTE2 Operation Set / remove breakpoints Debugger.Breakpoints.Add / .Delete Start / stop / attach Debugger.Go / .Stop / .Attach Step over / into / out Debugger.StepOver / .StepInto / .StepOut Read local variables Debugger.CurrentStackFrame.Locals Evaluate expressions Debugger.GetExpression(expr).Value
Skills: Teaching AI to Use the Tools A tool without documentation is a tool misused. Skills are structured instruction sets that tell AI exactly how to call each MCP tool: which parameters are required, what a valid workflow looks like, and how to recover when something fails.
Deployment Target Location Claude Code (external projects) .claude/skills/ in your project root (copy from GitHub) Built-in Claude Chat panel Skills/.claude/skills/ inside the VS extension bundle
Think of skills as the difference between handing an AI a hammer versus teaching it carpentry. The raw API access is the hammer; skills are the training.
The Bigger Picture: Programming Languages Designed for AI This project is an early experiment in a broader hypothesis: that the programming languages of the future will not be designed for humans to type, but for AI to manipulate as structured objects.
Today (Text-Based AI Editing) Future (Structured AI Editing) AI reads raw .cs files as strings AI receives typed syntax trees as data Edits made by string replacement Edits made by AST node substitution Compiler errors discovered after edit Diagnostics returned in same operation No awareness of type system Full semantic resolution before any change Navigation by text search / grep Navigation by compiler symbol resolution
Roslyn MCP Server is a working implementation of the "future" column — built today, on top of C# and the Roslyn compiler platform.
Resources & Links Demo Video 1: https://www.youtube.com/watch?v=skvnHbm2lpk Demo Video 2: https://www.youtube.com/watch?v=6d6Kx-MnXOc Visual Studio Marketplace: marketplace.visualstudio.com/items GitHub Repository: https://github.com/yarhoroh/RoslynMCP-Public
No responses yet.