Give an AI agent access to your product without giving it everything
Customers will ask to connect an AI assistant to your product. The safe version is a connection the person approves, limited to what they could do themselves, and useless against any other server.
7 min read · Last checked
In short
Key points
- MCP clients authorize with OAuth. The assistant discovers where to sign in from a 401 response and your resource metadata.
- The token should be issued for your server only, and your server must reject any other audience.
- Scopes are what the person approves, so write each description for a human reader.
- Authorization tells you who and what was approved. Filtering data to that person’s customer is still your code.
How the connection works
These are the OAuth 2.0 protected resource metadata (RFC 9728) and authorization server metadata (RFC 8414) standards. You can implement your side with any language and a JWT library; TenancyEngine is the authorization server.
- The assistant calls your MCP server with no token and receives 401 with a WWW-Authenticate header that points at your protected resource metadata.
- It reads that metadata, which names the authorization server, then reads the authorization server’s own metadata.
- It sends the person through sign-in using PKCE with the S256 method. TenancyEngine does not offer open client registration.
- The token that comes back is issued for your server, and your server checks that before serving the call.
Register your server and write the scopes
Your server’s identifier is the API base URL of the environment you register it in, an https URL with no fragment. Add the scopes your server understands under the application’s resource scopes, each with a short name and a plain-language description. That description is what the person reads when they approve access, so "Read your projects" is better than "projects.read".
Keep scopes narrow and separate reads from writes. An assistant that only needs to summarise a project should not hold a scope that can delete one.
Verify the token (ASP.NET, unreleased SDK helper)
The SDK source includes a helper that builds the resource metadata, the 401 challenge and an exact-audience JWT bearer scheme. It is documented but is not in the published 2.3.0 package yet, so treat the sample as the shape of the API and check the changelog before you rely on it.
builder.Services.AddAuthentication()
.AddTenancyEngineMcpResource(
resource: "https://api.example.com/mcp",
issuer: "https://auth.saasruntime.com/",
resourceMetadataUrl: "https://api.example.com/.well-known/oauth-protected-resource");
app.MapPost("/mcp", handler).RequireAuthorization(
new AuthorizeAttribute { AuthenticationSchemes = "TenancyEngineMcp" });What your server must still do
- Check the scope on every tool, not once at connection time.
- Resolve the person’s customer from the token and filter every query by it. A valid token proves who they are, not which rows they may read.
- Apply the same permissions the person has in your app. The assistant acts for them and should never be able to do more.
- Log tool calls with the person and the customer, so a customer can see what an assistant did.
A key for one application, for your own tooling
Separately from the OAuth path above, TenancyEngine lets you create a key with the mcp.connect scope that lets an MCP client reach one application’s data through the MCP gateway. Use it for your own assistants and automation. It reaches one application and carries only the scopes you grant. MCP calls are an allowance on Growth and above and are not part of Starter.
Honest limits
What to know before you rely on this
- The MCP resource helper is in the SDK source but unreleased on NuGet; the published SDK is 2.3.0.
- TypeScript and other language SDKs are not published, so verify tokens with a standard JWT library in those languages.
- MCP access and AI allowances start on Growth.
Questions people ask
Does the assistant ever see a long-lived API key?
In the OAuth path it receives a token issued for your server after the person approves. Do not hand an organization API key to an assistant that acts for customers.
Why is audience checking emphasised?
A token issued for another server, including a sibling path on your host, must not work on yours. The helper rejects any audience that is not exactly your resource.
Sources
Keep reading
Try it on the free plan
One app and five customers, no credit card required.