|
|
MCP Server mTLS Authentication
Author: Venkata Sudhakar
Mutual TLS (mTLS) is the strongest transport-level authentication for MCP servers. Unlike one-way TLS where only the server proves its identity, mTLS requires both the server and the client to present valid certificates. This ensures that only authorised agents - those holding a certificate signed by a trusted CA - can call MCP tools.
ShopMax India uses mTLS for its internal MCP servers that handle sensitive operations like pricing updates and order approvals. Each ADK agent is provisioned with its own client certificate issued by the internal CA. The MCP server rejects any connection that cannot present a valid certificate, preventing unauthorised access even from within the private network.
The below example shows how to run an MCP server over HTTP with SSE transport secured by mTLS, using Python's ssl module to enforce mutual certificate verification.
It gives the following output,
# Server starts with mTLS enforced
MCP server running on https://0.0.0.0:8443 with mTLS
# Authorised agent connects with valid cert:
Client cert CN: shopmax-pricing-agent
Tool: approve_price_change({product_id: "TV-201", new_price_rs: 59000, approver: "pricing-agent"})
Price change approved: product=TV-201 new_price=Rs 59000.0 by pricing-agent
# Unauthorised client without cert:
ssl.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed - connection rejected
Use Google Cloud Certificate Authority Service to issue and rotate client certificates for agents at scale. Store private keys in Secret Manager and mount them at runtime rather than baking them into container images. Set short certificate lifetimes (24-48 hours) and automate rotation so a compromised key has minimal exposure window. For Cloud Run deployments, combine mTLS at the application layer with VPC Service Controls at the network layer for defence in depth.
|
|