NetContextServer empowers AI coding assistants like VS Code to deeply understand your .NET codebase through the Model Context Protocol (MCP). This means more accurate code suggestions, better answers to your questions, and a more productive coding experience.
- π§ Semantic Code Search: Find code by describing what you're looking for in natural language
- π Intelligent Navigation: Help AI tools understand your project structure and dependencies
- π‘οΈ Built-in Security: Safe file access with automatic protection of sensitive data
- π VS Code Integration: Seamless setup with VS Code for enhanced coding assistance
- π¦ Package Analysis: Understand your dependencies and get update recommendations
- π Deep Dependency Visualization: See transitive dependencies with interactive, color-coded graphs
- π§© Smart Grouping: Visually group related packages for easier navigation
- π Update Recommendations: Identify outdated packages and security issues
- π Test Coverage Analysis: Deep insights into your test coverage
- π― Multi-Format Support: Parse coverage data from Coverlet, LCOV, and Cobertura XML
- π Detailed Reports: File-level coverage percentages and uncovered line tracking
- π Branch Coverage: Track method-level branch coverage where available
- π‘ Smart Recommendations: Get suggestions for improving test coverage
- β‘ Fast & Efficient: Quick indexing and response times for large codebases
- Clone & Build:
git clone https://github.com/willibrandon/NetContextServer.git
cd NetContextServer
dotnet build
- Set Up (optional, for semantic search):
# Set Azure OpenAI credentials in environment:
AZURE_OPENAI_ENDPOINT=your_endpoint
AZURE_OPENAI_API_KEY=your_key
- Start Using:
# Point to your project
dotnet run --project src/NetContextClient/NetContextClient.csproj -- set-base-dir --directory "path/to/your/project"
# Try semantic search
dotnet run --project src/NetContextClient/NetContextClient.csproj -- semantic-search --query "find authentication logic"
π Read our Getting Started Guide for detailed setup instructions and best practices.
- Open Visual Studio Code
- Press
Ctrl + Shift + P
(orCmd + Shift + P
on macOS) - Type "Configure MCP Server"
- Enter:
{
"command": "dotnet",
"args": ["run", "--project", "path/to/NetContextServer/src/NetContextServer/NetContextServer.csproj"]
}
Now VS Code can understand your codebase! Try asking it questions like:
- "List all .NET source files in this project directory"
- "Search for exact text matches in the code files"
- "Analyze NuGet packages in all projects"
- "Get the current list of ignore patterns"
- "Add these ignore patterns: .generated.cs, bin/"
- "List all .csproj files in this directory"
- "Show me the contents of this file"
- "What's the current base directory for file operations?"
- "Help me think through the authentication system design"
- "Document my reasoning about this architectural decision"
- "Analyze test coverage for MyService.cs"
- "Show me uncovered lines in the authentication module"
- "What's the overall test coverage percentage?"
- "Which files have the lowest test coverage?"
- Getting Started Guide - Quick setup and first steps
- Tool Reference - Detailed tool documentation
- Configuration Guide - Advanced configuration options
- Integration Examples - Using with different AI tools
- Contributing Guide - How to help improve NetContextServer
- π Project & File Listing: List all projects and source files in your solution
- π Code Search: Search through your codebase for specific patterns or text
- π§ Semantic Search: Find code based on meaning, not just exact text matches
- π File Content Access: Read source files with safety checks and size limits
- π‘οΈ Security: Built-in safeguards for sensitive files and directory access
- π― Pattern Management: Flexible ignore patterns for controlling file access
- π Coverage Analysis: Parse and analyze test coverage data
- π Coverage Reports: Support for Coverlet JSON, LCOV, and Cobertura XML formats
- π― Line Coverage: Track which lines are covered by tests
- π³ Branch Coverage: Monitor method-level branch coverage
- π‘ Recommendations: Get actionable suggestions to improve coverage
- π Structured Thinking: Document and validate reasoning about complex operations
- π§© AI-Optimized Reasoning: Based on Anthropic's research on improving LLM problem-solving
- π Task Planning: Break down complex problems into manageable steps
- β Policy Compliance: Verify solutions against project guidelines
- π Tool Output Analysis: Process results from other tools before taking next actions
- π Decision Documentation: Maintain audit trails of architectural choices
- Clone the repository:
git clone https://github.com/willibrandon/NetContextServer.git
cd NetContextServer
- Build the solution:
dotnet build
- Run the tests (optional):
dotnet test
Use the client to interact with your codebase:
dotnet run --project src/NetContextClient/NetContextClient.csproj -- <command> [options]
For semantic search functionality, you need to set up the following environment variables:
AZURE_OPENAI_ENDPOINT
: Your Azure OpenAI endpoint URLAZURE_OPENAI_API_KEY
: Your Azure OpenAI API key
- Set Base Directory:
dotnet run --project src/NetContextClient/NetContextClient.csproj -- set-base-dir --directory "D:\YourProject"
- Get Base Directory:
dotnet run --project src/NetContextClient/NetContextClient.csproj -- get-base-dir
- Get Version Information:
dotnet run --project src/NetContextClient/NetContextClient.csproj -- version
- List Projects:
dotnet run --project src/NetContextClient/NetContextClient.csproj -- list-projects-in-dir --directory "D:\YourProject\src"
- List Source Files:
dotnet run --project src/NetContextClient/NetContextClient.csproj -- list-source-files --project-dir "D:\YourProject\src\YourProject"
- Analyze Packages:
# Set your base directory first
dotnet run --project src/NetContextClient/NetContextClient.csproj -- set-base-dir --directory "path/to/your/project"
# Run the package analysis
dotnet run --project src/NetContextClient/NetContextClient.csproj -- analyze-packages
Example output:
Project: MyProject.csproj
Found 2 package(s):
- β
Newtonsoft.Json (13.0.1)
Used in 5 location(s)
Dependencies:
ββ Newtonsoft.Json
ββ System.*
ββ System.ComponentModel
- π Microsoft.Extensions.DependencyInjection (5.0.2 β 6.0.1)
Update available: 6.0.1
Dependencies:
ββ Microsoft.Extensions.DependencyInjection
ββ Microsoft.*
ββ Microsoft.Extensions.DependencyInjection.Abstractions
- Analyze Test Coverage:
# Set your base directory first
dotnet run --project src/NetContextClient/NetContextClient.csproj -- set-base-dir --directory "path/to/your/project"
# Analyze coverage from a Coverlet JSON report
dotnet run --project src/NetContextClient/NetContextClient.csproj -- coverage-analysis --report-path "TestResults/coverage.json"
# Get a coverage summary
dotnet run --project src/NetContextClient/NetContextClient.csproj -- coverage-summary --report-path "TestResults/coverage.json"
Example coverage analysis output:
[{
"filePath": "src/MyProject/Services/UserService.cs",
"coveragePercentage": 85.3,
"uncoveredLines": [42, 43, 88],
"branchCoverage": {
"ValidateUser()": 75.0,
"GetUserById()": 100.0
},
"recommendation": "Consider adding tests for the user validation error paths"
}
]
- Text Search:
dotnet run --project src/NetContextClient/NetContextClient.csproj -- search-code --text "authentication"
- Semantic Search:
# Search with default number of results (5)
dotnet run --project src/NetContextClient/NetContextClient.csproj -- semantic-search --query "handle user authentication"
# Search with custom number of results
dotnet run --project src/NetContextClient/NetContextClient.csproj -- semantic-search --query "database connection string" --top 10
The semantic search feature:
- Uses embeddings to find code based on meaning
- Returns code snippets ranked by relevance
- Shows line numbers and similarity scores
- Automatically indexes your code on first search
- Add Ignore Patterns:
dotnet run --project src/NetContextClient/NetContextClient.csproj -- add-ignore-patterns --patterns "*.txt" "*.log"
- View Current Patterns:
dotnet run --project src/NetContextClient/NetContextClient.csproj -- get-ignore-patterns
- Remove Specific Patterns:
dotnet run --project src/NetContextClient/NetContextClient.csproj -- remove-ignore-patterns --patterns "*.txt"
- Clear User Patterns:
dotnet run --project src/NetContextClient/NetContextClient.csproj -- clear-ignore-patterns
- View State File Location:
dotnet run --project src/NetContextClient/NetContextClient.csproj -- get-state-file-location
The following patterns are ignored by default to protect sensitive information:
*.env
- Environment filesappsettings.*.json
- Application settings*.pfx
- Certificate files*.key
- Key files*.pem
- PEM files*password*
- Files containing "password" in the name*secret*
- Files containing "secret" in the name
- Path Safety: Files can only be accessed within the specified base directory
- Pattern Validation: Ignore patterns are validated for proper syntax
- Size Limits: Large file contents are truncated to prevent memory issues
- Sensitive File Protection: Built-in patterns protect common sensitive files
- Set the base directory for your project:
dotnet run --project src/NetContextClient/NetContextClient.csproj -- set-base-dir --directory "D:\Projects\MyApp"
- Check server version and configuration:
dotnet run --project src/NetContextClient/NetContextClient.csproj -- version
- Set up custom ignore patterns:
dotnet run --project src/NetContextClient/NetContextClient.csproj -- add-ignore-patterns --patterns "*.generated.cs" "*.designer.cs"
- List all projects:
dotnet run --project src/NetContextClient/NetContextClient.csproj -- list-projects-in-dir --directory "D:\Projects\MyApp\src"
- Analyze your project's package dependencies:
dotnet run --project src/NetContextClient/NetContextClient.csproj -- analyze-packages
- Search for authentication-related code:
dotnet run --project src/NetContextClient/NetContextClient.csproj -- semantic-search --query "user authentication and authorization logic"
NetContextServer implements the Model Context Protocol (MCP), allowing seamless integration with AI coding assistants that support this protocol, such as:
- VS Code: Provides your AI assistant with full context of your codebase for more accurate code generation and assistance
- Other MCP-compatible tools: Any tool that implements the Model Context Protocol can connect to NetContextServer
To use with VS Code:
- Configure VS Code to use the NetContextServer as its MCP provider
- Enjoy enhanced code assistance with full codebase context
For testing and debugging MCP interactions, you can use the Model Context Protocol Inspector, a visual testing tool that helps you inspect and validate communications between MCP clients and servers. Visit the inspector documentation to learn more about its features and capabilities.
The NetContextServer enables AI collaborators to request specific information about your codebase, making the AI's suggestions more relevant and accurate to your specific project structure and coding patterns.
The server provides clear error messages for common scenarios:
- Directory not found
- Access denied (outside base directory)
- Invalid patterns
- File size limits exceeded
- Restricted file types
- Missing environment variables for semantic search
- Fork the repository
- Create a feature branch
- Commit your changes
- Push to the branch
- Create a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.