AI Engineer Europe 2026

Your Insecure MCP Server Won't Survive Production — Tun Shwe, Lenses

Loading slides…

Read the talk

Your Insecure MCP Server Won't Survive Production

A secure MCP service starts with the tools and data an agent can see, then carries those boundaries through remote transport, OAuth, upstream delegation and operational tracing.

From a talk by Tun Shwe and Jeremy Frenay

Before you start: Familiarity with HTTP requests, API keys and MCP tools will help; the OAuth discovery, PKCE and token-exchange flows are explained step by step.

What should an agent be allowed to see?

What changes when an API’s caller is an agent that reads tool descriptions, chooses operations and carries the results into its next decision? The interface now influences both what the caller can do and what it believes it should do. Tun Shwe and Jeremy Frenay approach that problem from their AI engineering work at Lenses, a streaming-data layer around Apache Kafka that supplies agents with real-time context. Their open-source MCP server brings that work into an interface where governance and security matter alongside access to data.

FastMCP creator Jeremiah Lowin’s product-engineering framing supplies the starting point: agents need interfaces designed for their use cases. Shwe extends it into a security principle: poor interface design and poor security compound each other. Discovery, iteration and context—the ways an agent learns about and uses an interface—each introduce a corresponding security exposure.

Slide states that agents deserve a purpose-built interface, not a REST API in a magical trenchcoat, and that a badly designed MCP server is also badly secured.Open full source frame
Agents need a purpose-built interface; poor MCP design also weakens security.
0:080:17
Suggest correction

This note stays in this page until you copy or download it. Nothing is submitted; reloading clears the draft.

0:08 · section reference included

Discovery, iteration and context

Discovery starts differently for a human and an agent. A developer can scan API documentation, select three endpoints and work with that subset. In Shwe’s example, the agent enumerates the server’s tools and reads their descriptions whenever it connects. That consumes tokens, but it also exposes the model to more potentially hostile text. Tool poisoning places malicious instructions inside descriptions, including text a client’s interface may not display. More exposed tools create more opportunities for injection.

Iteration can repeatedly move sensitive information across a boundary. A failed script may simply run again; an agent retry can send the conversation history back to the model, including sensitive results from earlier tool calls. The exposure therefore depends on more than the current request: data returned several steps ago can travel with later attempts. Full-history retries are the interaction pattern under discussion, not a requirement imposed by MCP.

Context is both a working resource and a place where sensitive data can accumulate. Shwe uses roughly 200,000 tokens as his context-window example, not as a limit shared by all agents. The OWASP MCP Top 10 identifies context injection and oversharing as item 10. Returning unfiltered PII, credentials and internal system details puts those values into a context that an attacker may try to manipulate into exfiltrating them. Loading all that material also adds latency and consumes space needed for the task.

Finding the answer becomes a needle-in-a-haystack problem, except that some of the hay may contain hostile instructions. The practical response is curation: choose the tools the agent needs and expose the smallest useful amount of information. Reducing unnecessary context reduces both the work of finding an answer and the material available to an attacker.

2:242:34
Suggest correction

This note stays in this page until you copy or download it. Nothing is submitted; reloading clears the draft.

2:24 · section reference included

Design for an outcome, then constrain its inputs

The first two of Shwe’s five design rules concern the operations an agent can request. OAuth can authenticate a caller and authorize access, but it cannot repair an interface that exposes unnecessary capabilities or accepts dangerous inputs. Those boundaries need to exist before authentication code is added.

First, expose a defined outcome. An agent checking an order should not also receive a tool for deleting users. Consolidate the related underlying API calls behind one operation that answers the order question, keeping the orchestration inside the server. That creates one place to authorize the requested outcome and record its execution, instead of asking the agent to navigate a collection of fine-grained operations. Fewer exposed operations mean fewer permission boundaries to manage.

Slide titled “1. Design for the Desired Outcome” says every exposed tool is a door and recommends burying orchestration in one tool with a clear outcome.Open full source frame
Design tools around a clear outcome, keeping orchestration inside one tool.

Second, constrain inputs at the schema boundary. Prefer top-level primitives, enums and flat dictionaries over arbitrary nested payloads. Shwe suggests Pydantic for stronger typing. The goal is to prevent unconstrained strings and structures from flowing into shells, query engines or downstream APIs. For the order-checking example, a Python request model can restrict both the identifier’s form and the requested view:

python

from typing import Literal

from pydantic import BaseModel, ConfigDict, Field


