Repository navigation
01 Architecture and Design Philosophy
This document details the architectural foundation, design principles, and engineering decisions behind Farol.
Farol's design is guided by five foundational principles:
- Compiler-Grade Accuracy: Never approximate what the compiler knows with certainty. Never rely on regex heuristics when Roslyn's semantic models can resolve exact overloads, type bindings, and syntax structures.
- Fast Feedback Loops: An AI agent cannot afford a full MSBuild build after every edit. Verification should take about a second.
-
Inclusive Legacy Fidelity: Legacy systems (.NET Framework, VB.NET, classic
.csproj,packages.config, WebForms, ASMX, WCF, WinForms, WPF) are treated as first-class citizens alongside modern .NET 10/11 codebases. - Token & Context Optimization: Output must be dense, concise, and structured specifically for LLM consumption. Redundancy, massive compiler logs, and irrelevant diagnostics must be aggressively filtered.
- Decoupled & Remote-Ready: The engine is completely isolated from the transport layer. All operations work against immutable snapshots, return unified diffs, and mirror workspace identifiers into standard headers, enabling future multi-tenant HTTP gateway deployments without architectural rewrites.
Farol follows a strict vertical layering model with unidirectional dependencies:
┌────────────────────────────────────────────────────────┐
│ Farol.Host │
│ - stdio JSON-RPC transport │
│ - CLI flags & configuration cascading │
│ - Standard stream isolation (stdout clean, stderr logs)│
│ - Local privacy-first telemetry logging & reports │
└──────────────────────────┬─────────────────────────────┘
│ depends on
┌──────────────────────────▼─────────────────────────────┐
│ Farol.Tools │
│ - 23 MCP Tools (organized across 7 feature toolsets) │
│ - 4 MCP Prompts (workflows as slash commands) │
│ - Parameter validation & tool guards │
│ - Token budgeting & truncation management │
│ - Compact text formatting tailored for LLMs │
└──────────────────────────┬─────────────────────────────┘
│ depends on
┌──────────────────────────▼─────────────────────────────┐
│ Farol.Engine │
│ - Roslyn MSBuildWorkspace & dual BuildHost loader │
│ - Analyzer & generator copies, newer-compiler fallback │
│ - Immutable WorkspaceSession & WorkspaceSnapshot │
│ - Background compilation warm-up & file watcher │
│ - DiagnosticCheck & load baseline engine │
│ - Cross-language Navigation (C#/VB, IOperation) │
│ - Markup indexing (WebForms, ASMX, WCF, XAML) │
│ - Decompilation via ICSharpCode.Decompiler │
│ - BuildRunner & TestRunner (binlog / TRX parsers) │
│ - Legacy inventory, config masking & migration planner │
│ - NuGet dependency analysis & public API inspector │
└──────────────────────────┬─────────────────────────────┘
│ depends on
┌──────────────────────────▼─────────────────────────────┐
│ Farol.Core │
│ - ZERO Roslyn / MSBuild dependencies │
│ - PathSandbox (symlinks, junctions, trust boundaries) │
│ - DisplayPath (POSIX-compliant, root-relative paths) │
│ - ProcessRunner (child process trees, stdio isolation) │
│ - AtomicFile (temp-write & atomic rename) │
│ - UnifiedDiff (Myers diff algorithm, 3-line context) │
│ - TokenBudget & ResponseBuilder │
│ - ServerPermissions (read-only mode enforcement) │
│ - ErrorCodes & FarolException │
│ - Local usage logging models (IUsageLog, UsageReport) │
└────────────────────────────────────────────────────────┘
Farol.Core is intentionally isolated from Microsoft Roslyn and MSBuild packages.
- Portability & Isolation: Core utility functions (path sandboxing, process execution, diffing, atomic file operations, token budgeting) must execute without loading heavyweight Roslyn assemblies into memory.
- Security Boundaries: Path traversal checks and process lifecycle management must not depend on complex Roslyn workspace states.
-
Fast Startup & Low Footprint: Operations that execute before a workspace is loaded (such as
--help,--usage-report, and startup permission checks) run instantaneously without triggering Roslyn type initialization.
Loading a legacy .NET Framework solution in modern .NET is historically difficult because .NET 10 runs on CoreCLR, whereas classic .csproj/.vbproj files depend on MSBuild targets that only exist in full .NET Framework and Visual Studio installations.
Farol leverages Roslyn's out-of-process BuildHost architecture. Farol itself runs Roslyn 5.12, the compiler of .NET 11:
flowchart TD
FarolEngine["Farol.Engine (runs on .NET 10 CoreCLR)"] --> MSBW["MSBuildWorkspace"]
MSBW -->|".NET SDK Host"| NetCoreHost["BuildHost-netCore (SDK-Style Projects)"]
MSBW -->|".NET Framework Host"| Net472Host["BuildHost-net472 (Classic .NET Framework Projects)"]
NetCoreHost --> DotnetSdk[".NET SDK Targets & Tasks"]
Net472Host --> VsMsBuild["Visual Studio 2022+ MSBuild.exe Targets & Tasks"]
- SDK-Style Projects: Handled by the modern .NET SDK BuildHost. Evaluates multi-targeting, modern package references, analyzers, and source generators.
-
Classic .NET Framework Projects: Handled by
BuildHost-net472. This host runs on the .NET Framework 4.7.2+ runtime and connects directly to Visual Studio's MSBuild (MSBuild.exe). It executes classic tasks, resolves assembly references from the GAC or reference assembly directories, and evaluates legacy.csproj/.vbprojfiles with the same MSBuild that builds them.
Some legacy solutions use SDK-style project formats but target .NET Framework and import Visual Studio WebApplication targets (e.g. $(VSToolsPath)\WebApplications\Microsoft.WebApplication.targets). Because Roslyn directs SDK-style projects to the .NET SDK host by default, these imports would fail. Farol detects Visual Studio via ToolchainProbe and automatically injects the correct VSToolsPath into the global MSBuild properties, so these hybrid projects load.
In large enterprise solutions, projects often reference custom analyzer assemblies or source generators built within the same solution. If these analyzer projects have not yet been built on disk, standard Roslyn workspaces throw fatal exceptions during symbol and reference searches. Farol intercepts unresolved analyzers (UnresolvedAnalyzerReference), drops them from the active workspace compilation, and issues an informative warning instructing the user to build the producer project once.
Two more load steps keep analyzers and source generators from breaking the solution or the agent's code generation (details on the Workspaces and Loading page):
- An analyzer built for a newer compiler than the one Farol runs does not run, and the code it generates is missing. SDK analyzers are then taken from the newest installed SDK whose compiler Farol runs, unless a
global.jsonpins the SDK; otherwise a load issue names the analyzer, the compiler version it needs and the fix (AC-46). - Farol loads copies of analyzers and generators from
%TEMP%/farol/analyzers/, with its own assembly loader, so it never holds the files of the generators a solution builds, and the solution can rebuild them while Farol runs (AC-47).
Farol adopts a purely functional, immutable snapshot model for workspace state:
stateDiagram-v2
[*] --> NotLoaded
NotLoaded --> Loading: First tool call or auto-load
Loading --> Ready: MSBuildWorkspace completes
Loading --> Failed: Load error encountered
Ready --> Ready: Source file edit (in-memory snapshot created)
Ready --> Loading: Project file change (.csproj/.sln) -> ReloadAsync
Failed --> Loading: dotnet_workspace action='reload'
-
Non-Blocking Readers: Every incoming tool request is bound to a single immutable
WorkspaceSnapshot(containing a RoslynSolutionand an incrementing version number). Multiple tool requests execute concurrently across thread-pool threads without acquiring locks on the solution state. -
Lazy Snapshot Refresh (
RefreshAsync): When source files change on disk, the running request is not interrupted. Before the next request begins, pending file changes are drained and applied to generate a new immutable snapshot. - Rebasing on Clean State: If an edited file is reverted to its original disk state, Farol rebases the snapshot on the original load solution, preserving existing cached compilations and avoiding redundant recompilation overhead.
-
Project File Invalidation: Edits to source files (
.cs,.vb) produce lightweight syntax/document updates. Edits to project files (.csproj,.vbproj,.sln,.props,.targets) make Farol reload the workspace (ReloadAsync), re-evaluating MSBuild properties and references; a call made meanwhile waits for it.
Traditional tools report all compiler diagnostics present in a solution. In legacy enterprise codebases, this is catastrophic: an older codebase might have hundreds or thousands of pre-existing warnings, deprecation notices, or style violations.
Farol introduces the Diagnostic Baseline:
At Workspace Load:
Solution Loaded ───► Load Snapshot (the baseline)
During Agent Edits:
Current Diagnostics ───► Split(Baseline)
├── Matches Baseline? ──► Silenced (Pre-existing)
└── New Fingerprint? ──► Reported to Agent (Instant Feedback)
The load snapshot is the baseline; a project's or file's baseline diagnostics are computed on first need and cached until the next reload.
A file edited while the workspace is still loading may have been read already edited, so it is no baseline: Farol keeps such files out of it, and the next check that covers one lists all of its diagnostics as new, saying that Farol did not see the file before the change (AC-48).
Diagnostics are fingerprinted using four invariants:
Because the line number is intentionally excluded from the fingerprint, adding or deleting lines above an existing warning shifts its physical line number without marking it as a new issue. Only if the actual code on that line is modified will it be treated as altered.
Although Farol operates primarily over stdio in the MVP, every layer is designed for seamless transition to remote, multi-tenant HTTP gateways (Phase 3):
-
Explicit Workspace Parameter: Every tool accepts an optional
workspaceparameter. In HTTP requests, this parameter is mirrored into theMcp-Param-Workspaceheader. Without it, a call about a file in a root that holds no single solution uses the workspace in use that holds the file, else the solution nearest above it (AC-44). - Zero Session Affinity: No mutable state is stored in the MCP protocol session. A future gateway can route incoming requests across a pool of Farol worker instances by forwarding the target workspace path.
-
Diff-Based Modifications: Tools like
dotnet_code_actionsreturn changes formatted as unified diffs. In local mode, clients can request atomic application (apply=true); in remote environments, diffs are returned for client-side application. -
Root-Relative Paths: Every file location in every response is relative to the root Farol runs in and uses forward slashes (
/); a path outside the root, underFarol:TrustedPaths, is written in full. Arguments may also be relative to the workspace's folder.
When developers work on non-English operating systems (e.g. Portuguese, Japanese, German), the .NET SDK and MSBuild localize error messages by default. This degrades LLM performance, as coding models are trained predominantly on English compiler errors (e.g. CS0103: The name 'x' does not exist in the current context).
Farol enforces English across all compiler interactions:
- Child processes run with
DOTNET_CLI_UI_LANGUAGE=enandVSLANG=1033. - MSBuild invocations pass
-p:PreferredUILang=en-US. - Roslyn diagnostics are rendered using
CultureInfo.InvariantCulture. - Farol ships without satellite resource assemblies (
SatelliteResourceLanguages=en), so Roslyn's own messages stay in English.
Welcome to the official technical documentation for Farol, an open-source Model Context Protocol (MCP) server that equips AI coding agents (Claude Code, GitHub Copilot, Google Antigravity, Cursor, Codex) with compiler-accurate understanding of C# and VB.NET solutions.
- Home — Project overview, value proposition, quickstart, and problem statement
- 01. Architecture & Design Philosophy — Layered architecture, snapshot isolation, BuildHost model, design rationale
- 02. Layer: Farol.Core — Zero-Roslyn foundation: path sandbox, process execution, diffing, atomic writes, privacy
- 03. Layer: Farol.Engine — Workspaces & Loading — MSBuildWorkspaceLoader, analyzer copies, Visual Studio toolchain probing, background warmup, file watcher
- 04. Layer: Farol.Engine — Navigation & Markup — Compiler-accurate navigation, symbol search, IOperation classification, WebForms & XAML indexers, decompilation
- 05. Layer: Farol.Engine — Verification & Testing — Diagnostic checks in about a second, baseline fingerprinting, edits during a load, edit impact analysis, Code Actions, build & test runners
- 06. Layer: Farol.Engine — Legacy Modernization & Packages — Legacy inventory, config inspector, target surface portability, migration planner, NuGet API inspector
- 07. Layer: Farol.Tools & MCP Contract — Comprehensive reference for all 23 MCP tools, 7 prompts, the skill resources and MCP tasks
- 08. Layer: Farol.Host & CLI — Stdio transport, stream isolation, configuration precedence, privacy-first usage telemetry
- 09. Integrations & Plugins — Claude Code plugin (hook & skill), Visual Studio 2026, Copilot, Antigravity, VS Code, NuGet distribution
- 10. Benchmarks & Evals — Performance benchmarks (Umbraco & DNN Platform), evaluation suite and Phase 2 round, compiler oracle
- 11. Phase 2: Refactorings, Analyzers, Loaders & Index — Refactoring write path, analyzers in checks, heuristic and binlog loaders, persistent index, structured output, MCP Registry
- 12. Phase 3: MCP Tasks & Skills — Build, test, load and convert as MCP tasks; the playbook as three skills served by the server; exit results