« All posts

Securing MCP Servers: Four Gates From Code to Production

A leaked .env file exposed a design flaw in an MCP server. Here's a four-gate, OWASP-aligned defense strategy engineers can adopt today.

During a demo, a Model Context Protocol (MCP) support assistant was tricked by a single line of text disguised as a customer ticket into walking up the directory tree and printing the contents of a .env file. Nothing crashed, no exception fired, no CVE applied — every function executed exactly as instructed. The vulnerability was architectural, not a bug.

This wasn't an isolated incident. Many MCP servers in production today are AI-authored in an afternoon, wired into agents holding real credentials for GitHub, Jira, payment APIs, and production databases, then merged with minimal review. OWASP's Top 10 for LLM Applications ranks prompt injection (LLM01) first, alongside sensitive information disclosure and unbounded consumption, while the newer OWASP MCP Top 10 catalogs MCP-specific risks like tool poisoning, token leakage, and supply-chain tampering. A documented attack on GitHub's official MCP server by Invariant Labs confirms this is a live threat, not a theoretical one.

The response outlined here isn't a single fix but four independent gates spanning the lifecycle: a code-integrity check on pull-request diffs that catches hallucinated dependencies and stubbed logic before merge, catalog scanning, adversarial CI tests, and runtime enforcement that blocks malicious tool calls in production. Each gate closes a blind spot the others miss, and the approach is implemented with open-source tools — AIV Integrity Gate, MCP Test Harness, and MCP-Bastion — that can be adopted individually.

This synthesis was produced from its source by AI; there is no human editor or manual review step. How we work