Skip to content

Threat model: the MCP server generator

Written before the code. The generator turns a configuration into an MCP server: it can import your modules, call HTTP APIs described by an OpenAPI document, read files and indexes, and run agents, all on behalf of an MCP client (and, behind aaa-server, a remote, authenticated one). The configuration is the new trusted input; what it points at is not.

Trust boundaries

Input Trusted?
The config file, builder code, CLI flags Yes, but it is an executable-ish input: it chooses what is imported and fetched. Treated as operator-authored; hardened against accidental injection (T3).
OpenAPI documents and the descriptions in them No. Their text is shown to a model (T7) and their servers URL tells the server where to connect (T1).
Modules named in module sources The operator's own code, but importing runs it (T2).
MCP client requests (tool arguments, resource URIs, prompt arguments) No: validated against schemas; tenant and user never come from them.
Upstream API responses, file contents, index documents No: returned to the client as data, size-capped.

Threats and decisions

# Threat Decision Ships in
T1 OpenAPI SSRF and credential forwarding. A spec (or a redirect) points the server at internal addresses, or leaks the API credential to another host. A non-empty allowed_hosts is mandatory; every call goes through the SSRF-safe fetcher (resolve once, all addresses public, connection pinned, redirects re-checked). Credentials come only from env: references and are attached only to the configured server's host, never after a redirect; redirects to another host are refused. Authorization, Cookie and Host can never be set from tool arguments. Private networks need an explicit opt-in that logs a warning. M5 (shipped)
T2 Arbitrary module import. A config names a module whose import has side effects, or an attacker-writable config makes the server import attacker code. module sources need an explicit module and allow-list (default __all__, never _names, only functions defined in that module). Introspection never calls the functions. A kill-switch (--no-import-sources, AAA_MCP_ALLOW_IMPORT=0) turns every importing source into a startup error, and a config file writable by others is refused. Module tools require approval unless the operator opts out per tool. M1 (objects), M4
T3 Config injection. YAML tags that construct objects, ${ENV} expansion in unexpected fields, template injection into generated files. yaml.safe_load only; the spec models forbid unknown keys; environment references are expanded only in the fields that declare them; generated files never interpolate user text into Python source (names are validated as slugs; YAML is written from the validated model). M1, M6
T4 Secrets in files, logs and errors. Secrets exist only as env:NAME references; the resolved value lives in a type whose repr is redacted; check, inspect and export print reference names only; a scaffold test plants a canary secret and searches the generated tree. A missing variable is a startup error, not a runtime one. M1, M6
T5 Resource exfiltration. Path traversal or symlinks out of a files root, one tenant reading another's documents or memory, URI-template variables smuggling paths. File resources use the confined FileAccess; index and memory providers filter by the call's tenant; file roots are per-tenant unless shared: true is set explicitly; template variables must match a strict pattern; an unknown resource and a forbidden one are indistinguishable. M3
T6 Cost amplification. An agent tool, a huge upstream response or a fan-out of calls. Every agent tool needs an explicit budget; a global cap on concurrent agent runs; response and request byte caps and timeouts; max_tools; per-source concurrency limits. M2, M5
T7 Prompt injection through descriptions. An OpenAPI description is shown to the model as a tool description. Descriptions are length-capped and treated as untrusted; description_override replaces them; aaa mcp inspect prints exactly what the model will see so an operator can review it. Not fully solvable: a spec you do not control puts its words in your model's context. M5 (shipped)
T8 Approval bypass by defaults. Exposing every operation of an API makes destructive calls available. Non-GET operations and module functions default to requires_approval, which keeps them hidden (indistinguishable from unknown tools) unless the operator opts in; a startup banner lists every state-changing operation exposed without approval. M4, M5
T9 Enumeration through errors. Distinguishing "forbidden" from "missing" resources, tools or prompts. The same response for both. M1, M3

Added for upstream MCP servers, per-tool policy, includes and client config

