.Net Code Context MCP server

Enables AI assistants to explore and understand .NET codebases.
Back to servers
Setup instructions
Provider
Brandon Williams
Release date
Mar 30, 2025
Language
C#
Stats
16 stars

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.

Installation

Prerequisites

  • .NET SDK installed on your system
  • Git (for cloning the repository)
  • Azure OpenAI credentials (optional, for semantic search functionality)

Step-by-Step Installation

  1. Clone the repository and build the project:
git clone https://github.com/willibrandon/NetContextServer.git
cd NetContextServer
dotnet build
  1. Set up environment variables for semantic search (optional):
# 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

Basic Usage

Setting Up Your Project

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

Core Commands

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 Functionality

Text Search

Search for exact text matches in your code:

dotnet run --project src/NetContextClient/NetContextClient.csproj -- search-code --text "authentication"

Semantic Search

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

Package Analysis

Analyze your project's NuGet packages:

dotnet run --project src/NetContextClient/NetContextClient.csproj -- analyze-packages

This command provides insights about your dependencies, including:

  • Package versions
  • Update recommendations
  • Dependency trees
  • Usage locations

Test Coverage Analysis

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"

Managing Ignore Patterns

Add Custom Ignore Patterns

Add patterns to ignore specific file types:

dotnet run --project src/NetContextClient/NetContextClient.csproj -- add-ignore-patterns --patterns "*.txt" "*.log"

View Current Patterns

See what patterns are currently being ignored:

dotnet run --project src/NetContextClient/NetContextClient.csproj -- get-ignore-patterns

Remove Specific Patterns

Remove patterns you no longer need:

dotnet run --project src/NetContextClient/NetContextClient.csproj -- remove-ignore-patterns --patterns "*.txt"

Clear All User Patterns

Reset to only the default ignore patterns:

dotnet run --project src/NetContextClient/NetContextClient.csproj -- clear-ignore-patterns

VS Code Integration

  1. Open VS Code
  2. Press Ctrl + Shift + P (or Cmd + Shift + P on macOS)
  3. Type "Configure MCP Server"
  4. Enter the following configuration:
{
  "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:

  • "List all .NET source files in this project directory"
  • "Search for authentication code"
  • "Analyze NuGet packages in all projects"
  • "Show me the contents of this file"
  • "Analyze test coverage for MyService.cs"

Example Workflow

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"

Security Features

NetContextServer includes several built-in security features:

  • Path Safety: Files can only be accessed within the specified base directory
  • Default Ignore Patterns: Protects sensitive files like .env, appsettings.*.json, certificate files, etc.
  • Size Limits: Large file contents are truncated to prevent memory issues
  • Pattern Validation: Ignores patterns with proper syntax validation

How to install this MCP server

For Claude Code

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.

For Cursor

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.

Adding an MCP server to Cursor globally

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"
            ]
        }
    }
}

Adding an MCP server to a project

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.

How to use the MCP server

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.

For Claude Desktop

To add this MCP server to Claude Desktop:

1. Find your configuration file:

  • macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
  • Windows: %APPDATA%\Claude\claude_desktop_config.json
  • Linux: ~/.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

Want to 10x your AI skills?

Get a free account and learn to code + market your apps using AI (with or without vibes!).

Nah, maybe later