Authorization Regression Tests for MCP Servers: What to Run in CI

A security review looks at your MCP server on one day. Your server changes every week. The gap between those two facts is where most regressions live: a refactor drops an audience check, a new tool ships without a scope, an SDK upgrade changes how a WWW-Authenticate header is built. None of these are exotic. All of them pass a manual test and fail a review three months later.

This tutorial is about the automated authorization tests that belong in your CI pipeline. It is not the pre-handover adversarial test plan, which is a one-time exercise with a human attacker mindset. This is the regression suite that keeps those findings closed.

What this suite is, and is not

It is a set of fast, deterministic tests that run on every pull request against a real instance of your server and a test authorization server.

It is not a replacement for a penetration test, a threat model, or a review of your tool design. It checks that decisions you already made stay made. If you have not made them, write the decisions down first.

Set up a test authorization server you control

The tests need to mint tokens with chosen properties: wrong audience, expired, missing scope, signed by an unknown key. You cannot do that against your production identity provider.

Run a minimal authorization server in the test environment, or a token-minting helper with its own signing key, and configure your server to trust that issuer through the same code path it uses in production. Do not add a test-only bypass in the server. A bypass that exists in the test build is a bypass that someone will eventually ship.

Your helper needs to produce:

  • a valid token with a given sub, tenant claim, scopes, and aud;
  • the same token with each claim altered one at a time;
  • tokens with exp in the past and nbf in the future;
  • a token signed by a key that is not in the published JWKS.

Group 1: discovery

The MCP authorization specification builds on OAuth 2.0 Protected Resource Metadata (RFC 9728). Test the discovery contract directly.

  1. An unauthenticated request to the MCP endpoint returns 401 with a WWW-Authenticate: Bearer header that includes a resource_metadata URL.
  2. That URL returns JSON with a resource value that exactly matches the canonical URI of your server, and an authorization_servers array that lists the issuer you expect.
  3. The resource value does not change when the request arrives through a different hostname, such as an internal load balancer name.

The third test catches a common bug: metadata built from the incoming Host header.

Group 2: token validation

For each case, send a request with the altered token and assert 401, and assert that no tool code ran. The second assertion matters. Check that your test tool's side-effect counter is unchanged.

Altered tokenExpected result
aud is a different resource401
aud is missing401
iss is not a trusted issuer401
exp in the past401
Signature from an unknown key401
alg set to none401
Valid token in a query string, not the header401

The audience cases are the ones that matter most. The specification requires your server to accept only tokens issued for it (RFC 8707 resource indicators on the client side, audience validation on yours). A test that sends a token minted for a sibling service is the cheapest way to prove you are not passing tokens through.

Add one test in the other direction: a token you accept must never be forwarded to a downstream API. Point the server's downstream at a recording stub and assert that the stub never sees the inbound Authorization value.

Group 3: scope and tool enforcement

Generate this group from your tool registry, not by hand. For every registered tool:

  • call it with a valid token that lacks the tool's required scope and assert 403 with insufficient_scope in the challenge;
  • call it with the right scope and assert success;
  • fail the build if a registered tool has no declared required scope.

The last rule is the one that pays. A new tool without a scope declaration should not compile into a release. Make the registry enforce it, and let the test confirm it.

Group 4: tenant and user isolation

Create two users in two tenants, each with a record the other must never see. Then:

  • user A requests user B's record by identifier, and the response must be indistinguishable from a record that does not exist;
  • list and search tools return only the caller's tenant data;
  • a tenant claim altered in the token to B's tenant is rejected by signature, and a token legitimately issued for B returns only B's data.

Run these against every tool that takes an identifier or returns a collection. Generate them from the registry in the same way.

Group 5: audit

Every test above has a second assertion: the audit event.

  • A rejected request produces a denial event with the reason, the client, and a request ID, and does not contain the token.
  • A successful call produces one event that names the user, tenant, tool, and outcome.
  • No event, for any test, contains a bearer token, refresh token, or authorization code. Scan the captured log output for the tokens your helper minted.

This ties the suite to the schema in your SIEM mapping. If the schema changes, the test breaks, and the customer's detection rules do not break silently.

Wire it into the pipeline

  • Run groups 1 to 3 on every pull request. They take seconds.
  • Run groups 4 and 5 on every pull request if your data fixtures are small, otherwise on merge to the main branch.
  • Treat any failure as blocking. A flaky authorization test is a bug in the test or in the server. Neither is acceptable to ignore.
  • Pin the SDK version. When you upgrade it, the discovery and token tests are what tell you whether behavior changed.

Track the specification

The MCP authorization specification is revised. When a revision changes a requirement, add the test first, watch it fail, then change the server. Keep a short table in the repository that maps each test to the specification section or RFC it enforces. That table is also useful evidence for a reviewer: it shows a control and the check that proves it still holds.

When you do not need this

If your server is a read-only, single-user, local tool with no network exposure, most of this is excess. A suite this size is for remote servers with multiple users, tenants, or write tools. If that is you, the first three groups are an afternoon of work, and they close the regressions we see most often.

If you want a second pair of eyes on the suite or the server behind it, that is what an MCP Security Audit covers, and we tell you in week one what we find.