# Threat Decision Ships in
T10 An upstream MCP server is untrusted input. Its tool descriptions are shown to your model, its results go back to your callers, and it can be slow, huge, or hostile. Descriptions are length-capped and replaceable (description_overrides) and aaa mcp inspect prints what the model will see; results are capped; every call has a timeout; an upstream failing or dying gives a generic tool error and never takes the server down. Unannotated or destructive upstream tools require approval (and so stay hidden) unless you say otherwise; annotations are not trusted unless trust_annotations is set. M7b
T11 Launching a subprocess. A configuration that names a command runs it. No shell (an argument vector); the child gets a minimal environment plus the variables you list in env_from (so a secret in the server's environment is not inherited by accident); AAA_MCP_ALLOW_SUBPROCESS=0 (--no-subprocess-sources) turns every stdio upstream into a startup error before anything is spawned, and a configuration that launches processes is refused when writable by everyone. M7b
T12 Upstream credentials. Only env: references; sent only to the upstream's own host; never in schemas, reports, errors or inspect; a missing variable is a startup error. M7b
T13 SSRF and DNS rebinding through an HTTP upstream. The upstream URL must be https (plain http only to loopback with an explicit flag), its host must be in a mandatory allowed_hosts, and the connection goes through a transport that resolves the name once, requires every address to be public (unless allow_private_networks), connects to that address with the original name as Host/SNI, and follows no redirects. Both SDK generations accept a caller-supplied HTTP client, so the same protection applies on 1.x (httpx) and 2.x (httpx2). M7b
T14 A shared upstream is not tenant-isolated. One connection serves every caller. Stated, not hidden: the operator decides whether an upstream is safe to share. Tenant and user are never forwarded to an upstream. M7b
T15 Policy bypass and enumeration. A tool hidden by scope or tenant must not be distinguishable from a missing one; rate limits and timeouts must not leak internals. Hidden-by-scope answers exactly like an unknown tool; refusals use fixed generic messages. Tested through core and aaa-server with two API keys. M7c
T16 Include/overlay abuse. include that reads outside the configuration's tree, or loops. Included paths are resolved (symlinks too) and must stay inside the top file's directory; depth and size are capped; cycles are an error naming the files. Overlays are operator-chosen. When the composed configuration runs code or processes, every contributing file is checked for world-write. M7d
T17 A client-config entry that leaks a secret. aaa mcp client-config prints variable NAMES as ${NAME} placeholders, never values (checked with canary values in the environment); an HTTP entry must be https unless localhost. M7e

Added for upstream resources and prompts, profiles, hot reload and OAuth to upstreams

# Threat Decision Ships in
T18 Upstream resources and prompts are untrusted content that reaches your callers' models, and a resource URI is a way to ask the upstream for something you did not intend. Both are opt-in per source (resources = true, prompts = true). Resources are listed once at startup and re-exposed under a namespaced URI (aaa://upstream/<source>/<token>); a read is accepted only for a URI the upstream listed (no templates, no arbitrary URI), text only, size-capped, and any failure is the uniform resource not found. Prompts keep only text messages, with names, descriptions, argument values and message sizes capped; arguments must be ones the upstream declared. Content is data for the caller's model exactly as tool results are (T10), and the shared-connection caveat of T14 applies. M8a
T19 Profiles must not be chosen by the caller. A profile that a client could select by a request parameter is a privilege escalation. A profile is a named list of tool, resource and prompt globs. The active profiles come only from the authenticated scopes (profile:<name>, granted by whoever configures the API keys) or, on stdio, from the operator's --profile / tenancy.scopes; nothing in a request can name one. With profiles_required, a caller with no profile sees nothing. A tool outside the profile answers like an unknown tool (T15). M8b
T20 Hot reload runs a new configuration inside a running server. A reload can bring in new code, a new process, a broken file, or a half-built server. A reload builds the whole new server first and swaps it in only if it compiled; any failure keeps the old one running. The same kill-switches and permission checks apply to every reload as to startup, and the new configuration may only refer to code that was already running at startup (modules, objects, algorithms, engines, launched commands): this is checked on the configuration before it is compiled, because compiling is what imports, so a refused reload has run nothing. The server's identity and its set of capabilities (tools, resources, prompts) are fixed at startup: a reload that would change them is refused with "restart required". Reloads are rate-limited, triggered only by SIGHUP, an explicit call, or a file change detected by content hash; the old server's upstream connections close after its in-flight calls finish. M8c
T21 OAuth credentials and tokens for an upstream MCP server or an OpenAPI API. Only the client-credentials grant (machine to machine; an interactive flow has no place in a headless server). client_id / client_secret are env: references; the token endpoint must be https and its host explicitly allowed, and is fetched through the SSRF-safe fetcher; the token is sent only to the upstream's own host, held in memory, refreshed shortly before it expires (one refresh in flight at a time, one retry after a 401), and never appears in logs, errors, schemas or inspect. A token endpoint that answers anything unusable fails the call generically. M8d

Also decided

  • Protocol floor. The generated server supports the MCP SDK 1.x line from 1.21.2 (older 1.x releases no longer import with current pydantic) and 2.x; the stdio and HTTP paths are tested against both.
  • No new log fields. The generator adds nothing to the event log; the frozen v0.2.0 fixtures stay green.
  • Out of scope: authenticating MCP clients on stdio (the process boundary is the trust boundary), interactive (browser) OAuth for upstream APIs, resource templates from upstreams, and what the exposed tools themselves do once called (see the tool, guardrail and server threat models).