class CheckOrderInput(BaseModel):
    model_config = ConfigDict(extra="forbid", strict=True)

    order_id: str = Field(pattern=r"^ORD-[0-9]{6}$")
    view: Literal["status", "delivery"] = "status"


request = CheckOrderInput.model_validate(
    {"order_id": "ORD-000123", "view": "status"}
)

This Pydantic v2 example gives the caller a small vocabulary instead of a generic command field. Validation narrows the accepted request; downstream operations still need safe query construction and authorization for the particular order.

4:434:54
Suggest correction

This note stays in this page until you copy or download it. Nothing is submitted; reloading clears the draft.

4:43 · section reference included

Make descriptions precise, responses small and permissions narrow

Third, treat documentation as part of the defensive design. OWASP lists tool poisoning as item 3. An attacker-controlled description on a neighboring MCP server may attempt to influence how the agent uses your tools, especially where your own instructions leave room for interpretation. Shwe argues for complete, unambiguous descriptions that state each tool’s purpose and expected use. Clear documentation reduces ambiguity; it is not an enforcement boundary or a guarantee against poisoning.

Fourth, return only what the immediate task needs. An order-status answer need not include the customer’s full record. PII, internal identifiers, credentials and system details all become potential exfiltration targets once returned to the agent. Filter the response before it enters the context window, rather than relying on the model to ignore fields it should never have received.

Fifth, minimize the blast radius. Enforce permissions at the individual tool and resource level, rather than granting broad access for an entire session. A non-destructive tool can advertise readOnlyHint, but the MCP schema treats annotations as hints, not authorization mechanisms; clients must not trust annotations from untrusted servers as a basis for tool-use decisions. Read-only access must be enforced by the server and its upstream credentials.

Where the operation is fundamentally about exposing readable data, consider an MCP resource instead of a tool. Removing an unnecessary tool removes an avenue for misuse. The larger design responsibility is to supply a trustworthy interface to a caller that may confidently use whatever capabilities and information it receives.

6:266:41
Suggest correction

This note stays in this page until you copy or download it. Nothing is submitted; reloading clears the draft.

6:26 · section reference included

Crossing the deployment security cliff

Once the interface is designed, deployment changes the trust boundary. In the local standard-I/O setup, the MCP host talks directly to a process on the developer’s machine. There is no listening network endpoint between that host and server, and no separate network authentication exchange is needed on that link. That makes the setup convenient for a single developer, although local processes, credentials and dependencies still carry security risks.

Streamable HTTP makes the MCP server a shared service. Multiple clients can connect remotely, deployments can scale horizontally, and governance can be centralized. The MCP interface also gives clients a consistent entry point while the service manages underlying API versions and capacity.

ConcernLocal standard I/ORemote Streamable HTTP
ConnectionHost to local processClient to network service
Typical useOne developerTeams and agent fleets
Service managementLocal process lifecycleShared scaling and governance
Added exposureLocal execution and secretsNetwork access and multiple callers

The remote service needs OAuth, token lifecycle management, TLS, appropriate CORS configuration and rate limiting together. This abrupt expansion of responsibilities is Shwe’s security cliff.

Shwe cites a Stacklok transport benchmark as a reason to examine the scaling path carefully. In Stacklok’s ToolHive standard-I/O container-attachment test, 20 of 22 actual requests failed at 20 simultaneous connections. The workload used a yardstick echo server on local kind Kubernetes with port forwarding, offering 10 requests per second for five seconds: 50 requests were expected, but only 22 were recorded and two succeeded. That result describes the tested transport and attachment configuration, not an inherent concurrency ceiling for every local standard-I/O server.

8:118:21
Suggest correction

This note stays in this page until you copy or download it. Nothing is submitted; reloading clears the draft.

8:11 · section reference included

What API-key plumbing leaves unresolved

Frenay begins the authorization walkthrough with the implementation burden: he counts more than ten specifications across core OAuth flows, client discovery and metadata, and token lifecycle management. Before following that machinery, it helps to trace the credentials in the simpler setups it replaces.

In the local example, the user provisions an API key and puts it in the MCP client configuration. The client supplies it to the local server through an environment variable, and the server uses it when requesting the external service. The user must store, maintain and rotate that credential. In the depicted setup, the key is long-lived, rarely rotated, not scoped to the client’s specific actions and sometimes shared across systems. The MCP server does not verify it before using it upstream.

