Most MCP servers and clients reach production without anyone testing the attacks the MCP project itself documents. The specification's Security Best Practices page lists concrete attacks, from token passthrough and confused deputy flaws to SSRF through OAuth discovery and malicious authorisation URLs, and each one translates into a test case with a clear pass or fail. This guide turns that list into a test plan for MCP servers, MCP clients and hosts, and gateways, and explains how to use the official MCP Inspector and conformance suite safely as test harnesses. It reflects MCP specification revision 2026-07-28, checked on 27 October 2026, and is written for AppSec engineers, penetration testers and teams who build or approve MCP integrations. For agent-level testing such as goal hijacking, use it alongside the AI Agent Security Testing Checklist.
Key takeaways
- Test the documented attacks first. The MCP Security Best Practices page is effectively the protocol's own threat list; every item has a testable MUST or SHOULD.
- Servers and clients fail differently. Servers fail on audience validation, token passthrough, state handles and Origin checks; clients fail on SSRF, URL scheme handling, consent dialogs and issuer validation.
- Conformance is not security. The official conformance suite checks protocol behaviour, including an auth suite; it does not look for injection in tool output or excess privilege. Run both kinds of test.
- The test harness is itself a target. MCP Inspector runs servers and holds OAuth tokens; keep its API token on, bind it to loopback and never set
DANGEROUSLY_OMIT_AUTH. - Retest on every protocol revision. Revision 2026-07-28 removed sessions, added required headers and changed error codes, so tests written for 2025-11-25 can pass while missing new failure modes.
Scope: what an MCP security test covers
An MCP deployment has three testable components, plus the model behaviour that sits on top.
| Component | Typical owner | Main test themes |
|---|---|---|
| Remote MCP server (Streamable HTTP) | Product or platform team, or vendor | Token audience and passthrough, scope design, state handles, requestState integrity, Origin and header validation, tool input validation, downstream authorisation |
| Local MCP server (stdio) | Developer tooling team, open-source maintainer | What it can reach on the host, startup command safety, secrets in environment, any local HTTP listener |
| MCP client or host | IDE, agent platform or in-house app team | SSRF during OAuth discovery, authorisation URL handling, issuer validation, consent dialogs, elicitation URL handling, credential storage |
| Gateway or proxy | Platform team or vendor | Fail-closed authentication, per-tool authorisation, credential brokering, logging; the gateway concentrates every credential |
| Agent behaviour | AI or product team | Indirect prompt injection through tool output, tool poisoning, rug pulls; covered in depth by the agent testing checklist |
Agree scope and rules of engagement in writing before testing third-party hosted servers; you may need the vendor's permission. See the Red Team Rules of Engagement Template.
Test cases from the official attack list
Each row is drawn from the MCP Security Best Practices (revision 2026-07-28) and the normative specification text it points to. Pass criteria are the specification's own requirements.
| Attack | Target | What to test | Pass criteria |
|---|---|---|---|
| Token passthrough | Server | Present a valid token issued for a different resource or audience | Rejected: servers MUST NOT accept tokens not issued for them and MUST validate audience per RFC 8707 |
| Confused deputy | Proxy server using a static client ID to a third-party API | Register a new client with a different redirect_uri after a legitimate consent, then replay the authorisation request | Per-client consent shown before third-party redirect; exact string match on redirect_uri; consent cookie uses __Host- prefix and is bound to the client_id; state single use and set only after consent |
| SSRF via OAuth discovery | Client deployed on a server | Malicious test server returns resource_metadata, authorization_servers or endpoint URLs pointing at private ranges, 169.254.169.254, localhost or a redirect chain | Requests blocked; HTTPS enforced except loopback in development; redirects validated per hop |
| SSRF against the authorisation server | Authorisation server accepting Client ID Metadata Documents | Submit a client_id URL that resolves to an internal address | Fetch blocked by IP range checks or an egress proxy |
| State handle hijacking | Stateful server | Use a handle minted for user A while authenticated as user B; try predictable handles | Rejected; handles random, expiring and bound server-side to the verified user |
Tampered requestState | Server using multi round-trip requests | Modify, replay or reuse the opaque state on retry | Integrity failure rejected (HMAC or AEAD); replay rejected where single use matters |
| Malicious authorisation URL | Client | Test server supplies javascript:, data:, file: or vbscript: authorisation URLs, or URLs containing shell metacharacters | Only https (and http on loopback) accepted; URL never opened through a shell |
| Mix-up attack | Client | Second authorisation server returns a code with a different or missing iss | Client records issuer before redirect and rejects a mismatched iss (RFC 9207); credentials keyed by issuer |
| Local server compromise | Client with one-click install | Install link with a long or obfuscated startup command | Full command shown untruncated, flagged as code execution, explicit approval required |
| DNS rebinding | Local HTTP server | Requests with a foreign Origin header | HTTP 403 for invalid Origin; server bound to localhost |
| Scope inflation | Server and authorisation server | Inspect scopes_supported and challenges; request privileged tool with a minimal token | No wildcard or omnibus scopes; precise WWW-Authenticate scope challenge; elevation logged |
Protocol-level checks added in 2026-07-28
- Header binding: Streamable HTTP POST requests must carry
Mcp-Methodand, where applicable,Mcp-Name. Send a body whose method differs from the header: the server should answer HTTP 400 with theHeaderMismatcherror (-32020). Gateways that authorise on headers but forward bodies are the risk this closes. - Schema handling: implementations must not automatically dereference
$refvalues that point to network URIs, and should bound schema depth and subschema counts. Feed tool schemas with remote$refand deep nesting to clients and gateways. - No session identity:
Mcp-Session-Idis gone. Check that servers upgraded from earlier revisions do not still treat a session-like value as proof of identity.
Using MCP Inspector and the conformance suite safely
MCP Inspector as a test client
The Inspector (v2 ships as the single package @modelcontextprotocol/inspector; v1 receives security fixes only) is the project's interactive client for exercising tools, resources, prompts, OAuth flows and elicitation against a server. Its own documentation sets out the security model you should keep intact when using it on a test bench:
- API token: every
/api/*route is guarded by a bearer token, random per launch unless you setMCP_INSPECTOR_API_TOKEN.DANGEROUSLY_OMIT_AUTHdisables it; do not use it. - Binding:
HOSTdefaults to127.0.0.1, and all-interfaces binds are refused unlessDANGEROUSLY_BIND_ALL_INTERFACESis set. The Docker image sets that flag, so publish the port as127.0.0.1:6274:6274, never a bare-p 6274:6274, which exposes the Inspector to your network. - Origins and hosts:
ALLOWED_ORIGINSandMCP_INSPECTOR_ALLOWED_HOSTSrestrict which browser origins andHostheaders are served; other hosts get HTTP 403. - Secrets: the Inspector persists acquired OAuth tokens by default. Its secret-storage documentation is explicit that the file store does not protect against code running as the same user, including the stdio servers the Inspector launches. On a bench that runs untrusted servers, use
MCP_INSPECTOR_SECRET_STORE=memoryand test accounts only. - Isolation: stdio servers launched by the Inspector receive only a short environment allowlist plus their configured
env, but they still run as your user. Run unknown servers in a disposable VM or container with no production credentials.
Conformance suite
The @modelcontextprotocol/conformance framework tests clients (it starts a scenario server and runs your client against it) and servers (it connects as a client). Useful options for security work are --suite auth, --spec-version 2026-07-28 to pin the revision under test, and --expected-failures with a YAML baseline so CI fails only on regressions. Treat a pass as evidence of correct protocol behaviour, then add your own negative tests from the table above.
Choosing test methods
| Method | Finds | Misses | When to use |
|---|---|---|---|
| Conformance suite in CI | Protocol and auth flow regressions | Business logic, injection, privilege | Every build of a server, client or SDK fork |
| Manual testing with Inspector and an intercepting proxy | Audience, scope, state and header flaws | Behaviour at scale | Before first release and after auth changes |
| Malicious test server against a client | SSRF, URL handling, consent and elicitation flaws | Server-side issues | Evaluating any MCP client or host you deploy |
| Agent red teaming | Prompt injection through tool output, tool poisoning effects | Protocol details | Agents with write tools or sensitive data; see the AI Red Teaming Guide |
| Code review and SAST | Command injection, path traversal, secrets in code | Runtime configuration | Open-source servers before approval |
Small organisations that mostly consume vendor servers should focus on testing their clients and gateway and on asking vendors for test evidence against the table above. Organisations that publish servers should own the full table and run conformance in CI.
Testing tools and tool output
- Tool definitions: diff
tools/listoutput across versions and runs; 2026-07-28 asks servers to return tools in deterministic order, which makes unexpected changes easier to spot. Review descriptions for hidden instructions (ATLAS AML.T0110 AI Agent Tool Poisoning). - Input validation: fuzz tool arguments against
inputSchema; look for command injection, path traversal and SQL injection in the tool implementation, mapped to ASVS input validation requirements. - Object-level authorisation: call tools with identifiers belonging to another user (OWASP API1:2023 Broken Object Level Authorization) and test function-level checks on admin tools (API5:2023).
- Tool output as an attack channel: plant instructions in data the server returns, such as a ticket, error report or document, and confirm the agent does not act on them without approval. The Sentry MCP agentjacking research is a realistic template: a fake error event led coding agents to run a package command.
- Resource consumption: check rate limits and pagination bounds on list and read operations (API4:2023 Unrestricted Resource Consumption).
Testing gateways and proxies
A gateway sits between many clients and many servers, so a single flaw exposes every connected credential. Test it as both a server (to clients) and a client (to servers).
- Fail closed: send requests with no token, an empty bearer value, a one-character token, an expired token and a token from another issuer. Every one must be refused before any tool list or call is processed.
- Policy on the right field: where the gateway authorises by tool name, send a request whose
Mcp-Nameheader names an allowed tool while the body calls a blocked one. The gateway must reject the mismatch or authorise on the body, never on the header alone. - Credential brokering: confirm clients never receive the downstream credential, that per-user tokens are not shared across users, and that the gateway does not forward the client's token downstream (passthrough at the gateway is the same flaw as passthrough at a server).
- Management plane: test the admin API and test endpoints separately from the MCP route; they often have weaker authentication and more power, such as the ability to add servers or run connection tests.
- Logging: check that every test call appears in gateway logs with client identity, server, tool and decision, and that secrets are redacted.
See the MCP Gateway and MCP Server Governance Guide for the controls these tests verify.
Running an MCP test programme
- Inventory and tier: list servers, clients and gateways, and tier them by data access and write capability. Test high tiers first.
- Build the bench: isolated VM or container network, test identity provider tenant, test accounts, an intercepting proxy, the Inspector on loopback with memory secret storage, and a malicious test server for client tests.
- Baseline with conformance: run the suites for the revision you support and record expected failures.
- Run the attack table: one test per row, with evidence (request, response, log line) for each result.
- Agent tests: add prompt injection and tool poisoning scenarios for agents with write tools.
- Fix and retest: track findings by severity; retest fixes and add each as a regression test in CI.
- Repeat on change: retest on every new protocol revision, SDK upgrade, new tool, scope change or gateway policy change. Roll back a release that fails a high-severity test rather than shipping with an exception.
Metrics
- Share of tier-1 servers and clients tested against the full attack table in the last 12 months.
- Open high-severity MCP findings and their median age.
- Conformance suite pass rate at the supported revision, excluding the documented baseline.
- Number of regression tests added per finding (target: at least one).
- Time from a new protocol revision to completed retest of tier-1 components.
Framework mapping
| Activity | NIST SP 800-53 Rev. 5 | NIST CSF 2.0 | Threat references |
|---|---|---|---|
| Penetration testing of servers, clients, gateways | CA-8 Penetration Testing; CA-2 Control Assessments | ID.RA-01 | ATT&CK T1190 Exploit Public-Facing Application |
| Conformance and developer testing in CI | SA-11 Developer Testing and Evaluation; SA-11(1) Static Code Analysis | PR.PS-06 | OWASP ASVS 5.0 |
| Token audience and passthrough tests | SC-7 Boundary Protection; AC-3 Access Enforcement | PR.AA-05 | ATT&CK T1528 Steal Application Access Token; OWASP API2:2023 |
| SSRF tests | SC-7; SI-10 Information Input Validation | ID.RA-01 | OWASP API7:2023 Server Side Request Forgery |
| Tool poisoning and injection tests | SI-10; RA-5 Vulnerability Monitoring and Scanning | DE.CM-09 | ATLAS AML.T0110; AML.T0051.001 Indirect prompt injection; mitigation AML.M0033 |
Common failure patterns
- Testing only the happy path. A server that completes the OAuth flow correctly can still accept tokens for another audience. Negative tests matter more than positive ones.
- Fail-open authentication. The LiteLLM MCP auth bypass (CVE-2026-59822, in CISA KEV since 2 September 2026) fell back to an empty authentication object when token validation failed, so any bearer token, even one character, produced a session. Always test malformed, empty and wrong-audience tokens.
- Ignoring build and hosting inputs. The Smithery.ai MCP hosting breach came from an unvalidated build path setting, not from the MCP protocol. Include platform configuration in scope.
- Exposing the test harness. An Inspector published on all interfaces with auth disabled is a remote command runner on the tester's machine.
- Testing with real credentials. Tokens stored by test clients are readable by the servers under test; use dedicated test tenants.
- Stale revision. Passing tests against 2025-11-25 says little about header validation or state handling in 2026-07-28 deployments.
Practitioner checklist
- Map every MCP server, client and gateway to a test tier and owner.
- Run each row of the official attack table and keep evidence per test.
- Run the conformance suite with
--spec-versionpinned and an expected-failures baseline in CI. - Keep the Inspector on loopback with its API token on, and use memory secret storage on benches that run untrusted servers.
- Test negative token cases: wrong audience, empty, malformed, expired, other issuer.
- Test clients with a malicious server for SSRF, URL schemes, mix-up and consent dialogs.
- Add prompt injection through tool output and tool definition diffing for agents with write tools.
- Retest on every protocol revision, SDK upgrade and scope change.
Standards and references
- Model Context Protocol: Security Best Practices
- Model Context Protocol: Authorization (revision 2026-07-28)
- Model Context Protocol: Streamable HTTP transport
- Model Context Protocol: MCP Inspector repository and documentation
- Model Context Protocol: MCP Conformance Test Framework
- OWASP: API Security Top 10 2023
- OWASP: Application Security Verification Standard 5.0
- MITRE ATLAS: AI Agent Tool Poisoning
Related NHI Mgmt Group resources: AI Agent Security Testing Checklist · MCP Security Guide · Remote MCP Server Hardening Guide · MCP Authorisation Specification Guide · MCP Incident Response Playbook