A .NET Codebase Context MCP Server that provides AI assistants with access to your .NET codebase through the Model Context Protocol (MCP). This allows AI tools to understand and work with your specific codebase context.
- 📁 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
- 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
- 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:
dotnet run --project src/NetContextClient/NetContextClient.csproj -- analyze-packages
- 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"
- 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"
- 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:
- Cursor AI: 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 Cursor AI:
- Configure Cursor AI to use the NetContextServer as its MCP provider
- Enjoy enhanced code assistance with full codebase context
The Model Context Protocol enables AI tools 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.
- Built with MCPSharp
- Uses Azure OpenAI for semantic embeddings
- Inspired by the Model Context Protocol