What Is the Model Context Protocol (MCP)? A Complete Guide to Phase 13 of the AI Engineering Curriculum

The Model Context Protocol (MCP) is an open-source, provider-agnostic standard that lets large language models discover, invoke, and exchange data with external tools via a JSON-RPC 2.0 client-server contract.

The Model Context Protocol (MCP) has emerged as the industry standard for connecting AI agents to external tools and resources. In the rohitg00/ai-engineering-from-scratch repository, Phase 13 (also labeled "Tools & Protocols") provides a comprehensive, hands-on curriculum for mastering MCP from fundamental concepts to production deployment. This phase teaches you to build secure, discoverable MCP servers and clients using the official Python SDK and FastMCP framework.

Understanding the Model Context Protocol (MCP) Standard

MCP is an open-source protocol first shipped by Anthropic in November 2024 and now stewarded by the Linux Foundation’s Agentic AI Foundation. It defines a client-server contract where an agent (client) queries a tool server for capabilities, then invokes tools via a standardized wire format.

Core Architecture and Primitives

The protocol defines six primitives (three server-side, three client-side) according to the 2025-11-25 specification. These include listTools, callTool, and streamResult, alongside authentication, discovery, and error handling mechanisms. Servers expose capabilities through a .well-known/mcp-capabilities manifest, enabling a central registry to index available MCP servers for platform-wide discovery.

Transport and Security Model

MCP defaults to StreamableHTTP, a stateless HTTP endpoint that streams JSON-RPC 2.0 responses, replacing earlier stdio-SSE transports. Security is enforced through OAuth 2.1 scopes with optional Open Policy Agent (OPA) policy gating. For example, destructive tools require approved:by:human scopes, while read-only operations may only need read permissions.

How Phase 13 Teaches MCP Implementation

Phase 13 of the curriculum progresses through seven interconnected lessons that move from theory to production deployment. According to the source files in phases/13-tools-and-protocols/, learners implement real clients and servers rather than just reading documentation.

Lesson 06: MCP Fundamentals

The curriculum begins with phases/13-tools-and-protocols/06-mcp-fundamentals/docs/en.md, which provides a concise historical overview of MCP, lists the six core primitives, and links to the official 2025-11-25 specification. This lesson establishes the theoretical foundation before writing any code.

Lesson 09: MCP Transports

In phases/13-tools-and-protocols/09-mcp-transports/docs/en.md, learners explore the evolution to StreamableHTTP transport. The lesson demonstrates how to issue a listTools request over HTTP and handle streaming responses, covering the wire protocol mechanics that underpin all MCP communication.

Lesson 08: Building an MCP Client

phases/13-tools-and-protocols/08-building-an-mcp-client/docs/en.md walks through constructing a production-ready client using the Python SDK (or TypeScript SDK). The lesson covers deserializing tool manifests, handling streaming responses, and enforcing OAuth 2.1 scope validation before executing remote tools.

Lesson 07: Building an MCP Server

The server-side implementation is taught in phases/13-tools-and-protocols/07-building-an-mcp-server/docs/en.md using the FastMCP framework. Learners expose tools such as a Postgres read-only API or an S3 list tool, wire JSON-RPC endpoints, and integrate OPA policy checks to enforce authorization at the tool level.

Lessons 15 and 16: Security and Governance

Security receives dedicated coverage across two lessons. phases/13-tools-and-protocols/16-mcp-security-oauth-2-1/docs/en.md details OAuth 2.1 scope design and implementation, while the tool-poisoning lesson explores threat models and mitigations against malicious tool definitions. Together, these lessons teach enterprise-grade authorization patterns.

Lesson 17: Registries and Gateways

phases/13-tools-and-protocols/17-mcp-gateways-and-registries/docs/en.md introduces the registry pattern—a separate service that polls MCP servers for capability manifests and presents a discovery UI. This enables platform teams to manage and enable MCP servers across an organization.

Lesson 13: Production Capstone

The phase culminates in phases/13-tools-and-protocols/13-mcp-server-with-registry/docs/en.md, where learners assemble a production-grade MCP server behind a load balancer. This capstone integrates OAuth 2.1 scopes, OPA gating, and a registry for enterprise-wide discovery, representing the full "learn-by-doing" approach of the curriculum.

Practical MCP Implementation Examples

The repository includes working code examples that demonstrate the client-server contract in action.

