A Model Context Protocol (MCP) server for intelligent C# project analysis and semantic code editing. Provides Claude Code with deep understanding of C# projects including cross-file dependencies, project structure, and Roslyn-based semantic operations.
- MCP Protocol Server — JSON-RPC 2.0 over stdio for Claude Code integration
- File Operations — Open projects, list files with glob patterns, read/write/edit files
- Roslyn Integration — Direct Roslyn APIs for C# semantic analysis (no subprocess overhead)
- Semantic Editing — Find classes, add properties/methods with proper indentation
- AI-Powered Tools — Natural language codebase queries using local Ollama or cloud AI (implements AI-Powered MCP pattern)
- Cross-platform — macOS, Linux, and Windows support
Claude Code
↓ MCP (stdio, JSON-RPC)
┌─────────────────────────────────┐
│ MCPsharp Server │
├─────────────────────────────────┤
│ • MCP Protocol Handler │
│ • Project Context Manager │
│ • File Operations Service │
│ • Roslyn Workspace (Phase 1) │
└─────────────────────────────────┘
↓ (in-process)
Roslyn APIs
See docs/CONCEPT.md for full design and docs/ARCHITECTURE-DECISION.md for architectural choices.
- .NET 9.0 SDK or later
- Git
# Restore dependencies
dotnet restore
# Build
dotnet build
# Build in Release mode
dotnet build --configuration Release
# Run tests
dotnet test
# Run tests with coverage
dotnet test --collect:"XPlat Code Coverage"# Linux x64
dotnet publish src/MCPsharp/MCPsharp.csproj -c Release -r linux-x64 --self-contained -o publish/linux-x64
# macOS arm64 (Apple Silicon)
dotnet publish src/MCPsharp/MCPsharp.csproj -c Release -r osx-arm64 --self-contained -o publish/osx-arm64
# macOS x64 (Intel)
dotnet publish src/MCPsharp/MCPsharp.csproj -c Release -r osx-x64 --self-contained -o publish/osx-x64
# Windows x64
dotnet publish src/MCPsharp/MCPsharp.csproj -c Release -r win-x64 --self-contained -o publish/win-x64Add to your Claude Code claude_desktop_config.json:
{
"mcpServers": {
"csharp": {
"command": "/path/to/mcpsharp",
"args": ["/path/to/your/csharp/project"]
}
}
}Or using dotnet run for development:
{
"mcpServers": {
"csharp": {
"command": "dotnet",
"args": ["run", "--project", "/path/to/MCPsharp/src/MCPsharp/MCPsharp.csproj", "/path/to/your/csharp/project"]
}
}
}MCPsharp includes AI-powered tools that use local or cloud AI to answer natural language questions about your codebase. This implements the AI-Powered MCP pattern — AI processes verbose data internally and returns concise answers, preventing context pollution.
MCPsharp auto-detects available AI providers in this order:
- Ollama (Local, free, recommended)
- OpenRouter (Cloud-based, requires API key)
- None (AI tools disabled)
Install and run Ollama locally:
# macOS
brew install ollama
# Linux
curl -fsSL https://ollama.com/install.sh | sh
# Start Ollama service
ollama serve
# Pull a code-specialized model
ollama pull qwen2.5-coder:3bMCPsharp will automatically detect Ollama at http://localhost:11434 and use qwen2.5-coder:3b by default.
Environment variables:
OLLAMA_URL— Ollama server URL (default:http://localhost:11434)OLLAMA_MODEL— Model to use (default:qwen2.5-coder:3b)
Configure OpenRouter API key:
export OPENROUTER_API_KEY="your-api-key"Or add to your configuration file. MCPsharp will use anthropic/claude-3.5-sonnet by default.
Set AIProvider:Type to none in configuration to disable AI-powered tools.
Once configured, use the ask_codebase tool to ask natural language questions:
{
"name": "ask_codebase",
"arguments": {
"question": "How does authentication work in this project?",
"focus_path": "src/Auth"
}
}The focus_path argument is optional. The AI analyzes your codebase structure, code, and configuration internally and returns a concise answer with file:line references.
In addition to read-only queries, MCPsharp provides AI-powered code modification tools that use Roslyn AST transformations to guarantee correctness:
{
"name": "ai_suggest_fix",
"arguments": {
"file_path": "src/MyService.cs",
"description": "Fix the null reference exception in ProcessData",
"line_number": 42,
"apply_changes": false
}
}The apply_changes parameter defaults to false to preview changes before applying them.
Why Roslyn AST instead of text manipulation?
Traditional tools use sed scripts, regex, or Python text manipulation which can:
- Generate syntactically invalid code
- Break compilation
- Corrupt code structure
- Introduce subtle bugs
MCPsharp's AI transformation tools use Roslyn's Abstract Syntax Tree (AST) to:
- ✅ Guarantee syntactically valid C# code
- ✅ Preserve compilation integrity
- ✅ Maintain code structure and formatting
- ✅ Validate changes before returning them
- ✅ Use semantic awareness for refactoring
Available transformation tools:
ai_suggest_fix- Bug fixes with Roslyn validationai_refactor- Semantic-aware refactoring (preserves behavior)ai_implement_feature- AST-based code generation
All tools return a preview by default. Set apply_changes: true to modify files directly.
# Run on current directory (auto-loads .sln/.csproj if found)
dotnet run --project src/MCPsharp/MCPsharp.csproj
# Run on specific project
dotnet run --project src/MCPsharp/MCPsharp.csproj /path/to/project
# Or use published binary
./mcpsharp /path/to/projectAuto-Loading: If MCPsharp is launched in a directory containing .sln or .csproj files, it will automatically load the project on startup. Solution files (.sln) are preferred over project files when both exist.
# Test initialize
echo '{"jsonrpc":"2.0","id":1,"method":"initialize","params":{}}' | dotnet run --project src/MCPsharp/MCPsharp.csproj
# Test tools/list
echo '{"jsonrpc":"2.0","id":1,"method":"tools/list","params":{}}' | dotnet run --project src/MCPsharp/MCPsharp.csproj
# Run manual test script
./tests/manual-test.shThe server provides 40 MCP tools:
File Operations:
project_open- Open a project directoryproject_info- Get current project informationfile_list- List files with optional glob patternsfile_read- Read file contentsfile_write- Write to a filefile_edit- Apply text edits to a file
Roslyn/Semantic Analysis:
find_symbol- Find symbols by nameget_symbol_info- Get detailed symbol informationget_class_structure- Get complete class structureadd_class_property- Add a property to a classadd_class_method- Add a method to a classfind_references- Find all symbol referencesfind_implementations- Find interface implementationsparse_project- Parse .csproj files
Workflow & Configuration:
get_workflows- Get GitHub Actions workflowsparse_workflow- Parse workflow YAMLvalidate_workflow_consistency- Validate workflow vs projectget_config_schema- Get config file schemamerge_configs- Merge configuration files
Advanced Analysis (Phase 2):
analyze_impact- Analyze code change impacttrace_feature- Trace features across filesrename_symbol- Rename symbols across the codebasefind_callers- Find all callers of a methodfind_call_chains- Analyze method call chainsfind_type_usages- Find all usages of a typeanalyze_call_patterns- Analyze method call patternsanalyze_inheritance- Analyze type inheritancefind_circular_dependencies- Find circular dependenciesfind_unused_methods- Find unused methodsanalyze_call_graph- Analyze call graphsfind_recursive_calls- Find recursive call chainsanalyze_type_dependencies- Analyze type dependencies
Code Quality:
code_quality_analyze- Analyze code quality issuescode_quality_fix- Apply automated fixescode_quality_profiles- List available fix profilesextract_method- Extract code to new method
AI-Powered Tools (Read-Only):
ask_codebase- Ask natural language questions about the codebase using AI (returns concise answers, not verbose data)
AI-Powered Code Transformation (Roslyn AST-based):
ai_suggest_fix- AI suggests bug fixes using Roslyn transformations (guarantees syntactically valid C#)ai_refactor- AI-guided refactoring with semantic awareness (preserves program behavior)ai_implement_feature- AI implements features using AST-based code generation (no string templates)
IMPORTANT: The AI transformation tools use Roslyn AST instead of text manipulation (sed/regex/Python) to ensure all code changes are syntactically valid and preserve compilation integrity. Always prefer these tools for C# code modifications.
MCPsharp/
├── src/
│ └── MCPsharp/ # Main MCP server
├── tests/
│ └── MCPsharp.Tests/ # xUnit tests
├── docs/ # Documentation
│ ├── CONCEPT.md # Design document
│ ├── MVP-PLAN.md # Implementation plan
│ └── ARCHITECTURE-DECISION.md
├── .github/
│ └── workflows/
│ └── build.yml # CI/CD workflow
└── MCPsharp.sln # Solution file
# Run all tests
dotnet test
# Run tests with detailed output
dotnet test --verbosity detailed
# Run specific test project
dotnet test tests/MCPsharp.Tests/MCPsharp.Tests.csproj
# Watch mode (re-run on file changes)
dotnet watch test# Run with debug output
dotnet run --project src/MCPsharp/MCPsharp.csproj --configuration Debug
# Attach debugger in VS Code or Riderproject_open— Open a C# project directoryproject_info— Get project metadatafile_list— List files with glob patternsfile_read— Read file contentsfile_write— Write file contentsfile_edit— Apply text edits
language_server_start— Initialize Roslyn workspacefind_symbol— Find classes, methods, properties by nameget_symbol_info— Get detailed symbol informationget_class_structure— Get class members and structureadd_class_property— Add property to class with correct indentationadd_class_method— Add method to classfind_references— Find all references to a symbol
See docs/MVP-PLAN.md for detailed tool specifications.
- Microsoft.CodeAnalysis.CSharp (4.11.0) — Roslyn C# compiler APIs
- Microsoft.CodeAnalysis.CSharp.Workspaces (4.11.0) — Roslyn workspace APIs
- Microsoft.Extensions.FileSystemGlobbing (9.0.0) — Glob pattern matching
- Microsoft.Extensions.Logging (9.0.0) — Logging infrastructure
- xUnit (2.9.2) — Test framework
- FluentAssertions (6.12.1) — Fluent assertion library
- Moq (4.20.72) — Mocking framework
- coverlet.collector (6.0.2) — Code coverage
GitHub Actions workflow runs on every push and PR:
- Builds on Linux, macOS, and Windows
- Runs all tests with code coverage
- Publishes self-contained binaries on main branch
- Uploads coverage to Codecov
- ✅ Phase 0 (Current): Basic MCP server with file operations
- 🚧 Phase 1 (Next): Roslyn integration for semantic C# operations
- 📋 Phase 2 (Future): Project/solution parsing, multi-project support
- 📋 Phase 3 (Future): Configuration analysis, workflow validation
- 📋 Phase 4 (Future): Database migrations, refactoring tools
This is a personal project by @jas88. Contributions are welcome!
- Fork the repository
- Create a feature branch
- Make your changes with tests
- Submit a pull request
[To be determined]
- CONCEPT.md — Full design specification
- MVP-PLAN.md — Implementation plan and timeline
- ARCHITECTURE-DECISION.md — Why direct Roslyn vs subprocess
- CLAUDE.md — Instructions for Claude Code instances