DotnetCodingContextMCP 0.4.2

dotnet tool install --global DotnetCodingContextMCP --version 0.4.2
                    
This package contains a .NET tool you can call from the shell/command line.
dotnet new tool-manifest
                    
if you are setting up this repo
dotnet tool install --local DotnetCodingContextMCP --version 0.4.2
                    
This package contains a .NET tool you can call from the shell/command line.
#tool dotnet:?package=DotnetCodingContextMCP&version=0.4.2
                    
nuke :add-package DotnetCodingContextMCP --version 0.4.2
                    

DotnetCodingContextMCP

An MCP server that gives AI agents the coding context they need to write compilable C# code — type signatures, constructors, mock patterns, and test conventions in a single call.

The Problem

When AI agents write C# code, they hallucinate type names, property names, constructor signatures, and assertion patterns:

What the agent writes What actually exists
new UserRepository() new UserRepository(IDbContext context)
user.EmailAddress = "..." user.Email (different property name)
record.Name = "x" positional record — requires constructor
result.Should().BeTrue() result.ShouldBeTrue() (wrong assertion library)

This causes build-fail-fix-build spirals that waste time and tokens.

The Solution: 4 Tools

analyze_solution_for_testing (new in v0.2.0)

Discover what's testable in a solution — call this FIRST.

Input:  { "path": "/src/MyApp.sln" }

Output:
{
  "sourceProjects": ["MyApp.Core", "MyApp.API"],
  "testProjects": ["MyApp.Tests"],
  "projects": [
    {
      "projectName": "MyApp.Core",
      "totalPublicTypes": 42,
      "testableTypes": [
        {
          "name": "UserService",
          "kind": "class",
          "publicMethodCount": 8,
          "constructorDependencies": ["IUserRepository", "ILogger<UserService>"],
          "complexity": 12,
          "instantiationHint": "new UserService(Mock.Of<IUserRepository>(), Mock.Of<ILogger<UserService>>())"
        }
      ]
    }
  ],
  "recommendedTestSetup": "Most-used dependencies to mock: IUserRepository, ILogger. Create mock instances first."
}

get_coding_context

One call → everything needed to write code against specific types.

Input:  { "typeNames": "UserService, OrderRepository",
          "path": "/src/MyApp.sln" }

Output:
{
  "types": [
    {
      "name": "UserService",
      "using": "using MyApp.Services;",
      "kind": "class",
      "constructors": ["new UserService(IUserRepository repo, ILogger<UserService> logger)"],
      "properties": [
        { "name": "IsInitialized", "type": "bool", "settable": false }
      ],
      "instantiation": "new UserService(Mock.Of<IUserRepository>(), Mock.Of<ILogger<UserService>>())"
    }
  ],
  "relatedTypes": [...]
}

get_interface_contract

Mock-ready interface extraction with Moq setup patterns.

Input:  { "interfaceName": "IUserRepository", "path": "/src/MyApp.sln" }

Output:
{
  "members": [
    {
      "name": "GetByIdAsync",
      "signature": "Task<User?> GetByIdAsync(int id)",
      "mockSetup": "mock.Setup(x => x.GetByIdAsync(It.IsAny<int>())).ReturnsAsync(default(User?)!)"
    }
  ],
  "implementations": ["SqlUserRepository", "InMemoryUserRepository"],
  "parameterTypes": [{ "name": "User", "kind": "class", "instantiation": "..." }]
}

get_project_test_context

Analyze existing tests to extract conventions.

Input:  { "testProjectPath": "/test/MyApp.Tests/MyApp.Tests.csproj" }

Output:
{
  "framework": "xunit",
  "assertionLibrary": "Shouldly",
  "mockingLibrary": "Moq",
  "assertionPatterns": {
    "equality": "result.ShouldBe(expected)",
    "true": "result.ShouldBeTrue()",
    "null": "result.ShouldBeNull()"
  },
  "namingConvention": "MethodName_Scenario_ExpectedBehavior",
  "helperMethods": [
    { "name": "CreateTestUser", "signature": "User CreateTestUser(string name)" }
  ]
}

Quick Start

Install

dotnet tool install --global DotnetCodingContextMCP

VS Code / GitHub Copilot

Add to mcp.json:

{
  "servers": {
    "coding-context": {
      "type": "stdio",
      "command": "coding-context-mcp"
    }
  }
}

Pair with DotnetTemplateMCP

For complete .NET AI tooling — templates for project creation, coding context for code authoring:

{
  "servers": {
    "dotnet-templates": {
      "type": "stdio",
      "command": "template-engine-mcp"
    },
    "coding-context": {
      "type": "stdio",
      "command": "coding-context-mcp"
    }
  }
}

Why Not SharpLensMcp / Other Roslyn MCPs?

Existing Roslyn MCP servers expose many granular tools designed for code exploration (navigate, inspect, analyze). This MCP exposes 4 compound tools designed for code authoring — giving agents exactly what they need to write compilable code:

Granular Roslyn MCPs This MCP (4 tools)
Tool calls per coding task ~25-50 3-5
Tool selection complexity High — dozens of choices Low — 3 obvious choices
Output format Raw Roslyn data Ready-to-paste code snippets
Mock setup generation ✅ Moq patterns included
Instantiation examples ✅ with actual constructor args
Test convention detection ✅ framework, assertions, helpers

Requirements

  • .NET 8 SDK or later (supports .NET 8 LTS and .NET 10)
  • MSBuild (included with .NET SDK)

License

MIT

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

This package has no dependencies.

Version Downloads Last Updated
0.4.2 122 3/9/2026
0.4.1 78 3/6/2026
0.4.0 79 3/6/2026
0.3.3 202 3/5/2026
0.3.2 197 3/5/2026
0.2.0 179 3/4/2026
0.1.0 144 3/4/2026