This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
NetContextServer is a .NET 9.0 Model Context Protocol (MCP) server that provides AI coding assistants with deep understanding of .NET codebases. It consists of three main projects:
NetContextServer: MCP server implementationNetContextClient: CLI interface for server interactionNetContextServer.Tests: Comprehensive test suite
# Build the solution
dotnet build
# Run tests
dotnet test
# Run the server
dotnet run --project src/NetContextServer/NetContextServer.csproj
# Run the client with a command
dotnet run --project src/NetContextClient/NetContextClient.csproj -- [command]
# Run a specific test
dotnet test --filter "FullyQualifiedName~TestName"
# Run tests with coverage
dotnet test --collect:"XPlat Code Coverage"# Publish for Windows
dotnet publish -c Release -r win-x64 --self-contained
# Publish for Linux
dotnet publish -c Release -r linux-x64 --self-contained
# Publish for macOS
dotnet publish -c Release -r osx-x64 --self-containedThe codebase follows a clean service-based architecture where business logic is encapsulated in services under src/NetContextServer/Services/. Each service has a corresponding interface and handles a specific domain concern.
Tools are organized under src/NetContextServer/Tools/ and grouped by functionality:
- FileTools: Project/file operations (
ListProjects,ListSourceFiles,ReadFile) - SearchTools: Text and semantic search (
SearchCode,SemanticSearch) - PackageTools: NuGet package analysis (
AnalyzePackages) - CoverageTools: Test coverage analysis (
GetCoverage) - ThinkTools: Structured reasoning (
Think)
Each tool class inherits from ModelContextTool<TArgs, TResult> and implements the MCP protocol.
- FileService: File system operations with security validation
- CodeSearchService: Text-based code search using regex
- SemanticSearchService: AI-powered semantic search with Azure OpenAI embeddings
- PackageAnalyzerService: NuGet dependency analysis and update recommendations
- CoverageAnalysisService: Multi-format coverage report parsing (Coverlet, LCOV, Cobertura)
User patterns and preferences are persisted in %LocalAppData%/NetContextServer/state.json through the StateService.
- Path validation ensures operations stay within allowed directories
- File size limits prevent resource exhaustion
- Sensitive files (.env, secrets) are protected from access
- All file operations validate against these security constraints
Tests are organized using xUnit with fixture-based integration testing:
- Unit Tests: Test individual services in isolation
- Integration Tests: Use
NetContextServerFixturefor full tool testing - Test Utilities:
TestOutputLoggerfor debugging test execution
When adding new features:
- Add unit tests for service logic
- Add integration tests for MCP tool implementations
- Use the existing fixture pattern for consistency
The server supports various configuration options through:
- Environment variables for Azure OpenAI integration
- Command-line arguments for server initialization
- Local state file for user preferences
When working with semantic search features, ensure Azure OpenAI credentials are configured in environment variables.