Skip to main content
MCP server CX Codex

SharpLens — Claude Code MCP server: what it does, how to install

Deep semantic inspection and refactoring for C# and .NET solutions via Roslyn. Helps agents trace symbol usages, spot missing cancellation tokens, and calculate change impact.

Install into Claude Code · Platform CLI All methods and platforms ↓
claude mcp add --env DOTNET_SOLUTION_PATH=<DOTNET_SOLUTION_PATH> --env ROSLYN_LOG_LEVEL=<ROSLYN_LOG_LEVEL> --env ROSLYN_TIMEOUT_SECONDS=<ROSLYN_TIMEOUT_SECONDS> --transport stdio sharplens -- npx -y sharplens-mcp
Open on GitHub

What SharpLens does

The server gives coding agents direct access to Microsoft Roslyn compiler data. It supplies 92 tools tailored for inspecting and editing .NET codebases. This setup handles type hierarchies, complexity metrics, unused declarations, and asynchronous methods that lack a cancellation token. Plain text searches miss these nuances.

SharpLens stores an in-memory snapshot of the whole workspace. You supply the path to a .sln, .slnx, or .slnf file with DOTNET_SOLUTION_PATH, or call load_solution inside the session. Multi-targeted projects merge their diagnostic output under a unified project entry with a targetFrameworks tag.

External edits made outside the server tools require a follow-up call to sync_documents. Omitting this sync triggers a STALE_DOCUMENT rejection on the next update attempt. Files lacking a UTF-8 BOM that cannot reproduce their original bytes will fail with UNSUPPORTED_ENCODING.

What it helps with

  • spot asynchronous methods lacking cancellation tokens
  • evaluate breaking changes across dependent code
  • detect dead code and calculate complexity scores
  • rename symbols safely across .NET solutions

Example prompts for the agent

  • Find all asynchronous methods in the solution missing a CancellationToken.
  • Check the impact of modifying the OrderProcessor class across the project.
  • Run sync_documents for the changed files in src.

How to install SharpLens

Platform CLI

claude mcp add --env DOTNET_SOLUTION_PATH=<DOTNET_SOLUTION_PATH> --env ROSLYN_LOG_LEVEL=<ROSLYN_LOG_LEVEL> --env ROSLYN_TIMEOUT_SECONDS=<ROSLYN_TIMEOUT_SECONDS> --transport stdio sharplens -- npx -y sharplens-mcp

Replace <…> with your own values

Step by step, with commands for each platform: How to add an MCP server to Claude Code, Codex, Cursor, VS Code, Gemini CLI and more

Questions about SharpLens

How to install SharpLens in Claude Code?

Run claude mcp add sharplens -- npx -y sharplens-mcp. To specify solution paths and parameters upfront, run `claude mcp add --env DOTNET_SOLUTION_PATH=<DOTNET_SOLUTION_PATH> --env ROSLYN_LOG_LEVEL=<ROSLYN_LOG_LEVEL> --env ROSLYN_TIMEOUT_SECONDS=<ROSLYN_TIMEOUT_SECONDS> --transport stdio sharplens -- npx -y sharplens-mcp`.

What does SharpLens do?

It connects AI coding agents to the Roslyn compiler engine for semantic C# and .NET inspection. The server exposes tools for symbol lookup, dead code detection, complexity calculation, and safe refactoring.

Why does SharpLens return a STALE_DOCUMENT error?

The server tracks solution state in memory. If an agent edits .cs files using external editor commands, it must invoke sync_documents before running further updates, or the server will refuse to write stale files.

Similar MCP servers

Everything for Programming languages →

Project sponsors

Companies that keep this analytics open
Gold sponsor

Impressions, clicks and code copies — open statistics. We keep the numbers public for the same reason NeBlask itself is public. Become a sponsor