Tharga.Mcp 2.1.1

dotnet add package Tharga.Mcp --version 2.1.1
                    
NuGet\Install-Package Tharga.Mcp -Version 2.1.1
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Tharga.Mcp" Version="2.1.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Tharga.Mcp" Version="2.1.1" />
                    
Directory.Packages.props
<PackageReference Include="Tharga.Mcp" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Tharga.Mcp --version 2.1.1
                    
#r "nuget: Tharga.Mcp, 2.1.1"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Tharga.Mcp@2.1.1
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Tharga.Mcp&version=2.1.1
                    
Install as a Cake Addin
#tool nuget:?package=Tharga.Mcp&version=2.1.1
                    
Install as a Cake Tool

Tharga.Mcp

Foundation package for MCP (Model Context Protocol) infrastructure in the Tharga ecosystem. Wraps the official ModelContextProtocol C# SDK with a Tharga-flavored registration pattern so downstream provider packages (Tharga.Team.Mcp, Tharga.MongoDB.Mcp, etc.) compose cleanly inside a single AddThargaMcp(...) callback.

Tharga.Mcp itself has no dependency on any other Tharga package — the auth/scope/audit integration lives in Tharga.Team.Mcp.

Docs: mcp.tharga.net — guides, API reference, and the provider/scope/auth walkthroughs.

Supported frameworks

Targets net10.0 and net11.0. Projects on .NET 10 are unaffected; the package brings no .NET 11 dependencies to them.

Install

dotnet add package Tharga.Mcp

Minimal usage

using Tharga.Mcp;

var builder = WebApplication.CreateBuilder(args);

builder.Services.AddThargaMcp(mcp =>
{
    mcp.Services.AddMcpServer().WithTools<HelloTools>();
});

var app = builder.Build();
app.UseThargaMcp();
app.Run();

UseThargaMcp() exposes the MCP endpoint at ThargaMcpOptions.EndpointBasePath (default /mcp). It also honors ThargaMcpOptions.RequireAuth (default true) — when set, the endpoint requires an authenticated caller, and the consumer must wire UseAuthorization() + an authentication scheme in the pipeline. Set mcp.Options.RequireAuth = false during registration to expose the endpoint anonymously.

ThargaMcpOptions.AuthenticationSchemes names the schemes that requirement authenticates against. Left empty it uses the application's default scheme — which in a host with interactive sign-in is OIDC, so an agent presenting an API key gets redirected to a login page instead of being let in. Name the scheme to accept it:

builder.Services.AddThargaMcp(mcp =>
{
    mcp.Options.AuthenticationSchemes.Add(ApiKeyConstants.SchemeName);
});

Bridge packages add the schemes their own callers use, so a host registering one usually needs nothing here. See Authorization.

An [Obsolete] MapMcp() alias still works for one release cycle but will be removed — update when you can.

Session mode

The transport is stateless by default, as protocol revision 2026-07-28 requires — no Mcp-Session-Id is issued, and the endpoint needs no session affinity. A client that negotiated a session against an earlier revision is refused with The Mcp-Session-Id header is not supported in stateless mode.

ThargaMcpOptions.SessionMode serves those clients:

builder.Services.AddThargaMcp(mcp =>
{
    mcp.Options.SessionMode = McpSessionMode.StatefulForInitializeClients;
});
Mode Legacy clients 2026-07-28+ clients Needs session affinity
Stateless (default) Rejected Served No
Stateful Full session Forced to downgrade Yes
StatefulForInitializeClients Full session Served statelessly Yes

Prefer StatefulForInitializeClients over Stateful when both kinds of client share the endpoint — Stateful refuses every modern client with -32022 UnsupportedProtocolVersion to accommodate the legacy ones. See Session mode.

Defining tools

Any class tagged with [McpServerToolType] exposing [McpServerTool] methods is recognised by the SDK:

[McpServerToolType]
public sealed class HelloTools
{
    [McpServerTool, Description("Returns a greeting for the given name.")]
    public string Greet([Description("The name to greet.")] string name)
        => $"Hello, {name}!";
}

Provider contracts

Tharga.Mcp also defines IMcpResourceProvider and IMcpToolProvider with per-scope registration (User, Team, System). This is the path for packages that need dynamic tools/resources — where the set of tools is known only at runtime (e.g. one MCP resource per MongoDB collection).

public sealed class TimeToolProvider : IMcpToolProvider
{
    public McpScope Scope => McpScope.System;

