In the previous post in this series I built a 10-test harness for the MCP 2026-07-28 authorization rules. A quickstart-style server passed 2 of them. A hardened version passed all 10.
That left an uncomfortable follow-up question. I maintain an MCP security scanner, mcpscan. If the naive server had shipped, would my scanner have stopped it? Would anyone's?
So I ran three static scanners against both servers. They produced the same report for the broken one and the fixed one.
TL;DR
- I scanned an MCP server that fails 8 authorization tests with three static analysis tools: mcpscan (my own, 23 rules in v0.20), Semgrep (200 rules from the
p/python,p/jwtandp/security-auditpacks) and Bandit.- All three found 0 of the 8 auth bugs. They reported identical findings for the naive and the hardened server, so their output couldn't tell the two apart.
- Five custom Semgrep rules, about 40 lines of YAML, caught 3 of 8 (no audience check, no issuer check, token read from the query string) with zero hits on the hardened server.
- The other five (missing discovery headers and metadata, missing scope checks, anonymous
tools/list, token passthrough) only showed up when a test talked to a running server.- Static scanners aren't wrong here. They're looking for a different class of bug. Auth for MCP servers needs runtime tests in CI, with a few static rules as a cheap early warning.
The setup
Both servers come from the auth harness. To keep the comparison clean, I split the original two-mode file into two single-mode copies, naive/server.py and hardened/server.py, so a scanner only ever sees one version. Then I re-ran the harness against each copy to make sure the split didn't change behaviour: still 8 failed and 3 passed for naive, 11 passed for hardened (10 tests plus a control).
The eight failures the scanners had to find:
| # | Failure in the naive server | Spec level |
|---|---|---|
| 01 | 401 without WWW-Authenticate / resource_metadata
|
MUST (header or well-known URI) |
| 02 | No Protected Resource Metadata endpoint | MUST |
| 04 | No audience validation | MUST |
| 05 | No issuer validation | MUST (via OAuth 2.1) |
| 07 | No per-tool scope check | SHOULD |
| 08 |
tools/list open to anonymous callers |
SHOULD |
| 09 | Client token forwarded to the downstream API | MUST NOT |
| 10 | Token accepted from ?access_token=
|
MUST NOT (client rule) |
Some of these are as obvious in the source as a bug can be. The decode call literally says:
claims = jwt.decode(token, signing_key(token), algorithms=["RS256"],
options={"verify_aud": False})
The results
What each tool did report, for both servers:
- mcpscan: nothing. "Clean, no issues found."
-
Semgrep (200 rules run): one finding,
dynamic-urllib-use-detectedon the downstream call, becauseurllibsupportsfile://URLs. -
Bandit: two findings: B310 on the same
urllibcall, and B105 "possible hardcoded password" on an empty string default.
None of those are about authorization, and all of them appear in the hardened server too. The verify_aud: False line above went unflagged by all three.
My own scanner deserves the most direct explanation. mcpscan's auth-adjacent rule, MCP012, checks client configuration: a remote MCP server entry with no auth header, or a hardcoded bearer token. It looks at how you connect to a server, not at how a server validates tokens. That's a real gap, and I'd rather find it with a harness than have someone find it in production.
Five rules that catch three bugs
Semgrep makes it cheap to encode a specific "never do this". These two rules did most of the work:
rules:
- id: jwt-audience-check-disabled
languages: [python]
severity: ERROR
message: Audience validation disabled. MCP 2026-07-28 says servers MUST validate the token audience (RFC 8707).
pattern: 'jwt.decode(..., options={..., "verify_aud": False, ...}, ...)'
- id: jwt-decode-without-audience
languages: [python]
severity: ERROR
message: jwt.decode() without audience= accepts tokens minted for other services.
patterns:
- pattern: jwt.decode(...)
- pattern-not: jwt.decode(..., audience=$A, ...)
Add the same shape for issuer=, and one rule for $Q.get("access_token", ...), and you get this against the naive server:
access-token-from-query-string line 73
jwt-audience-check-disabled line 77
jwt-decode-without-audience line 77
jwt-decode-without-issuer line 77
Against the hardened server: zero findings. Four hits on the naive server cover three distinct bugs (04, 05 and 10).
The fifth rule was the one I most wanted to work: a taint rule from headers.get("Authorization") to a downstream add_header("Authorization", ...), which would catch token passthrough (09). It found nothing. In this server the token is read in one function, returned, and handed to a second function that makes the downstream call. My best guess is that this cross-function flow is beyond what the rule can follow in Semgrep's open-source engine; I didn't dig further. The runtime test caught it in one assertion.
Why the other five can't be seen statically
Look at what the remaining failures have in common:
- 01 and 02 are about something missing: a header that's never set, an endpoint that doesn't exist. Static rules find bad code much more easily than absent code.
- 07 and 08 depend on a mapping between tools and scopes, and on which methods your policy says are public. That's business logic a generic rule can't know.
- 09 is a data flow across functions, which is hard for pattern-based tools by design.
A runtime test doesn't care how the code is written. It sends a request and checks the response, or checks what the fake downstream received. That's why the harness caught 8 of 8 and the scanners caught 0.
What I'd put in CI
- The runtime harness, on every pull request that touches the server. Ten tests ran in about 3 seconds here.
-
A handful of custom static rules for the patterns you never want to see:
verify_aud: False,decode()withoutaudience=, tokens from query strings. They fail fast, before anything starts. -
Your general scanners as well. Semgrep and Bandit flagged a real hardening point (the
urllibscheme), and mcpscan covers configuration and supply-chain risks the harness doesn't. They just aren't an auth test.
And on my side: mcpscan needs server-side auth rules. The two Semgrep patterns above are the obvious starting point.
Caveats
- One server, written by me. The naive baseline is deliberately typical, not a sample of real-world servers.
- Three scanners, default or common rule packs, in Python. Commercial SAST tools, Semgrep Pro's cross-file analysis, or other languages may do better, especially on the passthrough case.
- mcpscan is my project, so treat my explanation of its scope as the author's view. The scan output itself is unedited.
Update: I fixed mine
A scanner that misses all eight is a roadmap, so I wrote the rules. mcpscan now ships seven server-side authorization rules, MCP024 to MCP030, built on the Python AST rather than regex. Same naive server, same command:
| # | Failure | Before | After | Rule |
|---|---|---|---|---|
| 01 | 401 without resource_metadata
|
no | yes | MCP027 |
| 02 | No Protected Resource Metadata endpoint | no | yes | MCP028 |
| 04 | No audience check | no | yes | MCP025 |
| 05 | No issuer check | no | yes | MCP026 |
| 07 | No per-tool scope check | no | no | runtime only |
| 08 | Anonymous tools/list
|
no | no | runtime only |
| 09 | Token passthrough | no | yes | MCP029 |
| 10 | Token from ?access_token=
|
no | yes | MCP030 |
0 of 8 became 6 of 8, with 0 findings on the hardened server. MCP024 also flags jwt.decode with signature verification turned off. I ran the new rules over fastmcp, the official mcp SDK, LiteLLM and seven other MCP projects to hunt for false positives; the two causes I found are fixed and covered by tests. Scope checks and anonymous listing stay runtime-only for the reasons above, so the harness still earns its place in CI.
The rules are on the mcpscan main branch.
The takeaway
A clean scanner report means the scanner found nothing in its own rule set. These three tools ran hundreds of rules and gave the same verdict on a server that fails eight authorization tests and on one that passes them all. Test MCP auth the way an attacker would hit it, against a running server, and add static rules for the mistakes you never want to see.
Has your scanner ever given a clean report on a bug you later found by hand?