Moving the same arrangement to HTTP changes where the key travels, not its lifecycle:

  1. Generate the key and store it in the client configuration.
  2. Attach it to the HTTP Authorization header on a runtime request.
  3. Let the MCP server optionally validate it, then pass it to the upstream API for verification.
  4. Receive the illustrated 200 or 401 response; a failed credential requires manual replacement in this setup.

The credential remains long-lived and lacks action-specific scope even though the server is now remote.

Two upstream arrangements introduce different problems:

  • Pass the incoming credential through. Frenay connects this to access without proper user consent. More precisely, the MCP Security Best Practices prohibit token passthrough that accepts and forwards tokens without validating that they were issued for the MCP server. The guidance’s specific confused-deputy scenario also involves upstream client identity, dynamic registration and consent handling; passthrough and that attack are related but not interchangeable terms.
  • Map callers to a shared upstream credential. A single powerful key then serves many users. Revoking one user’s upstream access becomes harder, and a leak can compromise everyone using the shared credential.

Frenay estimates that long-lived, unscoped credential setups represent more than 50% of MCP servers, without supplying a survey or population definition. The architectural direction he describes is toward short-lived, scoped tokens through OAuth 2.1.

10:1010:20
Suggest correction

This note stays in this page until you copy or download it. Nothing is submitted; reloading clears the draft.

10:10 · section reference included

Discovering a server and registering a client

Short-lived tokens can be combined with token exchange to narrow upstream access, but first the authorization server needs to recognize the client. Traditional OAuth registration assumes a known collection of applications: a developer visits a portal, registers an app and receives a client ID. That is manageable for a handful of integrations. MCP permits Claude Desktop, Cursor, VS Code, CLI tools and arbitrary agents to discover servers at runtime. Manually registering every possible client-server pair does not fit that open-ended arrangement.

Dynamic Client Registration, or DCR, lets the client register itself with the authorization server protecting a remote MCP service. In Frenay’s walkthrough, each registration receives a new client ID. It removes the prerequisite that a user or developer manually create client credentials before connecting.

Dynamic Client Registration slide lists remote hosting, authorization-server protection, client self-registration, and a new ID each time, alongside a short HTTP server configuration.Open full source frame
Dynamic client registration lets the client self-register with the authorization server.

The Cursor example begins without a token and discovers what it needs from the server:

  1. Request /mcp. The MCP server returns 401 because the request lacks an access token.
  2. Follow the challenge. The WWW-Authenticate header points the client toward protected-resource metadata.
  3. Discover the authorization server. The resource document identifies the protected resource and its authorization server. Cursor then retrieves that authorization server’s metadata.
  4. Register the client. Cursor sends POST /register. The illustrated authorization server generates a client ID, persists it on disk and returns it.

The client now has a registration identifier. User authentication and permission to access the resource still come next.

13:4714:00
Suggest correction

This note stays in this page until you copy or download it. Nothing is submitted; reloading clears the draft.

13:47 · section reference included

From user consent to an upstream API call

The authorization-code flow uses PKCE, Proof Key for Code Exchange, as required by the MCP authorization specification. The client generates a secret code verifier and derives a challenge from it. The /authorize request carries the challenge; the verifier stays with the client until token exchange. The core S256 calculation in Python is:

python

import base64
import hashlib
import secrets

verifier = secrets.token_urlsafe(32)
challenge = base64.urlsafe_b64encode(
    hashlib.sha256(verifier.encode("ascii")).digest()
).rstrip(b"=").decode("ascii")

pkce_authorization_parameters = {
    "code_challenge": challenge,
    "code_challenge_method": "S256",
}

The challenge binds the later redemption of the authorization code to possession of the verifier.

Without an existing user session, the authorization server redirects the user to an identity provider for single sign-on. After login, the user sees a consent screen and can grant scopes to the client. The resulting authorization code is then sent to /token together with the original verifier. The authorization server validates the code and checks the verifier against the earlier challenge before issuing an access token. Frenay’s example uses a JWT; JWT is the token format chosen for this architecture.

The client can now invoke a tool with the access token in Authorization: Bearer <access_token>. The MCP server validates the token and checks its scopes before performing the operation. Validation must establish that the token is intended for this MCP server, not merely that some authorization server signed it.

The illustrated architecture then separates MCP access from upstream API access. The MCP server becomes an OAuth client for the upstream resource server and asks the same authorization server to exchange the incoming token for an appropriate upstream token under RFC 8693. Frenay calls these the delegation token and session token. The MCP server puts the exchanged session token in the upstream request’s Authorization header.

