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.
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 (
whileLoop): Wraps Function Calling inside an autonomous loop that continues until the goal is solved:- Read Sentry Logs (
NullPointerExceptionat line 42) - Query Postgres DB (inspect user record
#402) - Patch Source Code (add null guard in
checkout.ts) - Run Unit Test Suite (48/48 tests pass $\to$ Done!)
- Read Sentry Logs (
2. Inside the ReAct Loop (Reason + Act)
Every turn of a production AI agent executes four ordered steps:
- Step ① — Thought (Reason): The LLM inspects its goal and previous observations to plan its very next step.
- Step ② — Action (JSON Tool Call): The model emits a structured JSON tool call (
{"tool": "sentry_logs", "args": {"service": "checkout"}}). - Step ③ — Observation (Execute & Loop): Your agent runtime executes the tool, appends the real output back into the conversation context, and loops to Turn #2.
- 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:1connection over JSON-RPC 2.0 (stdioorHTTP/SSE). - ③ MCP Server: A lightweight adapter wrapping Postgres, GitHub, Slack, or Sentry behind the standard MCP specification (
tools/listandtools/call).
4. The 3 MCP Primitives
| Primitive | Controlled By | Purpose & Example |
|---|---|---|
| ① Tools | Model-Controlled (LLM) | Executable functions the LLM chooses to invoke (query_postgres(), create_github_pr()) |
| ② Resources | App-Controlled (Host) | Read-only files & schemas attached as context (postgres://schema.sql, repo://README.md) |
| ③ Prompts | User-Controlled (UI) | Reusable slash workflow templates (/review-pr, /debug-incident) |
Test Your Understanding
Quick architectural scenario challenge based on this breakdown.
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 –
Sign in to share your thoughts
Nothing yet. Be the first.