# How the Model Context Protocol (MCP) Functions in Phase 13 of the AI Engineering Course

> Discover how the Model Context Protocol (MCP) works in Phase 13 of the AI engineering course. Learn how MCP standardizes tool discovery and invocation for AI models and external services.

- Repository: [Rohit Ghumare/ai-engineering-from-scratch](https://github.com/rohitg00/ai-engineering-from-scratch)
- Tags: deep-dive
- Published: 2026-06-16

---

**The Model Context Protocol (MCP) standardizes tool discovery and invocation between AI models and external services through a JSON-RPC specification, enabling seamless cross-provider interoperability in Phase 13 of the curriculum.**

The `rohitg00/ai-engineering-from-scratch` repository introduces the Model Context Protocol (MCP) in Phase 13 (Tools & Protocols) as the standardized mechanism for AI agents to discover and execute external tools. This protocol replaces fragmented, provider-specific implementations with a unified JSON-RPC interface that works across Anthropic, OpenAI, Google, and other model providers.

## What Is the Model Context Protocol (MCP)?

MCP is a specification that defines how AI clients communicate with tool servers. According to [`phases/13-tools-and-protocols/06-mcp-fundamentals/docs/en.md`](https://github.com/rohitg00/ai-engineering-from-scratch/blob/main/phases/13-tools-and-protocols/06-mcp-fundamentals/docs/en.md), the protocol establishes a contract where servers expose capabilities through a well-known registry, and clients invoke these capabilities via standardized JSON-RPC 2.0 requests. This architecture enables **agent-to-agent delegation (A2A)** and supports dynamic tool ecosystems without hardcoded integrations.

## Core Architecture and Primitives

The protocol defines symmetrical primitives for both server and client implementations.

### Server Primitives

Server implementations must provide three core primitives:

- **Tool registration**: Exposing available functions through a JSON-Schema definition
- **Capability metadata**: Publishing supported features and authentication requirements at [`/.well-known/mcp.json`](https://github.com/rohitg00/ai-engineering-from-scratch/blob/main//.well-known/mcp.json)
- **Execution endpoint**: Handling JSON-RPC requests and returning structured responses

### Client Primitives

Client implementations mirror these capabilities:

- **Discovery**: Querying the tool registry to learn available methods and signatures
- **Request formation**: Constructing valid JSON-RPC payloads with properly typed arguments
- **Response handling**: Parsing results and streaming them back to the LLM or orchestration layer

## The MCP Lifecycle in Phase 13

The course material outlines a three-phase lifecycle that governs every MCP interaction.

### Discovery Phase

During discovery, the client fetches the tool registry from the server's well-known endpoint. As documented in [`phases/13-tools-and-protocols/06-mcp-fundamentals/docs/en.md`](https://github.com/rohitg00/ai-engineering-from-scratch/blob/main/phases/13-tools-and-protocols/06-mcp-fundamentals/docs/en.md), this registry contains JSON-Schema definitions for all available tools, enabling the client to understand required parameters and return types before invocation.

### Invocation Phase

The client sends a JSON-RPC 2.0 request containing the method name and arguments. The protocol supports **stateless server design**, allowing each request to be independent and horizontally scalable. Security is enforced through **OAuth 2.1 scopes and OPA policy gating**, preventing unauthorized tool access at the transport layer.

### Result Handling

The server returns a JSON-RPC response containing the execution result or error details. Clients can stream these responses back to the LLM, enabling real-time tool use within conversational interfaces.

## Implementation Examples from the Course

The repository provides practical implementations in both Python and TypeScript.

### Building an MCP Client

The client implementation in [`phases/13-tools-and-protocols/08-building-an-mcp-client/docs/en.md`](https://github.com/rohitg00/ai-engineering-from-scratch/blob/main/phases/13-tools-and-protocols/08-building-an-mcp-client/docs/en.md) demonstrates how to instantiate a client, discover tools, and execute remote functions:

```python
from mcp import Client

client = Client(base_url="https://my-mcp-server.com")

# Discover tools

tools = client.get_tools()
print(tools)               # → [{'name': 'read_file', 'params': {...}}]

# Invoke the tool

response = client.call(
    method="read_file",
    params={"path": "/tmp/example.txt"}
)
print(response.result)     # → file contents

```

### Building an MCP Server

The server implementation in [`phases/13-tools-and-protocols/07-building-an-mcp-server/docs/en.md`](https://github.com/rohitg00/ai-engineering-from-scratch/blob/main/phases/13-tools-and-protocols/07-building-an-mcp-server/docs/en.md) shows how to expose custom tools using the TypeScript SDK:

```typescript
import { Server } from "modelcontextprotocol";

const server = new Server({
  register: [
    {
      name: "read_file",
      description: "Read a text file",
      params: {
        type: "object",
        properties: { path: { type: "string" } },
        required: ["path"]
      },
      handler: async ({ path }) => {
        const fs = await import("fs/promises");
        return { result: await fs.readFile(path, "utf-8") };
      }
    }
  ]
});

server.listen(8080);

```

## Integration with LLM Engineering

Phase 13 connects MCP to broader LLM engineering patterns covered in [`phases/11-llm-engineering/14-model-context-protocol/docs/en.md`](https://github.com/rohitg00/ai-engineering-from-scratch/blob/main/phases/11-llm-engineering/14-model-context-protocol/docs/en.md). The protocol integrates with **LangGraph's `ToolNode`** through an MCP adapter, allowing agents to use external tools as nodes within computational graphs. This integration demonstrates how MCP enables **registry-driven discovery** in production environments, supporting plug-and-play tool ecosystems that scale across AWS ECS deployments.

## Summary

- MCP provides a **unified JSON-RPC specification** that replaces provider-specific function calling mechanisms.
- The protocol defines **three server primitives** (registration, metadata, execution) and **three client primitives** (discovery, request formation, response handling).
- Tool discovery occurs through a **well-known registry** at [`/.well-known/mcp.json`](https://github.com/rohitg00/ai-engineering-from-scratch/blob/main//.well-known/mcp.json), enabling dynamic capability detection.
- **OAuth 2.1 and OPA policies** enforce security at the transport layer, while stateless design supports horizontal scaling.
- Implementation files in `phases/13-tools-and-protocols/` provide working Python and TypeScript examples for both client and server construction.

## Frequently Asked Questions

### What is the primary purpose of MCP in AI engineering?

The Model Context Protocol standardizes how AI agents discover and invoke external tools, eliminating the need for custom integrations across different model providers. As defined in [`glossary/terms.md`](https://github.com/rohitg00/ai-engineering-from-scratch/blob/main/glossary/terms.md), MCP establishes a common JSON-RPC interface that enables **agent-to-agent delegation** and dynamic tool ecosystems.

### How does MCP differ from provider-specific function calling?

Unlike proprietary implementations such as OpenAI's function calling or Anthropic's tool use, MCP provides a **provider-agnostic specification** based on JSON-RPC 2.0. This allows a single client implementation to communicate with any MCP-compliant server, regardless of the underlying AI model or hosting platform.

### What transport protocols does MCP support?

MCP supports **streamable transports** including HTTP and WebSocket, as documented in [`phases/13-tools-and-protocols/06-mcp-fundamentals/docs/en.md`](https://github.com/rohitg00/ai-engineering-from-scratch/blob/main/phases/13-tools-and-protocols/06-mcp-fundamentals/docs/en.md). The protocol's stateless design makes it compatible with standard load balancing and horizontal scaling strategies in cloud environments like AWS ECS.

### Where can I find the MCP implementation files in the repository?

The core specification resides in [`phases/13-tools-and-protocols/06-mcp-fundamentals/docs/en.md`](https://github.com/rohitg00/ai-engineering-from-scratch/blob/main/phases/13-tools-and-protocols/06-mcp-fundamentals/docs/en.md), while practical implementation guides are located in [`phases/13-tools-and-protocols/07-building-an-mcp-server/docs/en.md`](https://github.com/rohitg00/ai-engineering-from-scratch/blob/main/phases/13-tools-and-protocols/07-building-an-mcp-server/docs/en.md) and [`phases/13-tools-and-protocols/08-building-an-mcp-client/docs/en.md`](https://github.com/rohitg00/ai-engineering-from-scratch/blob/main/phases/13-tools-and-protocols/08-building-an-mcp-client/docs/en.md). Integration examples with LangGraph appear in [`phases/11-llm-engineering/14-model-context-protocol/docs/en.md`](https://github.com/rohitg00/ai-engineering-from-scratch/blob/main/phases/11-llm-engineering/14-model-context-protocol/docs/en.md).