mcp implementation security review
Review the implementation source code of MCP (Model Context Protocol) servers, clients, and tool handlers against a security baseline — authentication, sessions, rate limiting, input-schema validation, official-SDK usage, RCE vectors, and the OWASP MCP Top 10 — producing a report with file/line evidence. Use this skill when: - Reviewing an MCP server implementation for security before release - Checking a server against the baseline controls (MCP-01 to MCP-05) and the OWASP MCP Top 10 - Auditing
Documentation & Preview
--- name: mcp-implementation-security-review description: | Review the implementation source code of MCP (Model Context Protocol) servers, clients, and tool handlers against a security baseline — authentication, sessions, rate limiting, input-schema validation, official-SDK usage, RCE vectors, and the OWASP MCP Top 10 — producing a report with file/line evidence. Use this skill when:
- Reviewing an MCP server implementation for security before release
- Checking a server against the baseline controls (MCP-01 to MCP-05) and the OWASP MCP Top 10
- Auditing tools for RCE vectors (command/code injection, unsafe deserialization, path traversal, SSTI, dependency hijacking, SSRF)
- Verifying auth, session, rate-limiting, and input-validation controls on a network-exposed server
- Reviewing MCP client code that handles untrusted server responses and session IDs
- Requests like "review this MCP server for security" or "is my MCP server implementation secure?"
---
MCP Implementation Security Review
Process
Step 1 — Classify the target
- Check MCP protocol version 2025-03-26 or later (current: 2025-11-25). Flag older versions as a finding but continue the review.
- Determine whether the target is a server or client.
- Classify transport as network-exposed or local-only using the transport reference below.
- Record transport, protocol version, and whether sessions exist.
Completion criterion: Target type, protocol status, and transport are identified.
Step 2 — Filter false positives
- Apply the False Positive Filters before opening findings.
- Keep docs only when they describe the repo's own server behavior, deployment, transport, or auth posture.
- For framework/SDK repositories, scope findings to the default configuration and public API surface.
Completion criterion: Remaining evidence is in-scope code, repo-owned docs, or public API behavior.
Step 3 — Check baseline controls
- For network-exposed servers, check MCP-01 through MCP-05.
- For local/STDIO servers, do not mark baseline controls PASS/FAIL; give best-practice notes and continue to RCE review.
- For clients, only review token/session handling explicitly visible in client code; do not apply the server baseline unless the user asks for client-side risk review.
Completion criterion: Each applicable control has a supported status.
Step 4 — Check RCE vectors
- Review all 7 RCE vectors.
- Mark each vector SAFE, AT RISK, or N/A.
- Prefer direct evidence over inference; the RCE Vectors table below enumerates the patterns to look for.
Completion criterion: Every relevant tool has an RCE result or explicit N/A.
Step 5 — Check OWASP MCP Top 10
- Evaluate all 10 OWASP risks below.
- If a control from Step 3 already fully covers an OWASP risk, reference that result rather than re-checking.
- For local/STDIO servers, mark network-dependent OWASP risks (MCP07, MCP09) as N/A.
- Mark each risk PASS, FAIL, or NEEDS INVESTIGATION.
Completion criterion: All 10 OWASP risks have outcomes supported by observable evidence or referenced from Step 3.
Step 6 — Report
- Use the Compliance Output Format below.
- Include file/line references in every justification.
- Separate code findings from manual follow-ups.
- If evidence is incomplete, use NEEDS INVESTIGATION and name the missing artifact.
Completion criterion: The report includes controls, RCE, optional OWASP, and actions.
Reference
Decision rules
- Network-exposed server: Apply all 5 controls, then run RCE and requested OWASP checks.
- Local/STDIO server: Give best-practice guidance only for the 5 controls; still run RCE because tool input can execute locally.
- Client: Review received-token handling and refusal to trust server-provided session IDs; do not force server controls unless asked.
- Reverse proxy or container exposure: If traffic can reach the server over a network, treat it as network-exposed even if inner binding is localhost.
- Unclear evidence: Do not guess. Mark NEEDS INVESTIGATION and say what must be verified manually.
- Ambiguous auth coverage: Auth middleware exists but it is unclear whether it covers MCP endpoints → mark NEEDS INVESTIGATION.
- Undeterminable transport: If transport cannot be established from code, flag for manual review and do not assume STDIO — defaulting to STDIO would wrongly skip the server controls.
Transport classification
Network-exposed (enforce all controls):
| Pattern | Transport | |---|---| | transport="http" or transport="sse" | HTTP/SSE | | StreamableHttpServerTransport | HTTP (TS/JS) | | SSEServerTransport | SSE (TS/JS) | | WithHttpTransport() | HTTP (C#) | | host="0.0.0.0" | All-interfaces binding | | Express .listen(port) with MCP routes | HTTP (default 0.0.0.0) | | EXPOSE in Dockerfile + MCP server | Network-exposed |
Local-only (best practices only):
| Pattern | Transport | |---|---| | StdioServerTransport | STDIO (TS/JS) | | WithStdioServerTransport() | STDIO (C#) | | transport="stdio" | STDIO | | mcp.run() with no args (Python FastMCP) | STDIO default | | .vscode/mcp.json with command key and no URL | STDIO child process |
Host binding gotchas:
| Binding | Actual exposure | |---|---| | host="0.0.0.0" | 🔴 Network-exposed | | host="127.0.0.1" or localhost | 🟢 Local-only | | No explicit host (Express/Node) | 🔴 Defaults to 0.0.0.0 | | No explicit host (Python FastMCP) | 🟡 Depends on transport — verify | | Docker ports: "8000:8000" | 🔴 Network-exposed even if the process binds 127.0.0.1 inside the container |
False Positive Filters
| FP pattern | How to detect | |---|---| | .github/skills/ templates | Path contains .github/skills/ — skill template, not server code | | Vendored SDK / OSS copies | File defines class FastMCP, class McpServer, or path is in node_modules/, vendor/ | | MCP client configs | .vscode/mcp.json with inputs/servers but no server code | | Documentation / tutorials | .md, .rst with code fences unrelated to the repo's own server | | Outbound-only auth libraries | DefaultAzureCredential, service account JSON, or similar used only for outbound auth |
Docs describing the repo's own server behavior, transport, auth posture, or deployment are not false positives.
Controls Reference
MCP-01 — Identity isolation
Scope: Remote MCP servers
Condition
- Authenticate every inbound request with a trusted identity provider and enforce authorization at the server boundary; do not infer auth from session IDs, prior requests, or network location.
- Use a unique server-specific application identity and audience/resource identifier; outbound calls use independently scoped service credentials or on-behalf-of flow where required, never the inbound token.
- Unauthenticated discovery endpoints are allowed only for metadata-only OAuth/MCP bootstrapping:
/.well-known/oauth-protected-resource,/.well-known/oauth-authorization-server,/.well-known/openid-configuration.
What to check
- Token validation and authorization middleware run on every MCP route; authorization distinguishes tool invoke, read-only, and admin operations if present.
- Identity config shows a dedicated application/client/resource ID and audience; outbound clients acquire their own tokens and never copy inbound
Authorization. - Discovery endpoints return metadata only and cannot execute tools or expose protected data.
Key pitfall: Shared application identities or forwarded caller tokens break identity isolation and create confused-deputy paths.
MCP-02 — Sessions
Scope: Remote MCP servers that support sessions
Applicability
- No session identifiers issued or used anywhere → mark N/A (per-request auth is still required; see MCP-01).
- Sessions managed by the transport/SDK (e.g., Streamable HTTP
Mcp-Session-Id) but generation/binding not visible in source → mark NEEDS INVESTIGATION, not FAIL. - Session identifiers present in code → score PASS/FAIL against the conditions below.
Condition
- Authenticate and authorize every request; session state never substitutes for token validation.
- Session IDs are opaque correlation/continuity tokens only; they do not grant privileges, encode authorization, or bypass auth.
- Session IDs are CSPRNG-generated, unpredictable, bound to an authenticated context, and never embedded in URLs.
What to check
- Middleware validates tokens per request, not only when a session starts.
- Authorization logic never trusts a session ID alone; loss or reuse of a session ID must not grant access.
- Session creation uses random IDs (GUID v4/CSPRNG acceptable; sequential or time-based IDs are not).
Key pitfall: Treating a session ID as a bearer credential turns a correlation token into authentication.
MCP-03 — Rate limits
Scope: MCP servers and tools
Condition
- Enforce rate limits and abuse protection on tool discovery and tool invocation.
- Enforce limits at the MCP server runtime, not only at a gateway; partition by authenticated identity and by session where sessions exist.
- Apply stricter limits to mutation-capable and high-cost tools; when limits are exceeded, fail closed with HTTP 429 and Retry-After and do not execute the tool.
What to check
- Rate-limit middleware or equivalent is present on discovery and invocation endpoints in server code, not just in ingress or proxy config.
- Limits are keyed by identity and session, with tighter budgets for write/high-cost operations.
- Exceeded requests stop before backend action and return 429 with Retry-After.
Starting thresholds (tune to actual load, downstream limits, and cost):
| Tool type | Per-identity | Per-session | Notes | |---|---|---|---| | Read-only / listing | 100/min | 200/min | Lower if downstream APIs are sensitive | | Mutation / write | 10/min | 20/min | Stricter for state-changing ops | | High-cost compute | 5/min | 10/min | Cost-weighted; watch cloud spend | | Tool discovery | 30/min | 60/min | Prevents enumeration abuse |
Key pitfall: Gateway-only throttling or one flat bucket leaves bypasses and under-protects expensive tools.
MCP-04 — Schema validation
Scope: MCP servers exposing tools with structured arguments
Condition
- Validate all tool arguments against explicit schemas before execution.
- Schemas define types, required fields, enums, and bounds, and reject unspecified properties by default (
additionalProperties: falseor equivalent). - Validation runs server-side on every invocation; invalid input fails closed with a 400/MCP error and no backend action.
What to check
- Each tool descriptor has a schema covering types, required fields, enums, bounds, and property restrictions.
- Validation occurs at the server boundary on every call, not only in clients, gateways, or downstream services.
- Negative tests reject malformed input, extra properties, and bounds violations.
Key pitfall: Allowing extra properties or client-only validation creates hidden attack surface and scope creep.
MCP-05 — SDK-first
Scope: Remote MCP servers
Condition
- Build remote MCP servers on an official MCP SDK for your server's language:
- Tier 1 (fully supported): TypeScript (modelcontextprotocol/typescript-sdk), Python (modelcontextprotocol/python-sdk), C#/.NET (modelcontextprotocol/csharp-sdk), Go (modelcontextprotocol/go-sdk)
- Tier 2/3 (developing): Java (modelcontextprotocol/java-sdk), Kotlin (modelcontextprotocol/kotlin-sdk), Rust (modelcontextprotocol/rust-sdk), Swift (modelcontextprotocol/swift-sdk), PHP (modelcontextprotocol/php-sdk), Ruby (modelcontextprotocol/ruby-sdk)
- If not using an of