Listing Tools with a Python Client

This minimal client from phases/13-tools-and-protocols/08-building-an-mcp-client/docs/en.md demonstrates how to query a server for available tools using JSON-RPC 2.0 over HTTP:

import json, requests

def list_tools(endpoint: str, token: str):
    payload = {
        "jsonrpc": "2.0",
        "method": "listTools",
        "params": {},
        "id": 1
    }
    headers = {"Authorization": f"Bearer {token}"}
    resp = requests.post(endpoint, json=payload, headers=headers, stream=True)
    for line in resp.iter_lines():
        if line:
            print(json.loads(line))

Building a FastMCP Server

The following server implementation from phases/13-tools-and-protocols/07-building-an-mcp-server/code/main.py exposes a read-only Postgres tool using the FastMCP framework:

from fastmcp import MCPServer, Tool

def query_postgres(sql: str) -> str:
    # (implementation omitted for brevity)

    return "result rows …"

server = MCPServer(transport="streamable_http", auth="oauth2")
server.register_tool(
    Tool(name="postgres_query",
         description="Read‑only SQL query against a PostgreSQL DB",
         parameters={"type": "object",
                     "properties": {"sql": {"type": "string"}}},
         fn=query_postgres,
         scopes=["postgres:read"])
)
server.start()

Enforcing Security with OPA Policies

To prevent unauthorized destructive operations, phases/13-tools-and-protocols/16-mcp-security-oauth-2-1/code/main.py includes OPA (Open Policy Agent) policies that gate tool access based on OAuth scopes:

package mcp.authorization

allow {
    input.scope == "approved:by:human"
}
allow {
    not destructive_tool
    input.scope == "read"
}
destructive_tool {
    input.tool in {"jira_create", "linear_create", "postgres_write"}
}

Summary

  • Model Context Protocol (MCP) is an open-standard JSON-RPC 2.0 protocol for LLM-to-tool communication, now maintained by the Linux Foundation.
  • Phase 13 of the rohitg00/ai-engineering-from-scratch curriculum provides a complete learning path from fundamental concepts to production deployment.
  • Learners implement FastMCP servers and Python SDK clients with real authentication, authorization, and transport handling.
  • The curriculum covers StreamableHTTP transport, OAuth 2.1 security, and OPA policy gating for enterprise use cases.
  • A registry pattern enables organization-wide discovery of MCP servers through capability manifests.

Frequently Asked Questions

What makes MCP different from traditional REST API integration?

MCP provides a standardized discovery mechanism and client-server contract specifically designed for AI agents. Unlike ad-hoc REST integrations, MCP servers expose a .well-known/mcp-capabilities manifest that allows clients to dynamically discover available tools, their schemas, and required authentication scopes. This eliminates the need for hard-coded API endpoints and enables the ecosystem of tools used by Claude Desktop, ChatGPT, and Cursor.

How does MCP handle authentication and authorization?

MCP uses OAuth 2.1 for authentication and supports fine-grained scope-based authorization. According to phases/13-tools-and-protocols/16-mcp-security-oauth-2-1/docs/en.md, tools can declare required scopes (e.g., postgres:read or approved:by:human), and the server validates these tokens before execution. Additionally, OPA policies can enforce complex governance rules, such as blocking destructive operations unless explicitly approved by a human operator.

What transport protocol should I use for MCP servers?

You should use StreamableHTTP, the default stateless transport defined in the 2025-11-25 specification. As taught in phases/13-tools-and-protocols/09-mcp-transports/docs/en.md, StreamableHTTP replaces earlier stdio and SSE transports by providing a scalable, HTTP-based endpoint that supports streaming JSON-RPC responses. This works better with load balancers and cloud-native deployments than the older transport methods.

How do I discover available MCP servers in an enterprise environment?

Deploy a registry service that indexes server capabilities. Lesson 17 in Phase 13 (phases/13-tools-and-protocols/17-mcp-gateways-and-registries/docs/en.md) demonstrates building a registry that polls MCP servers for their manifests and exposes a UI or API for discovery. This pattern allows platform teams to centrally manage which tools are available to different agents while maintaining security through the gateway layer.

Have a question about this repo?

These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:

Share the following with your agent to get started:
curl -s "https://instagit.com/install.md"

Works with
Claude Codex Cursor VS Code OpenClaw Any MCP Client

Maintain an open-source project? Get it listed too →