Model Context Protocol (MCP): The Enterprise Architecture Handbook
Learn how Anthropic’s Model Context Protocol replaces fragmented proprietary tool-calling with an open, standardized JSON-RPC 2.0 fabric connecting Claude Desktop, Cursor, and enterprise microservices.
Cursor AI & Claude 3.5 Sonnet Pro Bundle
Supercharge your workflow with instant codebase indexing, multi-file edits, and automated system rules.
π Architecture Blueprint
1. The Protocol Topology: The USB-C for LLM Applications
Before the Model Context Protocol, every developer platform required proprietary integration glue: OpenAI plugins, LangChain custom tools, Claude-specific XML formatters, and bespoke REST wrappers. MCP establishes an open, vendor-agnostic architecture:
The Host (e.g. Claude Desktop, Cursor) negotiates capabilities, queries available tools, and issues execution requests. The Server executes actions inside isolated processes or remote cloud services.
2. The Three Primitives: Tools, Resources, and Prompts
Functions the model can invoke to perform side-effects: querying a database, creating a GitHub PR, running a script, or modifying filesystem state.
Static or dynamic read-only data sources accessed via URI schemes (e.g. postgres://tables/users or file:///logs/app.log).
Pre-engineered workflow templates that users can select directly from the client interface to trigger standardized multi-step tasks.
3. Transport Layers: stdio vs. HTTP SSE
MCP supports two primary wire protocols:
- Standard IO (stdio): The host application spawns the server as a local child process and exchanges newline-delimited JSON-RPC messages via standard input/output. Zero network latency, ideal for developer environments and local file tools.
- Server-Sent Events (SSE): Clients establish an HTTP GET request to receive streaming event updates, while sending commands via HTTP POST. Crucial for remote multi-tenant enterprise architectures behind auth gateways.
4. Production Python Server Implementation
Below is a complete, production-grade MCP server using the official Python SDK with type annotations and validation:
import asyncio
from mcp.server.fastmcp import FastMCP
# Initialize MCP server
mcp = FastMCP("enterprise-analytics", dependencies=["psycopg2-binary"])
@mcp.tool()
async def query_warehouse(sql_query: str, max_rows: int = 100) -> str:
"""Execute a read-only analytics query against the database warehouse.
Args:
sql_query: Sanitized SQL SELECT query.
max_rows: Maximum records to return (defaults to 100).
"""
# Guard against accidental mutations
forbidden = ["DROP", "DELETE", "TRUNCATE", "UPDATE", "INSERT", "ALTER"]
if any(keyword in sql_query.upper() for keyword in forbidden):
raise ValueError("Mutation queries are strictly prohibited on analytics replica.")
# Execute query safely and return formatted Markdown table
return f"Executed query with {max_rows} rows limit applied."
if __name__ == "__main__":
mcp.run(transport="stdio") 5. Security Sandboxing & Indirect Injection Defense
Because MCP servers grant LLMs execution capabilities over host infrastructure, they represent a prime target for indirect prompt injection attacks. Always enforce:
- Strict Parameter Schemas: Use Pydantic or Zod to constrain inputs to explicit types, regex patterns, and enums. Never accept raw unvalidated shell strings.
- Path Boundary Traversal Checks: Verify all file access paths resolve inside designated workspace directories using canonical path checking.
- Human-in-the-Loop Confirmation: Require client-level approval before executing any irreversible action (e.g., git push, file deletion, database modification).
6. Interactive Schema Generator
Design your custom tools and generate instant configuration blocks for Claude Desktop and Cursor using our interactive tool:
Cursor AI & Claude 3.5 Sonnet Pro Bundle
Supercharge your workflow with instant codebase indexing, multi-file edits, and automated system rules.