![]() |
VOOZH | about |
dotnet add package Tharga.Mcp --version 0.1.6
NuGet\Install-Package Tharga.Mcp -Version 0.1.6
<PackageReference Include="Tharga.Mcp" Version="0.1.6" />
<PackageVersion Include="Tharga.Mcp" Version="0.1.6" />Directory.Packages.props
<PackageReference Include="Tharga.Mcp" />Project file
paket add Tharga.Mcp --version 0.1.6
#r "nuget: Tharga.Mcp, 0.1.6"
#:package Tharga.Mcp@0.1.6
#addin nuget:?package=Tharga.Mcp&version=0.1.6Install as a Cake Addin
#tool nuget:?package=Tharga.Mcp&version=0.1.6Install as a Cake Tool
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.MongoDB.Mcp, Tharga.Platform.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.Platform.Mcp (Phase 1).
Docs: mcp.tharga.net — guides, API reference, and the provider/scope/auth walkthroughs.
dotnet add package Tharga.Mcp
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 calls .RequireAuthorization() and requires the consumer to wire UseAuthorization() + an authentication scheme in the pipeline. Set mcp.Options.RequireAuth = false during registration to expose the endpoint anonymously.
An [Obsolete] MapMcp() alias still works for one release cycle but will be removed — update when you can.
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}!";
}
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.AddPlatform(); // from Tharga.Platform.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 (/mcp/me, /mcp/team, /mcp/system) activates in Phase 1 once Tharga.Platform.Mcp populates IMcpContextAccessor.Current from the authenticated request.
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 (populated by Tharga.Platform.Mcp from the authenticated principal, or left anonymous in Phase 0). When no context is populated, every provider is visible. The three-endpoint split is deferred — see the master plan decision 2026-04-18.
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
MIT. See .
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 net8.0 is compatible. net8.0-android net8.0-android was computed. net8.0-browser net8.0-browser was computed. net8.0-ios net8.0-ios was computed. net8.0-maccatalyst net8.0-maccatalyst was computed. net8.0-macos net8.0-macos was computed. net8.0-tvos net8.0-tvos was computed. net8.0-windows net8.0-windows was computed. net9.0 net9.0 is compatible. net9.0-android net9.0-android was computed. net9.0-browser net9.0-browser was computed. net9.0-ios net9.0-ios was computed. net9.0-maccatalyst net9.0-maccatalyst was computed. net9.0-macos net9.0-macos was computed. net9.0-tvos net9.0-tvos was computed. net9.0-windows net9.0-windows was computed. net10.0 net10.0 is compatible. net10.0-android net10.0-android was computed. net10.0-browser net10.0-browser was computed. net10.0-ios net10.0-ios was computed. net10.0-maccatalyst net10.0-maccatalyst was computed. net10.0-macos net10.0-macos was computed. net10.0-tvos net10.0-tvos was computed. net10.0-windows net10.0-windows was computed. |
Showing the top 5 NuGet packages that depend on Tharga.Mcp:
| Package | Downloads |
|---|---|
|
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.Platform.Mcp
Platform bridge for Tharga.Mcp. Provides Platform-backed IMcpContext, scope enforcement, audit logging, and authentication for MCP tool and resource invocations. |
|
|
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.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. |
|
|
Tharga.Communication.Mcp
Exposes Tharga.Communication runtime data (connected clients, active subscriptions, registered handlers) via MCP (Model Context Protocol). Plugs into Tharga.Mcp. |
This package is not used by any popular GitHub repositories.