Top comments (17)
Honest result, and rare to see a maintainer test their own scanner this way. Did the 3 custom Semgrep rules that worked also hold up on an MCP server you didn't write, or are they still tuned to your two test servers?
Fair question, and the honest answer is no: the five Semgrep rules were only ever run against my two test servers, so I can't claim they generalise. What did get run on code I didn't write is the follow-up, the seven AST rules that went into mcpscan (MCP024 to MCP030). I ran those over fastmcp, the official mcp SDK, LiteLLM and seven other MCP projects to look for false positives, found two causes and fixed them. That only shows they stay quiet on good code, though. The useful next test would be a real server with an auth bug I didn't plant myself.
That split makes sense, quiet on good code is only half of it. For a bug you did not plant, older releases of MCP servers with published security advisories could work as a test set, since the fix commit shows exactly what a scanner should have flagged.
That's the test set I was missing. A vulnerable release plus its fix commit gives you ground truth for free: the scanner should fire on the old tag and go quiet on the new one. My guess is the auth slice would be small, since the advisories I remember are mostly about what tools do with their input rather than token handling. Still worth building, even a dozen pairs would say more than one server I wrote myself.
A dozen pairs is a good size, and the thin auth slice is a finding in itself. One thing I'd keep: pairs where the fix landed in a dependency bump rather than the server code. A scanner that stays quiet on both tags there isn't blind, it just can't see it, and the write-up should say which of the two it was.
This matches what we saw from the outside. On November 4 we checked 61 login-protected vendor MCP servers against the 2026-07-28 spec with a passive probe: one unauthenticated initialize plus the public discovery documents. All 61 got the 401 and PKCE right. But 40 didn't advertise the RFC 9207 issuer parameter, and 22 gave no scope hint in the 401 or in scopes_supported. None of that is in the source a scanner reads, and all of it shows up in one anonymous request to the running server. Your tests 01 and 02 alone would make a cheap CI gate.
61 servers with one anonymous request each is a nice way to size this. It matches what I saw: the parts every library and tutorial pushes you toward (the 401, PKCE) are fine, and the parts you only get by reading the spec closely, like the RFC 9207 issuer parameter and scope hints, are where people drop off. And yes, 01 and 02 together cost about a second in CI. Are you planning to publish the per-check counts? That would be useful for anyone choosing between vendors.
They're in the write-up, per vendor too: all 61 return the 401 and support PKCE, 36 don't advertise a Client ID Metadata Document, 40 skip the RFC 9207 issuer check, 22 give no scope hint. x1y1.co/journal/official-mcp-serve...
One runtime assertion I would add to the harness: send the request twice, once with no token and once with a token in the right header that the server cannot accept, and require the two 401s to differ. RFC 6750 already draws the line: without credentials the challenge should carry no error code, and with a rejected token it says error="invalid_token". When the two answers are identical, a client behind a proxy that strips the header, or one using the wrong header name, cannot tell whether its token ever arrived, and it debugs the token instead of the plumbing. I ran the same pair last week against six hosted memory APIs that use API keys, with a made-up key in each one's documented header: four answered both requests identically.
That's a good assertion and cheap to add: two requests, compare the challenges, fail if they match. As written, test 01 only cares that the challenge and resource_metadata are there at all, so a proxy that strips the Authorization header would still pass it. Four of six answering identically is higher than I'd have guessed. Did any of the four at least differ in the body, or was it the same bytes all the way down?
Same bytes all the way down. I reran the pair today and compared the full responses: for all four the status, the body length and the SHA-256 of the body are the same with and without the token.
Only one of the four sends a WWW-Authenticate header at all, Bearer realm="api", identical in both answers, with no error code and no resource_metadata. The other three send no challenge, so a client has only the body to go on, and the body does not change.
Flagging absent code in Python AST gets messy once an ingress enters the picture: if Envoy or Cloudflare serves Protected Resource Metadata and
WWW-Authenticate, MCP027/MCP028 will cry wolf until someone mutes them in CI. Did any of the ten repos you checked terminate auth at a gateway, or were they all app-handled?Fair worry. The ten I ran were libraries and SDKs (fastmcp, the official mcp SDK, LiteLLM and seven more), not deployments, so none of them had a gateway in front and I can't claim the gateway case is covered. When Envoy or Cloudflare owns the 401 and the metadata, the app code never mentions them and MCP027/MCP028 have nothing to see. The way I'd scope those two: fire only when the same codebase validates tokens itself, because a server that decodes JWTs but never sets WWW-Authenticate is the real bug, and one that never touches a token is probably fronted by something else. For gateway setups a per-rule ignore in CI is fine, as long as a runtime check against the public URL proves the header actually shows up there.
This lines up with the usual SAST blind spot: auth and authorization are runtime, cross-request decisions, so a static scanner reads the handlers but never sends an unauthenticated or cross-tenant request to see whether the guard actually fires. A dynamic harness that probes each tool without a token, with the wrong scope, and after expiry catches what pattern matching misses. On the desktop side it's the same gap: linting the IPC handlers won't prove a renderer can't invoke a privileged channel — you need integration tests that actually send those messages and assert they're rejected.
The IPC comparison fits well, it's the same shape of bug: the handler that should refuse the call looks fine on its own, and only a message sent across the boundary tells you whether it does. On expiry, the case I'd add is a token that expires halfway through a long tool call, since it's easy to test one that's already expired and never test that one.
Your result matches what the protocol docs imply. MCP authorization is optional, and the interesting failures are usually "the server shipped without audience checks or token binding," not a bad regex in source (MCP Authorization spec, 2026-07-28). A static rule can flag a missing library call, but it cannot tell whether a live server rejects a token minted for a different audience, or whether a tool description changed after the client first listed it. The harness you already built against the 2026-07-28 rules is the control I would keep as the merge gate, and I would add two runtime cases scanners also miss: a token with the wrong audience, and a second tools/list after the server has been up long enough to change a description. Your finding is the right caveat for any scanner comparison: use those tools for known patterns, not as proof the auth story works.
Agreed on keeping the harness as the merge gate. The wrong-audience token is test 04, and on the naive server it was the worst failure because it paired with passthrough. The second tools/list after some uptime is the one I don't have, and I like it: a description that changes mid-session never shows up in a scan of the repo. I'd hash the tools/list response at start, again after a wait, and fail on any diff.