Veroffentlicht am
- 14 min read
Sichere und skalierbare MCP-Architektur: Schutz des Modellkontextprotokolls von Repository bis Laufzeit
Security and scale don’t happen in production; they’re designed into the first commit.
Why “secure and scalable” MCP is its own discipline
The Model Context Protocol (MCP) changes the shape of application risk. Traditional apps already wrestle with identity, secrets, and data access—but MCP adds a new layer: context orchestration. The system is no longer just code calling APIs. It’s a chain of tools, prompts, retrieval sources, and function calls that can be induced to behave differently under adversarial or simply messy input.
A robust MCP architecture treats context as a governed asset. That means you need to secure:
- How context is selected (what is included or excluded)
- How context is transported (between client, server, and tools)
- How context is executed (tool calls, side effects, and write operations)
- How context is audited (who asked, what was used, what happened)
And you need to do this while scaling horizontally, across repos, and across teams—without turning your MCP servers into “magic boxes” no one can reason about.
This article focuses concretely on MCP repositories and the production-grade architecture around them: identity, tool boundaries, secrets, policy, observability, and supply-chain controls.
Start with the threat model: what goes wrong in MCP systems
A secure MCP design begins by naming failure modes in plain language. In practice, most incidents map to a few categories:
Prompt- and context-driven abuse
- Context injection via untrusted documents, web pages, issue comments, or chat messages that alter tool behavior.
- Tool coercion where the model is induced to call a privileged tool (“delete”, “refund”, “rotate keys”) or to exfiltrate sensitive data.
- Cross-tenant leakage when retrieval indexes, caches, or logs accidentally mix tenants.
Identity and access drift
- Over-broad tokens in tool adapters.
- A shared “service account” with no per-user traceability.
- Missing authorization checks because the model “decides” what to call.
Supply chain compromise
- Malicious dependency updates in MCP server repos.
- Unsafe container images or base images.
- Unreviewed tool definitions that secretly broaden capability.
Operational risk at scale
- No rate limiting, leading to cost blowouts and denial-of-wallet.
- Poor observability that makes tool-call chains impossible to reconstruct.
- No safe rollback of tool versions, prompts, or retrieval rules.
Your security posture improves quickly when you treat MCP as a distributed system with explicit trust boundaries, not as a clever integration layer.
Architectural baseline: separate control plane from data plane
A scalable MCP architecture benefits from a split:
- Control plane: policy, identity mapping, tool registry, versioning, approvals, and configuration distribution.
- Data plane: the runtime MCP servers and tool executors that handle user traffic and context processing.
This is a familiar pattern from API gateways and service meshes. The key is to avoid “policy scattered in code.” Instead, you want policy centrally defined and enforced at runtime through consistent hooks.
Minimal reference layout for MCP repositories
A common repo topology for MCP projects that want to scale across many tools looks like this:
mcp-server/- transport (stdio/http), auth middleware, request validation
- tool dispatcher and tool sandbox layer
tools/- tool implementations grouped by domain (
crm/,billing/,infra/) - tool capability declarations (schema, scopes, side effects)
- tool implementations grouped by domain (
policies/- access rules by tenant, role, environment, data classification
- allowlists/denylists for tool invocation
prompts/- system prompts, tool instructions, safety constraints
- versioned, code-reviewed, tested like code
infra/- IaC for deployment, secrets, network policy, logging, metrics
tests/- unit tests for tools
- contract tests for tool schema
- adversarial tests for injection and data leakage
That structure creates friction in the right places: tool definitions can’t slip into production without review, and policy isn’t buried inside implementation.
Identity first: authenticate the client, then bind tool calls to an actor
MCP often sits between a client (IDE, desktop agent, internal portal) and privileged systems (Git hosting, cloud consoles, ticketing systems). If you don’t bind calls to a real identity, you lose the ability to apply least privilege.
Recommended identity pattern
- Client authentication: The MCP client authenticates to your MCP server using OIDC (preferred), mTLS, or short-lived signed tokens.
- Actor binding: Every request is associated with:
- user identity (human) or workload identity (service)
- tenant/org boundary
- session id and correlation id
- Delegated authorization: Tool calls either:
- execute with a constrained delegated token for the user, or
- execute with a service token but with strict per-user authorization enforced server-side.
The first approach (delegation) is usually safer. The second can be necessary for legacy systems, but it demands rock-solid server-side checks and logging.
Don’t trust the model to do authorization
Authorization should be enforced in the MCP server’s tool dispatcher, not inside prompt text. Prompt rules are helpful, but they are not enforcement. You want a hard gate:
- Validate that the tool is allowed for the actor, tenant, and environment.
- Validate parameters (types, ranges, allowed enums).
- Require additional approval for high-risk side effects.
Tooling boundaries: define “capabilities,” not just functions
In MCP, “tools” are the sharp edges. They are where the model can cause side effects, read sensitive data, or trigger workflows. A scalable architecture treats each tool as a capability with:
- Scope: what it can access (systems, objects, fields)
- Side-effect level: read-only, write, destructive, financial, privileged admin
- Data classification: public, internal, confidential, regulated
- Rate and quota class: cheap, expensive, bursty, slow
- Approval mode: auto, user-confirm, two-person review, change window
A mature MCP repository codifies this in a machine-readable format alongside the tool schema. The schema alone is not enough—you need metadata to drive policy.
A practical tool risk taxonomy
- Tier 0 (safe): formatting, math, local parsing, no network
- Tier 1 (read-only): search, fetch non-sensitive docs, public APIs
- Tier 2 (sensitive read): internal tickets, customer info, code search in private repos
- Tier 3 (write): create tickets, open PRs, modify records
- Tier 4 (destructive/privileged): delete, disable, rotate credentials, production changes
Each tier maps to stronger controls: validation, confirmation, approvals, and runtime sandboxing.
Secure context handling: treat retrieval as an untrusted input channel
Retrieval-augmented flows can quietly become your largest attack surface. Documents might include instructions, embedded secrets, or content designed to cause tool misuse.
Context hygiene controls that scale
- Document provenance: store source, author, timestamp, and trust score in metadata.
- Index partitioning: isolate tenants and environments; never mix staging and prod.
- Content filtering:
- strip executable snippets when not needed
- redact obvious secrets before indexing
- ignore “instructional” sections from untrusted sources
- Context budgets: cap how much retrieved content can be included, and prefer summaries of trusted sources.
- Policy-based retrieval: retrieval results should be filtered by the same access model as tools.
A subtle but important pattern: make retrieval a tool with explicit authorization. “Search the knowledge base” is not neutral if the knowledge base includes confidential runbooks.
Secrets: remove them from repos, then remove them from tool memory
MCP repositories often get compromised the old-fashioned way: credentials in environment files, leaked tokens in CI logs, or hardcoded API keys “temporarily” left in code.
Baseline secrets posture for MCP repos
- Use a real secrets manager (Vault, AWS Secrets Manager, GCP Secret Manager, Azure Key Vault).
- Enforce short-lived credentials (OIDC to cloud, dynamic DB creds).
- Never allow tools to return secrets in plain text unless the actor is explicitly allowed and the event is audited.
- Configure logging to redact credentials and sensitive fields at ingestion.
A common mistake: a tool fetches a secret to call an API, and the model sees the secret in the tool output or in verbose logs. Tools should never return raw credentials; they should return status only.
Network and runtime isolation: assume every tool will be abused eventually
A scalable MCP runtime is usually containerized. That’s good, but only if you use the isolation you already pay for.
Runtime controls that matter
- Egress policy: tools should only reach known hosts; default-deny outbound traffic.
- Per-tool network policies: billing tools shouldn’t access infrastructure endpoints.
- Filesystem constraints: read-only root FS; explicit writable mounts.
- Sandboxing for high-risk tools: separate worker pools for Tier 3/4 tools.
- Resource limits: CPU/memory caps to prevent runaway execution.
The goal is to make misuse survivable. When a tool is coerced into doing something stupid, the blast radius should be small.
Policy engine: centralize authorization and safety gates
To scale, you need a policy layer that is:
- consistent (same rules everywhere),
- auditable (who changed what, when),
- testable (unit tests for policy),
- deployable (versioned, with rollbacks).
Many teams adopt a policy-as-code approach (e.g., OPA/Rego or Cedar). The exact engine matters less than these properties:
- Tools declare capabilities and required scopes.
- Requests come with actor identity and context (tenant, env, sensitivity).
- Policy decides: allow/deny/allow-with-conditions.
Conditional approvals and step-up controls
High-risk operations shouldn’t be blocked forever, but they should be gated:
- User confirmation: present a human-readable diff or action summary.
- Step-up auth: require re-authentication for destructive actions.
- Two-person rule: for production changes, require a second approver.
- Change windows: allow Tier 4 tools only during scheduled periods.
These controls are normal in infrastructure platforms; MCP just needs them in the tool dispatcher.
Testing MCP repositories like security-critical code
MCP repos shouldn’t rely on “it seems fine in the chat.” You want automated coverage for the failure modes you actually fear.
What to test (and how)
- Schema contract tests: tools enforce types and reject unexpected fields.
- Authorization tests: deny-by-default; verify least privilege by role.
- Injection tests: feed retrieved documents with adversarial content and verify the system refuses to elevate privilege.
- Redaction tests: ensure sensitive fields never appear in tool output or logs.
- Replay tests: record a session and verify deterministic tool call policy decisions.
A productive pattern is to keep a corpus of “bad documents” in the repo: snippets designed to manipulate tool use, ask for secrets, or override system behavior. The tests should assert that the tool dispatcher enforces policy regardless of the text.
Versioning and release discipline: scale by making change safe
MCP systems evolve quickly: new tools, new prompt instructions, new retrieval sources. Without release discipline, you get drift and silent regressions.
Version everything that can change behavior
- Tool schemas and capability metadata
- Policy bundles
- Prompt templates and system rules
- Retrieval configuration (indexes, filters, ranking settings)
- Safety thresholds and redaction patterns
You also want compatibility guarantees. If a client pins to v1 of a tool schema, the server should honor it or explicitly negotiate.
Promotion pipeline by environment
A secure scalable architecture promotes changes:
- dev (fast iteration, synthetic data)
- staging (real integrations, restricted scope)
- prod (strict policy, approvals, auditing)
Each stage should have different policy defaults and different tool allowlists. It’s normal for staging to allow more introspection while prod is locked down.
Observability: reconstruct the chain without logging secrets
MCP observability isn’t just latency and error rates. You need to answer:
- Who invoked which tool?
- With what parameters (redacted)?
- What data sources were retrieved?
- What policy decision was applied?
- What side effects occurred in external systems?
This requires structured event logs with consistent IDs.
Minimum viable telemetry set
- Request id, session id, actor id, tenant id
- Tool name, tool version, capability tier
- Policy decision (allow/deny/conditions)
- Parameter hashes or redacted parameter map
- External call metadata (host, endpoint class, duration, status)
- Retrieval sources and document IDs (not raw content)
A surprising benefit: good telemetry makes cost management much easier. You can see which tools cause expensive model calls, which tenants drive load, and where caching is safe.
Photo by Microsoft Copilot on Unsplash
Scaling strategies: when one MCP server becomes many
A single MCP server can be fine for small internal tools, but scale introduces new constraints: concurrency, noisy neighbors, per-tenant quotas, and operational ownership.
Horizontal scaling without losing governance
To scale MCP runtimes, prefer stateless servers:
- Store session state in a shared store if needed (but keep it minimal).
- Put policies and tool registries in a distributed config store.
- Use a queue for long-running or high-risk tasks.
Then apply workload separation:
- Frontline MCP gateway: auth, routing, policy checks, request shaping
- Tool execution pools: segregated by risk tier
- Retrieval services: isolated, tenant-partitioned, with strict ACLs
This allows you to scale the hot path (gateway) differently than the slow path (execution). It also enables tighter security for Tier 3/4 tools without punishing Tier 1 calls.
Rate limiting and quotas as first-class controls
Denial-of-wallet is real in MCP. You need:
- Per-tenant request rate limits
- Per-user tool call quotas
- Per-tool concurrency limits
- Budget alarms and circuit breakers
Quotas should be enforced before expensive model calls when possible. For example, reject a high-risk tool call early rather than generating a long plan first.
Data governance: classification, residency, and retention
MCP often touches sensitive data indirectly: retrieved docs, ticket attachments, internal code, customer records. Governance isn’t optional, especially at scale.
Apply classification end to end
- Tag sources and documents with classification.
- Tag tools with what they can access and what they can output.
- Enforce “no downgrade”: confidential inputs shouldn’t lead to public outputs without an explicit policy exception.
Retention rules for MCP logs and traces
Logs can become a shadow data store. Define retention per environment and per data class:
- Keep minimal operational logs for shortest necessary period.
- Store sensitive traces only when needed, with restricted access.
- Support “delete my data” workflows where applicable.
This requires discipline in repositories too: don’t store conversation transcripts as test fixtures if they contain real data.
Supply chain security for MCP repositories
MCP repos are attractive targets because they sit near credentials, integrations, and automation. A supply chain compromise can quietly turn tools into backdoors.
Practical repo hardening measures
- Enforce signed commits for critical branches.
- Require code owner reviews for:
- tool capability metadata
- policy bundles
- auth and logging middleware
- Pin dependencies and use lockfiles.
- Run SAST and dependency scanning on every PR.
- Build containers from minimal base images; scan images in CI.
- Keep build provenance (SLSA-style metadata) if your org supports it.
Treat tool definitions like infrastructure changes. A one-line schema update can widen access more than a hundred lines of code.
Product components that commonly appear in secure MCP stacks
Different teams assemble MCP architectures from a set of building blocks. Here are common components, described by their role rather than marketing promises.
-
Policy engine (OPA/Cedar)
Centralized allow/deny decisions based on actor identity, tool tier, tenant, and environment; versioned and testable policies. -
Secrets manager (Vault/Cloud secrets)
Short-lived credentials, audit logs for secret access, and automatic rotation; reduces credential sprawl in MCP repositories. -
API gateway/service mesh
mTLS, request shaping, rate limits, and consistent telemetry across MCP servers and tool execution pools. -
Vector database with tenant partitioning
Retrieval with strict access boundaries, metadata filters, and retention controls; critical for preventing cross-tenant leakage. -
SIEM + structured logging pipeline
Central event correlation for tool calls, policy decisions, and external side effects—without storing raw sensitive context. -
Container runtime sandboxing (gVisor/Kata)
Stronger isolation for high-risk tools; reduces blast radius when a tool is coerced into harmful actions.
Operational playbooks: incident response for tool-driven systems
When something goes wrong in MCP, it often looks like “the assistant did a thing.” A scalable architecture makes that “thing” traceable and reversible.
What you need ready before the incident
- A kill switch to disable a tool globally or per tenant.
- A way to roll back tool versions and policy bundles quickly.
- An audit trail that ties tool calls to actors and sessions.
- A quarantine mode for retrieval sources (stop indexing, stop serving).
- Backpressure and circuit breakers to stop cascades.
Typical incident flows
- Suspected exfiltration: disable sensitive read tools (Tier 2), increase redaction, rotate compromised credentials, check logs for abnormal retrieval patterns.
- Unauthorized writes: disable Tier 3/4 pools, enable mandatory confirmations, verify policy bundles and tool schemas weren’t modified.
- Supply chain alert: freeze deployments, verify build provenance, lock dependency updates, and rebuild from known-good commits.
The difference between a bad day and a crisis is often whether you can disable a tool in seconds without redeploying the world.
Designing for human control without breaking developer velocity
The temptation in MCP is to either lock everything down (and kill usefulness) or allow everything (and accept chaos). The sustainable middle is graduated control.
A workable governance model
- Developers can add Tier 0/1 tools with standard review.
- Tier 2 tools require security review and explicit scope declarations.
- Tier 3/4 tools require:
- approval workflow
- runtime isolation
- mandatory observability fields
- on-call ownership
This model scales because it matches controls to risk. It also creates a clear path: prototype as Tier 1, then promote with additional safeguards.
Make “safe” the default in templates
If you provide internal MCP repo templates, bake in:
- deny-by-default policies
- structured logging with redaction
- input validation helpers
- capability metadata scaffolding
- test harnesses for injection and authorization
Teams move faster when the secure path is also the easiest path.
The architecture that holds up under pressure
A secure and scalable MCP architecture is not a single pattern, but it has recurring traits:
- identity-bound requests and delegated authorization
- tools treated as capabilities with tiered risk controls
- policy centralized, versioned, and enforced in the dispatcher
- retrieval treated as untrusted input with provenance and partitioning
- secrets handled with short-lived credentials and strict redaction
- runtime isolation, network egress controls, and resource limits
- observability designed for reconstruction without data leakage
- supply chain controls applied to tool definitions and policy as seriously as code
When you build MCP this way, the system remains understandable even as repositories multiply, tools proliferate, and traffic grows. That’s the real test of scale: not just handling more requests, but staying governable when the context, the code, and the organization all change at once.
External Links
Build Secure and Scalable MCP Servers | Blogpost How to build secure and scalable remote MCP servers Scaling MCP adoption: Our reference architecture for simpler, safer and cheaper enterprise deployments of MCP Scaling MCP: A simpler, safer enterprise architecture - Cloudflare TV How to Design Secure MCP Deployments - Curity at Platform Summit 2025 | Videos