NetContextServer is a powerful tool that enables AI coding assistants to understand your .NET codebase through the Model Context Protocol (MCP). It provides semantic code search, intelligent navigation, and built-in security features to enhance your coding experience when working with AI tools like VS Code.
git clone https://github.com/willibrandon/NetContextServer.git
cd NetContextServer
dotnet build
# For Windows
set AZURE_OPENAI_ENDPOINT=your_endpoint
set AZURE_OPENAI_API_KEY=your_key
# For Linux/macOS
export AZURE_OPENAI_ENDPOINT=your_endpoint
export AZURE_OPENAI_API_KEY=your_key
First, set the base directory for your project:
dotnet run --project src/NetContextClient/NetContextClient.csproj -- set-base-dir --directory "path/to/your/project"
Verify the base directory is set correctly:
dotnet run --project src/NetContextClient/NetContextClient.csproj -- get-base-dir
List all projects in a specific directory:
dotnet run --project src/NetContextClient/NetContextClient.csproj -- list-projects-in-dir --directory "path/to/your/project/src"
List source files in a project directory:
dotnet run --project src/NetContextClient/NetContextClient.csproj -- list-source-files --project-dir "path/to/your/project/src/YourProject"
Check the server version:
dotnet run --project src/NetContextClient/NetContextClient.csproj -- version
Search for exact text matches in your code:
dotnet run --project src/NetContextClient/NetContextClient.csproj -- search-code --text "authentication"
Search for code based on meaning rather than exact text:
# Default number of results (5)
dotnet run --project src/NetContextClient/NetContextClient.csproj -- semantic-search --query "handle user authentication"
# Custom number of results
dotnet run --project src/NetContextClient/NetContextClient.csproj -- semantic-search --query "database connection string" --top 10
Analyze your project's NuGet packages:
dotnet run --project src/NetContextClient/NetContextClient.csproj -- analyze-packages
This command provides insights about your dependencies, including:
Analyze test coverage from various report formats:
# Analyze coverage from Coverlet JSON
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"
Add patterns to ignore specific file types:
dotnet run --project src/NetContextClient/NetContextClient.csproj -- add-ignore-patterns --patterns "*.txt" "*.log"
See what patterns are currently being ignored:
dotnet run --project src/NetContextClient/NetContextClient.csproj -- get-ignore-patterns
Remove patterns you no longer need:
dotnet run --project src/NetContextClient/NetContextClient.csproj -- remove-ignore-patterns --patterns "*.txt"
Reset to only the default ignore patterns:
dotnet run --project src/NetContextClient/NetContextClient.csproj -- clear-ignore-patterns
Ctrl + Shift + P
(or Cmd + Shift + P
on macOS){
"command": "dotnet",
"args": ["run", "--project", "path/to/NetContextServer/src/NetContextServer/NetContextServer.csproj"]
}
Once configured, your VS Code AI assistant will have deep understanding of your codebase. You can ask questions like:
Here's a complete example workflow:
# 1. Set the base directory
dotnet run --project src/NetContextClient/NetContextClient.csproj -- set-base-dir --directory "D:/Projects/MyApp"
# 2. Set up custom ignore patterns
dotnet run --project src/NetContextClient/NetContextClient.csproj -- add-ignore-patterns --patterns "*.generated.cs" "*.designer.cs"
# 3. List all projects
dotnet run --project src/NetContextClient/NetContextClient.csproj -- list-projects-in-dir --directory "D:/Projects/MyApp/src"
# 4. Analyze package dependencies
dotnet run --project src/NetContextClient/NetContextClient.csproj -- analyze-packages
# 5. Search for authentication code
dotnet run --project src/NetContextClient/NetContextClient.csproj -- semantic-search --query "user authentication and authorization logic"
NetContextServer includes several built-in security features:
.env
, appsettings.*.json
, certificate files, etc.To add this MCP server to Claude Code, run this command in your terminal:
claude mcp add-json "netcontextserver" '{"command":"dotnet","args":["run","--project","path/to/NetContextServer/src/NetContextServer/NetContextServer.csproj"]}'
See the official Claude Code MCP documentation for more details.
There are two ways to add an MCP server to Cursor. The most common way is to add the server globally in the ~/.cursor/mcp.json
file so that it is available in all of your projects.
If you only need the server in a single project, you can add it to the project instead by creating or adding it to the .cursor/mcp.json
file.
To add a global MCP server go to Cursor Settings > Tools & Integrations and click "New MCP Server".
When you click that button the ~/.cursor/mcp.json
file will be opened and you can add your server like this:
{
"mcpServers": {
"netcontextserver": {
"command": "dotnet",
"args": [
"run",
"--project",
"path/to/NetContextServer/src/NetContextServer/NetContextServer.csproj"
]
}
}
}
To add an MCP server to a project you can create a new .cursor/mcp.json
file or add it to the existing one. This will look exactly the same as the global MCP server example above.
Once the server is installed, you might need to head back to Settings > MCP and click the refresh button.
The Cursor agent will then be able to see the available tools the added MCP server has available and will call them when it needs to.
You can also explicitly ask the agent to use the tool by mentioning the tool name and describing what the function does.
To add this MCP server to Claude Desktop:
1. Find your configuration file:
~/Library/Application Support/Claude/claude_desktop_config.json
%APPDATA%\Claude\claude_desktop_config.json
~/.config/Claude/claude_desktop_config.json
2. Add this to your configuration file:
{
"mcpServers": {
"netcontextserver": {
"command": "dotnet",
"args": [
"run",
"--project",
"path/to/NetContextServer/src/NetContextServer/NetContextServer.csproj"
]
}
}
}
3. Restart Claude Desktop for the changes to take effect