OwlTheEngineer
How It Actually WorksEpisode 56 · AI

How AI Agents and MCP (Model Context Protocol) Actually Fit Together

From 1-shot Function Calling to the autonomous ReAct while-loop, and how Model Context Protocol (MCP) acts as the universal USB-C port for AI tools.

Owl · 2 min read · 2 views
– comments
Ep 56 · AI
60s VISUAL BREAKDOWN
Episode 56
Watch the fast visual breakdown or discuss on social:

In Episode 53, we saw how Function Calling lets an LLM emit a structured JSON request for one external tool call.

So what makes an AI Agent different from standard Function Calling—and where does MCP (Model Context Protocol) fit into the stack?


1. 1-Shot Function Calling vs. Autonomous AI Agent

  • Standard Function Calling (1-Shot): A single turn. The LLM requests one tool (get_weather("Tokyo")), your server returns the JSON result, the LLM writes a reply, and execution immediately stops.
  • Autonomous AI Agent (while Loop): Wraps Function Calling inside an autonomous loop that continues until the goal is solved:
    1. Read Sentry Logs (NullPointerException at line 42)
    2. Query Postgres DB (inspect user record #402)
    3. Patch Source Code (add null guard in checkout.ts)
    4. Run Unit Test Suite (48/48 tests pass $\to$ Done!)

2. Inside the ReAct Loop (Reason + Act)

Every turn of a production AI agent executes four ordered steps:

  1. Step ① — Thought (Reason): The LLM inspects its goal and previous observations to plan its very next step.
  2. Step ② — Action (JSON Tool Call): The model emits a structured JSON tool call ({"tool": "sentry_logs", "args": {"service": "checkout"}}).
  3. Step ③ — Observation (Execute & Loop): Your agent runtime executes the tool, appends the real output back into the conversation context, and loops to Turn #2.
  4. Step ④ — Safety Guardrails: Production runtimes enforce max_iterations (to prevent infinite token-burning loops) and Human-in-the-Loop approval before destructive actions (DROP TABLE, production deploys).

3. Why MCP Exists: The $M \times N$ Connector Nightmare

Without a standard protocol, connecting $M$ AI applications (Claude Desktop, Cursor IDE, your custom backend agent) to $N$ external tools (Postgres, GitHub, Slack, Sentry) requires $M \times N$ custom integrations. Every engineering team had to rewrite duplicate auth wrappers, parsers, and JSON schemas for the exact same tools.

Model Context Protocol (MCP) solves this by acting as the universal USB-C port for AI applications, turning an $O(M \times N)$ problem into $O(M + N)$:

  • ① MCP Host: The AI application you interact with (Cursor, Claude Desktop, or your custom backend agent).
  • ② MCP Client: Inside the Host, each MCP Client maintains an isolated 1:1 connection over JSON-RPC 2.0 (stdio or HTTP/SSE).
  • ③ MCP Server: A lightweight adapter wrapping Postgres, GitHub, Slack, or Sentry behind the standard MCP specification (tools/list and tools/call).

4. The 3 MCP Primitives

PrimitiveControlled ByPurpose & Example
① ToolsModel-Controlled (LLM)Executable functions the LLM chooses to invoke (query_postgres(), create_github_pr())
② ResourcesApp-Controlled (Host)Read-only files & schemas attached as context (postgres://schema.sql, repo://README.md)
③ PromptsUser-Controlled (UI)Reusable slash workflow templates (/review-pr, /debug-incident)
SYSTEM DESIGN CHECK

Test Your Understanding

Quick architectural scenario challenge based on this breakdown.

SCENARIO

A 3rd-party payment gateway starts timing out with 504 errors during peak traffic.

Q1.How should a downstream dependency failure be handled to protect upstream service availability?

Comments –