Tharga.Team.Mcp
4.9.0
dotnet add package Tharga.Team.Mcp --version 4.9.0
NuGet\Install-Package Tharga.Team.Mcp -Version 4.9.0
<PackageReference Include="Tharga.Team.Mcp" Version="4.9.0" />
<PackageVersion Include="Tharga.Team.Mcp" Version="4.9.0" />
<PackageReference Include="Tharga.Team.Mcp" />
paket add Tharga.Team.Mcp --version 4.9.0
#r "nuget: Tharga.Team.Mcp, 4.9.0"
#:package Tharga.Team.Mcp@4.9.0
#addin nuget:?package=Tharga.Team.Mcp&version=4.9.0
#tool nuget:?package=Tharga.Team.Mcp&version=4.9.0
Tharga Team Mcp
Team bridge for Tharga.Mcp. Connects MCP tool and resource invocations to Tharga.Team's authentication, scope enforcement, and audit logging.
Renamed from
Tharga.Platform.Mcp. NuGet package IDs cannot be renamed, so this is a new ID and the old one is deprecated. Migrating is a deliberate step with two breaking changes:mcp.AddPlatform()is nowmcp.AddTeam(), and every resource URI moved fromplatform://toteam://— update any MCP client that references them by string.
What it does
- Populates
IMcpContextfrom the authenticatedHttpContext.User(works with both OIDC and API Key authentication) - Enforces provider scope class:
McpScope.SystemrequiresRoles.Developer,McpScope.Teamrequires team membership - Emits audit log entries for every MCP tool invocation — success and failure
- Registers built-in
mcp:*scopes in both of Team's scope registries — see below - Requires authentication on the MCP endpoint — anonymous requests are rejected
Quick start
builder.Services.AddThargaMcp(mcp =>
{
mcp.AddTeam(); // bridge to Team auth/scopes/audit
// ... other provider packages (e.g. mcp.AddMongoDB())
});
app.UseThargaMcp();
Granting mcp:discover
AddTeam() registers the built-in mcp:* scopes in both the team and the system registry,
because both routes to holding one are legitimate. mcp:discover can therefore be granted three ways:
| Route | How | Where it authorizes |
|---|---|---|
| Access level | Registered at AccessLevel.Viewer, so any member at Viewer or above holds it |
Inside the caller's selected team |
| App role | o.ConfigureSystemRoles = r => r.Map("Developer", McpScopes.Discover); |
System-wide, no team needed |
| System API key | Grant it when minting the key | System-wide, no team needed |
IMcpScopeChecker accepts either provenance. A system grant authorizes with no team selected; a
team grant authorizes only alongside a TeamKey claim — a scope claim without a team context is not
a grant, and is refused.
public sealed class MyTool(IMcpScopeChecker scopeChecker)
{
public Task<string> ListAsync()
{
scopeChecker.Require(McpScopes.Discover); // throws UnauthorizedAccessException if not held
...
}
}
IMcpScopeChecker is an opt-in helper for tools that want to enforce a scope imperatively; nothing in
this package or Tharga.MongoDB.Mcp calls it for you.
Behaviour change.
mcp:discoverwas previously registered as a team scope but checked only against system claims, so an access-level grant could never satisfy it and a tool callingRequire(McpScopes.Discover)rejected every caller — including a team Owner. If you wrote a test asserting that rejection, it now passes the caller instead.
Authentication
mcp.AddTeam() contributes the API-key scheme to the MCP endpoint, so the default
ThargaMcpOptions.RequireAuth = true accepts an API key with no further configuration:
builder.Services.AddThargaMcp(mcp => mcp.AddTeam());
app.UseThargaMcp();
That matters because MCP callers are agents — there is normally no user, so an API key is the expected
credential. Before Tharga.Mcp 1.0.1, RequireAuth emitted a policy naming no scheme, which
authenticated against the application's default scheme; in a Blazor host that is OIDC, so a valid key
was answered with a 302 to a login page (Tharga/Mcp#18).
Add your own scheme alongside if you also want a signed-in user to reach the endpoint:
mcp.Options.AuthenticationSchemes.Add(CookieAuthenticationDefaults.AuthenticationScheme);
User and team resources
Always-on resource providers that surface the authenticated caller's own data. Both providers self-gate on the principal's claims, so anonymous and system-only callers see no resources.
User scope (McpScope.User)
| URI | Contents |
|---|---|
team://me |
The caller's IUser (key, identity, name, email) and a memberships array — for each team the caller is in, its teamKey, teamName, plus the caller's accessLevel and membership state. |
Listed when the principal carries a NameIdentifier (or equivalent) claim. Read fails with UnauthorizedAccessException if IUserService.GetCurrentUserAsync returns null.
Team scope (McpScope.Team)
| URI | Contents |
|---|---|
team://team |
Metadata for the team the call addresses — the one named in X-Team-Key, else the TeamKey claim: key, name, icon, consentedRoles. |
team://team/members |
Members of that team: key, name, accessLevel, state, tenantRoles, scopeOverrides, and an invited flag. |
team://team/apikeys |
API keys for that team, with the rules of IApiKeyManagementService.GetKeysAsync: it needs apikey:manage on the team, lists the team's shared keys plus the caller's own private ones, and every private key only for an apikeys:oversee holder. Raw key values are redacted (the apiKey property is omitted entirely). Listed only to a caller who holds apikey:manage, and only when IApiKeyManagementService is registered; a caller without the scope is refused on read. |
Listed when the principal carries a TeamKey claim or names a team on the call (below). Read fails with UnauthorizedAccessException if neither applies.
Naming a team on the call
Send the team key in an X-Team-Key header:
POST /mcp
Authorization: Bearer <api key>
X-Team-Key: acme-corp
Everything on this surface used to derive from the caller's TeamKey claim, so a call could only address
the team the caller was already anchored to — and a system key is anchored to none, so it could
address no team at all. That also made team consent unreachable here: there was no team whose consented
level could be resolved. The Blazor surface has done this since 3.2.0; this is parity, not new semantics.
Per call, not per session. ModelContextProtocol 2.0.0 is stateless by default, so there is no
session to hold a selection in — and over HTTP, per-request is per-call. The header is read once, in
HttpContextMcpContextAccessor; providers keep reading context.TeamId and need no change.
What naming a team grants
A person and a key are answered differently, because they are different things.
| Caller | Gets |
|---|---|
| A person, member of the named team | Their membership scopes in it |
| A person, not a member but holding a role the team consented to | The team's consented level |
| A system API key, naming a team that has consented | The team's consented level |
| A team API key, naming any team but its own | Refused — a contradiction, not a preference |
| Neither, or the team does not exist | Refused |
| A suspended member | Refused — suspension means no access, by any door |
A person is matched against the team's consented roles; a key holds no roles at all, so for a key the question is simply whether the team consented, and the consented level is the grant.
A team enabling consent so its support staff can help thereby admits system keys at that same level. Consent is one statement about who may enter, and it does not distinguish people from machines.
A team API key needs no header. Its team cannot be anything other than its own, so there is nothing to name — and naming a different one is refused rather than ignored.
Selection replaces, it never accumulates. Scopes are recomputed for the named team; the principal's own scope claims describe a different team and are never consulted, so naming a team can only narrow what a caller may do. System scopes are unaffected, being team-independent.
The same code answers this on REST. TeamContextResolver is shared, and the header name is
configured once on TeamContextOptions.TeamKeyHeader — not separately here, because two places to
configure one name is one place for the surfaces to disagree.
Refused, not empty
Naming a team you cannot reach throws rather than returning an empty result. Everywhere else on this surface seeing nothing is the correct answer; here it would be a misleading one — the caller asked about a specific team, and an empty answer reads as "that team is empty" rather than "you cannot see it".
Change the header name with TeamContextOptions.TeamKeyHeader if it collides with something in your
stack — one setting, both surfaces.
Consent is configured in one place
The default level a team's consent grants lives on ConsentOptions in the Tharga.Team package, and
is registered once for every surface to read:
builder.AddThargaTeam(o => o.Blazor.Consent.AccessLevel = AccessLevel.User);
It is deliberately not an MCP option. Consent decides what a caller may do in a team they do not belong to, and a second copy here would let the same caller reach the same team at two different levels depending on which door they came through — which is exactly what happened before it was moved.
A resource is listed only if you could read it
resources/list shows a resource only when the caller could actually read it. Listing something they
cannot read advertises data they may not have; omitting something they can read hides a capability they
hold. Both were once true here at the same time — the audit read moved onto audit:read while the listing
one method above still asked for the Developer role.
Each entry therefore asks the same question its read asks, rather than one check standing in for all of
them. For audit that means asking IAuditOversightService, which is what the read is gated on: a
registered logger says the feature exists, not that this caller may use it.
Reading the caller in your own provider
IMcpContext carries only the scope. Your own IMcpToolProvider or IMcpResourceProvider reads the calling
team and user through AsTeamContext(), which is public from 3.24:
using Tharga.Team.Mcp;
var caller = context.AsTeamContext();
if (string.IsNullOrEmpty(caller?.TeamId)) return Refuse("Select a team first.");
await valuations.GetAsync(caller.TeamId, caller.UserId);
Null means no identity, so refuse. It is what you get when the context came from another bridge or none did. Never read it as "no team" or as an ordinary user.
Where each value comes from:
| Property | Source |
|---|---|
TeamId |
the team named on the call; failing that, the TeamClaimTypes.TeamKey claim |
UserId |
the ClaimTypes.NameIdentifier claim; failing that, sub |
IsDeveloper |
the principal is in the configured Developer role |
In a unit test, construct the context directly. TeamMcpContext has a public constructor:
var principal = new ClaimsPrincipal(new ClaimsIdentity(
[
new Claim(ClaimTypes.NameIdentifier, "user-1"),
new Claim(TeamClaimTypes.TeamKey, "team-1")
], "test"));
IMcpContext context = new TeamMcpContext(principal, McpScope.Team, developerRole: "Developer");
System-scope diagnostic resources (opt-in)
Expose read-only diagnostic data under team://system/* for callers with the Developer role. Non-developers see no resources and get UnauthorizedAccessException on read.
builder.Services.AddThargaMcp(mcp =>
{
mcp.AddTeam(o =>
{
o.ExposeSystemResources = true;
});
});
Available resources (listed only when the matching dependency is registered):
| URI | Contents |
|---|---|
team://system/apikeys |
System API keys (not bound to a team), with the rules of ISystemApiKeyManagementService.GetSystemKeysAsync: the Developer role and the apikey:system-manage scope are both needed, and the shared keys plus the caller's own personal ones are listed, everyone's only for an apikeys:oversee holder. Raw key values are redacted. |
team://system/roles |
Tenant roles registered via AddThargaTenantRoles |
team://system/audit |
Most recent ~100 audit entries from the last 7 days |
Per-team API-key listings now ship under team://team/apikeys (see "Team scope" above). Cross-tenant team listings remain deferred — they require a new ITeamService.GetAllTeamsAsync method.
Support AI connection tools (opt-in)
An agent can read and change what the support assistant answers its team with, over MCP, as the REST endpoints
MapThargaSupportAiConnection do. Off by default, as the endpoints are only mapped when you map them:
builder.Services.AddThargaSupportAiConnections(); // Tharga.Team.Support: the service the tools use
builder.Services.AddThargaMcp(mcp => mcp.AddTeam(o => o.ExposeSupportAiConnection = true));
| Tool | What it does |
|---|---|
support.ai.get_connection |
What the team's assistant answers with: the platform's model, a provider and model, or off. Says whether a key is stored, never returns it. |
support.ai.get_choices |
What the team may choose, where each provider starts from, and what the platform's model is. |
support.ai.list_models |
The models a provider offers for a key. Saves nothing. |
support.ai.test |
Asks the model one short question and returns its reply. Saves nothing. |
support.ai.connect |
Answers the team with a provider, after checking that it lists the chosen model for the key. The key is stored encrypted. |
support.ai.use_platform_model |
Answers the team with the platform's model, and forgets any stored key. |
support.ai.turn_off |
Turns the assistant off for the team, and forgets any stored key. |
list_models, test and connect take kind (one of the kinds get_choices lists), baseAddress, apiKey and
model. Leave apiKey out to use the key the team stored, allowed only while the kind and address are unchanged.
- Authorization is the service's. It requires
assistant:manageon the team and audits every change, a refusal too. The tools add no check of their own; a caller without the scope is told so in the result rather than getting a transport error. Nothing is offered to a caller with no team, or when the service is not registered. - The team is the caller's own, from the same claim REST reads. There is no team argument.
- The key never comes back. No result and no error carries it, and an error never quotes what was sent. It does travel through whatever conversation the agent keeps, which is the agent's to protect; for a team that cares, set the key from a form and let the agent only read, test and list.
- No new dependency. The service and its types are in
Tharga.Team, which this package already uses, soTharga.Team.Mcptakes nothing fromTharga.Team.Support.
Related packages
| Package | Description |
|---|---|
| Tharga.Mcp | MCP foundation (contracts, transport) |
| Tharga.Team.Service | Team scope/audit primitives |
| Product | Versions 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. |
-
net10.0
- Tharga.Mcp (>= 2.1.1)
- Tharga.Team.Service (>= 4.9.0)
-
net11.0
- Tharga.Mcp (>= 2.1.1)
- Tharga.Team.Service (>= 4.9.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 4.9.0 | 0 | 11/27/2026 |
| 4.8.8 | 85 | 11/23/2026 |
| 4.8.7 | 91 | 11/23/2026 |
| 4.8.6 | 99 | 11/23/2026 |
| 4.8.5 | 91 | 11/22/2026 |
| 4.8.4 | 94 | 11/22/2026 |
| 4.8.3 | 107 | 11/22/2026 |
| 4.8.2 | 104 | 11/21/2026 |
| 4.8.1 | 100 | 11/20/2026 |
| 4.8.0 | 112 | 11/20/2026 |
| 4.7.4 | 107 | 11/19/2026 |
| 4.7.3 | 95 | 11/18/2026 |
| 4.7.2 | 103 | 11/17/2026 |
| 4.7.1 | 128 | 11/15/2026 |
| 4.7.0 | 102 | 11/15/2026 |
| 4.6.9 | 107 | 11/14/2026 |
| 4.6.8 | 111 | 11/14/2026 |
| 4.6.7 | 113 | 11/13/2026 |
| 4.6.6 | 100 | 11/12/2026 |
| 4.6.5 | 112 | 11/12/2026 |