    public Task<IReadOnlyList<McpToolDescriptor>> ListToolsAsync(IMcpContext context, CancellationToken ct)
        => Task.FromResult<IReadOnlyList<McpToolDescriptor>>(
            [new McpToolDescriptor { Name = "time_now", Description = "Current UTC time." }]);

    public Task<McpToolResult> CallToolAsync(string name, JsonElement args, IMcpContext context, CancellationToken ct)
        => Task.FromResult(new McpToolResult
        {
            Content = [new McpContent { Text = DateTimeOffset.UtcNow.ToString("O") }],
        });
}

builder.Services.AddThargaMcp(mcp =>
{
    mcp.AddToolProvider<TimeToolProvider>();
});

Provider packages expose an extension method on IThargaMcpBuilder so consumers can compose them inside the same callback:

builder.Services.AddThargaMcp(mcp =>
{
    mcp.AddMongoDB();   // from Tharga.MongoDB.Mcp
    mcp.AddTeam();      // from Tharga.Team.Mcp
    mcp.AddToolProvider<MyCustomProvider>();
});

The two paths (attribute-based [McpServerTool] and contract-based IMcpToolProvider) work side by side — use attributes for statically-declared tools, providers for dynamic or programmatically-generated tools. Scope filtering activates once something populates IMcpContextAccessor.Current from the authenticated request — Tharga.Team.Mcp does, or you can register your own accessor.

Endpoint scopes

The master plan defines three scopes — User (/mcp/me), Team (/mcp/team), System (/mcp/system). Phase 0 ships a single endpoint (/mcp) that exposes registered tools and resources filtered by a scope hierarchy: a caller at System sees User + Team + System providers; Team sees User + Team; User sees only User. The caller's effective scope is read from IMcpContextAccessor.Current, which Tharga.Team.Mcp derives from the authenticated principal. When no context is populated, every provider is visible — so until a bridge or your own IMcpContextAccessor is registered, a provider's declared scope hides it from nobody. The three-endpoint split is deferred — see the master plan decision 2026-04-18.

Sample

Runnable end-to-end sample lives under Sample/Tharga.Mcp.Sample/. Start it and connect with @modelcontextprotocol/inspector:

cd Sample/Tharga.Mcp.Sample
dotnet run
# in another terminal:
npx @modelcontextprotocol/inspector http://localhost:5138/mcp

License

MIT. See LICENSE.

Product Compatible and additional computed target framework versions.
.NET 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.  net11.0 is compatible. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (6)

Showing the top 5 NuGet packages that depend on Tharga.Mcp:

Package Downloads
Tharga.Team.Mcp

Team bridge for Tharga.Mcp. Provides Team-backed IMcpContext, scope enforcement, audit logging, and authentication for MCP tool and resource invocations.

Quilt4Net.Toolkit.Mcp

MCP (Model Context Protocol) provider for Quilt4Net.Toolkit. Exposes Application Insights query operations as MCP tools and resources, plugging into the Tharga.Mcp ecosystem so AI agents can look up incidents and correlate logs.

Tharga.MongoDB.Mcp

Exposes Tharga.MongoDB monitoring data (collections, calls, clients) and actions (touch, rebuild index) via MCP (Model Context Protocol). Plugs into Tharga.Mcp.

Tharga.Platform.Mcp

Platform bridge for Tharga.Mcp. Provides Platform-backed IMcpContext, scope enforcement, audit logging, and authentication for MCP tool and resource invocations.

Tharga.Cache.Mcp

Exposes Tharga.Cache monitoring data (cache types, items, persistence health, fetch queue) and actions (clear all, clear stale) via MCP (Model Context Protocol). Plugs into Tharga.Mcp.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
2.1.1 610 11/14/2026
2.0.4 833 10/25/2026
2.0.3 161 10/25/2026
2.0.2 784 9/28/2026
2.0.1 1,221 8/24/2026
2.0.0 455 8/17/2026
1.1.0 223 8/14/2026
1.0.1 517 7/31/2026
1.0.0 606 7/26/2026
0.1.7 177 7/25/2026
0.1.6 1,319 6/7/2026
0.1.5 143 6/6/2026
0.1.4 935 5/14/2026
0.1.3 861 4/28/2026
0.1.2 163 4/20/2026
0.1.1 191 4/19/2026
0.1.0 166 4/18/2026