SharpLens
io.github.pzalutski-pixelPublished by GitHub account pzalutski-pixelv1.5.3Updated Oct 26, 2026
67 semantic C#/.NET analysis tools via Roslyn: navigation, refactoring, codegen, audit.
Overview
Local MCP server that gives an AI assistant Roslyn-based semantic analysis of C#/.NET solutions: navigation, refactoring, code generation and code audit.
- What you can do
- Navigate and search symbols: definitions, references, implementations, callers, call graphs, type hierarchies, overloads, attributes and XML docs
- Analyze code: compiler and analyzer diagnostics, change impact, data and control flow, complexity metrics, dead code, circular dependencies, API-surface diffs
- Refactor and generate: rename, change signature, extract method or interface, organize usings, format, apply code actions, add null checks, equality members and test stubs
- Audit quality: god objects, untested code, async issues, architecture rules, naming violations, unused dependencies
- Inspect the workspace: load a solution, sync edited files, view project structure, dependency graphs…
- When to use it
- Useful when an assistant works on a C#/.NET codebase and needs compiler-accurate answers that plain text search or an LSP cannot give, such as impact analysis, dead code, complexity metrics or safe solution-wide refactors with preview.
- Requirements
- Runs locally over stdio, installed as a .NET global tool or via npx. Needs the .NET 8.0 SDK or later and an MCP-capable client. Set DOTNET_SOLUTION_PATH to a .sln, .slnx or .slnf file, or call load_solution first. Optional settings include SHARPLENS_LOG_LEVEL, SHARPLENS_TIMEOUT_SECONDS, SHARPLENS_MAX_DIAGNOSTICS, SHARPLENS_ABSOLUTE_PATHS and SHARPLENS_ENABLE_SEMANTIC_CACHE. No authentication is declared.
Installation
In SourceWeft
- Open SharpLens in the dashboard and add it to a workspace.
- Enable the server for the chats that should use its tools.
Desktop only via STDIO. STDIO servers start a local process, so they need the SourceWeft desktop host.
Other MCP clients
Follow the launch instructions in the repository.
README
SharpLensMcp
A Model Context Protocol (MCP) server providing 92 AI-optimized tools for .NET/C# semantic code analysis, navigation, refactoring, and code generation using Microsoft Roslyn.
Built for AI coding agents - provides compiler-accurate code understanding that AI cannot infer from reading source files alone.
Installation
Via NuGet (Recommended)
Then run with:
Via npm
Build from Source
Claude Code Setup
- Install the tool (pick one):
- Create
.mcp.jsonin your project root:
-
Restart Claude Code to load the MCP server
-
Verify by asking Claude to run a health check on the Roslyn server
Why Use This with Claude Code?
Claude Code has native LSP support for basic navigation (go-to-definition, find references). SharpLensMcp adds deep semantic analysis:
Configuration
The pre-1.6.0 ROSLYN_* spellings of these variables are still read as a fallback; the SHARPLENS_* spelling wins when both are set. Boolean values are case-insensitive. A number that does not parse or is below its minimum falls back to the default, and one above its maximum is capped; each case logs a warning to stderr.
Multi-targeted projects
A project built for several target frameworks is one project to every tool: each result is reported once, with a targetFrameworks list where it exists only under some frameworks. projectName accepts the plain name (MyLib) for all frameworks, or a framework-qualified name (MyLib(net8.0)) for one.
If DOTNET_SOLUTION_PATH is not set, you must call the load_solution tool before using other tools.
Migrating from 1.5.x tool names
Tool names no longer carry the roslyn: prefix — the colon violates the MCP tool-name pattern (^[a-zA-Z0-9_-]{1,64}$), which some clients enforce. Every tool keeps its name minus the prefix:
tools/list publishes only the new names. Calls using the old prefixed names are still accepted as aliases for one release and will be removed in the following one.
AI Agent Configuration Tips
AI models may have trained bias toward using their native tools (Grep, Read, LSP) instead of MCP server tools, even when SharpLensMcp provides better capabilities.
To ensure optimal tool usage:
-
Claude Code: Add to your project's
CLAUDE.md: -
Other MCP clients: Configure tool priority in your agent's system prompt
The semantic analysis from Roslyn is more accurate than text-based search, especially for overloaded methods, partial classes, and inheritance hierarchies.
Agent Responsibility: Document Synchronization
Important: SharpLensMcp maintains an in-memory representation of your solution for fast queries. When files are modified externally (via Edit/Write tools), the agent is responsible for synchronizing changes.
When to call sync_documents:
Usage:
A full sync also picks up new .cs files the project's compile items include. SharpLensMcp's apply tools write only the files an edit changes, keep each file's encoding and line endings, and refuse with STALE_DOCUMENT when a target file changed on disk since it was read — run sync_documents, then retry. They also refuse with UNSUPPORTED_ENCODING to write a file whose bytes its encoding cannot reproduce (a BOM-less file that is not valid UTF-8 on a system whose fallback code page is UTF-8, such as Linux); save it as UTF-8 first.
Why this design?
This mirrors how LSP (Language Server Protocol) works - the client (editor) notifies the server of changes. This approach:
- Eliminates race conditions (agent controls timing)
- Avoids file watcher complexity and platform quirks
- Is faster than full solution reload
- Gives agents explicit control over workspace state
If you don't sync: Queries may return stale data (old method signatures, missing new files, etc.)
Features
- 92 Semantic Analysis Tools - Navigation, refactoring, code generation, diagnostics, discovery, audit/quality
- AI-Optimized Descriptions - Clear USAGE/OUTPUT/WORKFLOW patterns
- Structured Responses - Consistent
success/error/dataformat withsuggestedNextTools - Zero-Based Coordinates - Clear warnings to prevent off-by-one errors
- Preview Mode - Safe refactoring with preview before apply
- Batch Operations - Multiple lookups in one call to reduce context usage
Tool Categories
Navigation & Discovery (24 tools)
Analysis (17 tools)
Refactoring (16 tools)
Code Generation (3 tools)
Compound Tools (7 tools)
Audit & Quality (10 tools)
Discovery (3 tools)
Infrastructure (12 tools)
Other MCP Clients
For MCP clients other than Claude Code, add to your configuration:
Usage
- Load a solution: Call
load_solutionwith path to.slnor.slnxfile (or setDOTNET_SOLUTION_PATH) - Analyze code: Use any of the 92 tools for navigation, analysis, refactoring, audit
- Refactor safely: Preview changes before applying with
preview: true
Architecture
Requirements
- .NET 8.0 SDK or later — works with .NET 8, 9, 10, and future versions. Analyzes any .NET 8+ project/solution.
- MCP-compatible AI agent
FAQ
Why does the tool target net8.0 — can it analyze my .NET 9 / .NET 10 project?
Yes. net8.0 is the tool's own runtime floor — the Roslyn 5.x packages it builds on require it — not a ceiling on what it can analyze. RollForward lets the installed tool run on newer .NET runtimes, and MSBuildWorkspace loads each project's real target framework from its csproj, so one install analyzes solutions targeting .NET 8, 9, 10, and beyond.
Development
Adding New Tools
- Add the method to the matching
src/RoslynService.*.cspartial (Navigation, Analysis, Refactoring, CallAnalysis, …) and return through the shared response envelope:
-
Register one
ToolDefinitioninsrc/ToolRegistry.cs— its name, description, input schema, theReadOnlyflag (mutating tools passReadOnly: falseand receive adestructiveHintannotation), and a handler that binds arguments throughJsonRpcParametersand calls your method. The registry drives bothtools/listand dispatch; there is no separate switch to edit. Two tests keep it honest:ToolsListGoldenTestslocks the published schema byte-for-byte (re-capture the golden when a schema change is intentional), andToolSchemaParityTestsasserts every parameter the handler reads is declared in the schema. -
Build and publish:
- Add both test levels — a unit test of the
RoslynServicemethod against a deterministic fixture, AND a wire test through the MCP dispatcher (intests/SharpLensMcp.Tests/Mcp/) with exact value locks plus an error path. This is non-negotiable; see Testing.
Testing
Every test must satisfy the Testing Charter (C1–C9) in tests/SharpLensMcp.Tests/TESTING.md — the standing contract. The headline rules:
- Lock exact values (C1): assert a concrete name / count / substring / error code /
(line, column)— neverNotBeNull/> 0/ a type-only check as the sole assertion. - Both levels per tool (C4): a unit test against a
Fixtures/*.csfixture and a dispatcher (wire) test that unwrapscontent[0].text, plus an error path. - Right casing (C3): in-process Newtonsoft yields PascalCase
error.Code/meta.TotalCount; the MCP wire yields camelCase. Read the casing your test's path actually produces. - Deterministic (C7): the suite is serialized via
xunit.runner.json; fixture mutators always restore; the timeout test uses a forced-cancellation seam, not a timing race. - Out-of-process spine (C6):
StdioIntegrationTestsvalue-pins one tool per category over the real binary and runs thetools/listgolden over the stdio pipe. - Pre-commit gate (C9): build-clean + green is necessary but not sufficient — re-read each changed test and confirm it fails on a wrong answer.
Run the suite:
Key Files
License
MIT - See LICENSE for details.
Source: README.md at commit 35c4196
Tools
0Version history
1- v1.5.3LatestSep 16, 2026
Score
50% of the applicable checks met
How complete this listing is, computed from the registry entry, the endpoint and public sources. Not a rating of the server and not a statement that it is safe or working today: reachability is a dated check, and no installs or reviews go into the score.
- Reached in the last 30 days25 pts
Keep the endpoint answering the MCP handshake; SourceWeft probes it every 30 days.
- Auth declared10 pts
Declare the credential headers in the registry entry, or keep the endpoint answering the probe so its auth can be classified.
- Tools listed15 pts
Answer tools/list without a credential, or ship a package that starts in a sandbox without one.
- DescriptionRequired15 pts
- Logo10 pts
- Documentation15 pts
- License10 pts