Request boundaryCredential in the walkthroughReceiver
Client → MCP serverDelegation/access tokenMCP server
MCP server → authorization serverToken-exchange requestAuthorization server
MCP server → upstream APIExchanged session tokenUpstream resource server

These token names describe the walkthrough, not universal RFC terminology. This is also an architectural flow rather than a claim about the current Lenses repository implementation: its README describes introspection and forwarding, rather than establishing this exchange path.

16:2016:33
Suggest correction

This note stays in this page until you copy or download it. Nothing is submitted; reloading clears the draft.

16:20 · section reference included

Replacing self-asserted registration with a metadata URL

DCR removes manual registration, but it leaves both administrative and identity problems. In the example, using Claude on Windows and then macOS creates distinct registrations rather than one portable client identity. An open /register endpoint also accepts attacker submissions. If the authorization server trusts self-asserted metadata, a malicious client can claim to be Claude; possession of a registration ID does not establish that claim. That creates opportunities for misleading consent screens and phishing.

Client ID Metadata Documents, or CIMD, change where client metadata comes from. The client owner publishes a document at a public URL, and that URL serves as the client ID. During authorization, the authorization server can retrieve the document rather than accept a fresh identity claim through a registration request.

Client ID Metadata Document slide describes a remote MCP server, authorization-server protection, a publicly exposed client ID, and fetching that ID during authorization, beside an HTTP server configuration.Open full source frame
Client ID Metadata Document: the client owner exposes the client ID at a public URL.

The beginning of the flow remains familiar, but the separate registration step disappears:

  1. Discover the protected service. An unauthenticated request receives 401 and a resource-metadata location. The client discovers the MCP resource and authorization server.
  2. Proceed directly to authorization. There is no instruction to send POST /register. The client generates its PKCE verifier and challenge, then calls /authorize with its URL-valued client ID.
  3. Fetch the client metadata. The authorization server retrieves the document and uses its URL as the unique client identity.
  4. Authenticate and obtain consent. The identity provider handles user login, the authorization server presents the requested scopes, and the token issuance and upstream exchange flow follow.

CIMD changes client identification; it does not remove user login, consent or token validation.

This avoids continually accumulating independent registration identities and gives policy a more stable reference. Controlling the published metadata under claude.ai, for example, is more meaningful than merely submitting a registration request that claims that name. The document binds allowed redirect URIs to the client, making callback substitution harder, and the authorization server can explicitly allow or deny client identities. Domain-controlled metadata still does not authenticate every running client instance: metadata fetching needs SSRF defenses, and localhost callback impersonation remains a concern.

Frenay describes CIMD as the preferred approach since November 2025. The versioned specification expresses that preference precisely: implementations SHOULD support CIMD and MAY support DCR. CIMD is therefore preferred in that specification, not mandatory. DCR remains a useful step beyond manual credential setup, with different identity and administration tradeoffs.

18:5519:07
Suggest correction

This note stays in this page until you copy or download it. Nothing is submitted; reloading clears the draft.

18:55 · section reference included

Govern the operation after authorization

Successful OAuth authorization is not the end of the permission check. Frenay calls for role-based access control at the individual tool and resource level. A scope granted to a session must translate into a decision about the particular operation and data being requested. For the order-checking interface, that means deciding whether this caller may read this order, not merely whether the caller has an authenticated session.

The response needs its own boundary. Email addresses, phone numbers and national insurance numbers may need masking before the agent sees them. If a field is unnecessary, omit it; if the task needs a restricted representation, mask it before returning the result. The model should not become the mechanism responsible for concealing information it was never authorized to handle.

Audit records must make individual interactions explainable: which agent called which tool, with which parameters, and what data was returned. Frenay invokes the EU AI Act as a motivation for this transparency, rather than establishing a blanket legal requirement to retain every raw parameter and payload. The audit design must support accountability without undoing the data-protection boundaries applied to tool responses.

Finally, trace the whole request: client call, validation, tool execution, data retrieval and generated response. An isolated tool log cannot show where authorization was applied, where sensitive fields were removed or how an upstream result became the answer. Distributed-system observability provides the foundation, extended to the decisions and actions taken by agents. Governing an agent requires being able to reconstruct what it did end to end.

22:4023:03
Suggest correction

This note stays in this page until you copy or download it. Nothing is submitted; reloading clears the draft.

22:40 · section reference included

Resources

From the talk

  • Attack scenarios and mitigations for token passthrough, confused deputies, SSRF and local MCP compromise.

Transcript download
Full transcript

Loading transcript…