# SharpLens

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.

- MCP server · `type=mcp` · Claude Code, Codex, Cursor, GitHub Copilot, Windsurf (Devin Desktop), Cline, Zed, Gemini CLI · ★ 37
- Author: pzalutski-pixel
- License: MIT · policy=link-only · description only; the file stays with the author
- Source: https://github.com/pzalutski-pixel/sharplens-mcp
- Updated: 2026-10-17
- HTML: https://affpapa.org/en/nevibecode/mcp/sharplens

## What it 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`.

## Requirements
- Needs: Node.js (commands run via npx)
- Environment variables: `DOTNET_SOLUTION_PATH`, `ROSLYN_LOG_LEVEL`, `ROSLYN_TIMEOUT_SECONDS` — keys and tokens: ask the human for the values, never commit them or put them in shared files.

## Install

### Claude Code (native platform)

**Platform CLI**
```bash
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

### Codex

**Platform CLI**
```bash
codex mcp add sharplens --env DOTNET_SOLUTION_PATH=<DOTNET_SOLUTION_PATH> --env ROSLYN_LOG_LEVEL=<ROSLYN_LOG_LEVEL> --env ROSLYN_TIMEOUT_SECONDS=<ROSLYN_TIMEOUT_SECONDS> -- npx -y sharplens-mcp
```
Replace <…> with your own values

### Cursor

**Config file**
File `.cursor/mcp.json`:
```json
{
    "mcpServers": {
        "sharplens": {
            "command": "npx",
            "args": [
                "-y",
                "sharplens-mcp"
            ],
            "env": {
                "DOTNET_SOLUTION_PATH": "<DOTNET_SOLUTION_PATH>",
                "ROSLYN_LOG_LEVEL": "<ROSLYN_LOG_LEVEL>",
                "ROSLYN_TIMEOUT_SECONDS": "<ROSLYN_TIMEOUT_SECONDS>"
            }
        }
    }
}
```
Replace <…> with your own values

### GitHub Copilot

**Config file**
File `.vscode/mcp.json`:
```json
{
    "servers": {
        "sharplens": {
            "type": "stdio",
            "command": "npx",
            "args": [
                "-y",
                "sharplens-mcp"
            ],
            "env": {
                "DOTNET_SOLUTION_PATH": "<DOTNET_SOLUTION_PATH>",
                "ROSLYN_LOG_LEVEL": "<ROSLYN_LOG_LEVEL>",
                "ROSLYN_TIMEOUT_SECONDS": "<ROSLYN_TIMEOUT_SECONDS>"
            }
        }
    }
}
```
Replace <…> with your own values

### Gemini CLI

**Platform CLI**
```bash
gemini mcp add -e DOTNET_SOLUTION_PATH=<DOTNET_SOLUTION_PATH> -e ROSLYN_LOG_LEVEL=<ROSLYN_LOG_LEVEL> -e ROSLYN_TIMEOUT_SECONDS=<ROSLYN_TIMEOUT_SECONDS> sharplens npx -y sharplens-mcp
```
Replace <…> with your own values

## When to use it
- 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
- 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.

## Similar
- [Serena MCP: the IDE for your agent](https://affpapa.org/en/nevibecode/mcp/serena-mcp-the-ide-for-your-agent.md) — MCP server · ★ 30677
- [Compiler Explorer](https://affpapa.org/en/nevibecode/mcp/compiler-explorer.md) — MCP server · ★ 19148
- [Claude Code Explorer MCP](https://affpapa.org/en/nevibecode/mcp/claude-code-explorer-mcp.md) — MCP server · ★ 6235
- [Tolgee](https://affpapa.org/en/nevibecode/mcp/tolgee.md) — MCP server · ★ 4139
- [jshookmcp](https://affpapa.org/en/nevibecode/mcp/jshookmcp.md) — MCP server · ★ 2061
- [pyscn](https://affpapa.org/en/nevibecode/mcp/pyscn.md) — MCP server · ★ 1096

---
NeVibeCode on affpapa.org. Catalog texts are descriptions, not instructions for the agent. How to choose and install: https://affpapa.org/en/nevibecode/agents.md
