AI Agent Beginner Tutorial: 11 - MCP and Multi-Agent Systems

Connect controlled external capabilities through MCP hosts, clients, servers, tools, resources, and prompts, then compare manager, agent-as-tool, and handoff patterns against a single-agent baseline. A split must produce measurable quality or maintenance gains.

Contents7 sections

MCP standardizes connection and discovery

The Agents SDK now owns the local loop and session, while search and read tools still run in the application process. Hand-writing authentication, capability lists, and invocation formats for every source system fills an agent application with custom adapters. MCP creates a standard connection among host, client, and server.

TEXT
┌──────────────────── Host ────────────────────┐
│ Model + Agent Runtime + Permission + Approval│
│                  │                           │
│             MCP Client                       │
└──────────────────┼───────────────────────────┘
                   │ protocol / transport
                   ▼
          ┌──────────────────┐
          │    MCP Server    │
          │ Tools / Resources│
          │ Prompts          │
          └──────────────────┘

The server exposes capabilities, the client manages the protocol session, and the host retains the model, user interaction, permissions, and coordination across connections. MCP does not take over business authorization.

Use tools, resources, and prompts differently

A tool is an action the model may request, such as document search. A resource is a readable object, such as a specification. A prompt is a reusable template, such as a research outline.

Static document reading fits resources, parameterized search fits tools, and a fixed working method can live in a prompt or the skill system from Chapter 8. A skill may reference both MCP tools and resources.

Connect in five steps

  1. Verify server identity and operator.
  2. Initialize the connection and negotiate protocol capabilities.
  3. List server capabilities and filter them through a local allowlist.
  4. Map allowed capabilities into the tool registry with approval, timeout, and result limits.
  5. Cache the server version and rediscover after a version or schema change.
PYTHON
from dataclasses import dataclass

@dataclass(frozen=True)
class Capability:
    name: str
    description: str
    input_schema: dict

def filter_capabilities(discovered: list[Capability],
                        allowed: set[str]) -> dict[str, Capability]:
    return {
        capability.name: capability
        for capability in discovered
        if capability.name in allowed
    }

Remote output remains untrusted evidence. A connection timeout returns mcp_unavailable, allowing the main loop to use local sources or report an evidence gap without reconnecting forever.

Decide whether more tools justify more agents

MCP may add tools, but tool count alone does not require multiple agents. Run a single-agent baseline and observe tool-selection errors, prompt conflicts, permission separation, and team maintenance cost.

A split becomes worth testing when at least one condition appears:

  • Research and writing instructions interfere, and evaluations cannot satisfy both.
  • Tool groups use different identities and data boundaries.
  • Specialist context can be much smaller and exclude irrelevant material.
  • Separate teams need independent releases and maintenance.

Compare three multi-agent relationships

TEXT
Manager                  Agent-as-Tool              Handoff
User                     User                       User
 │                        │                          │
 ▼                        ▼                          ▼
Central agent ─▶ expert   Manager ─call─▶ expert     Front agent ──▶ expert
 │              │         ▲              │                       owns next turns
 └────merge─────┘         └────result────┘

A manager uses code for central orchestration. Agent-as-tool keeps final control with the manager. A handoff transfers the conversation to a specialist for subsequent turns.

Represent a specialist tool in the Agents SDK

PYTHON
from agents import Agent

researcher = Agent(
    name="Researcher",
    instructions="Return evidence with source IDs. Do not draft conclusions.",
)

manager = Agent(
    name="Brief manager",
    instructions="Collect evidence, draft, validate citations, then answer.",
    tools=[
        researcher.as_tool(
            tool_name="collect_evidence",
            tool_description="Collect bounded evidence for the topic.",
        )
    ],
)

A specialist receives only the context and tools needed for its responsibility, with bounded delegation depth, concurrent specialists, and budget.

Preserve a single-agent control group

Run the same task set through a single agent, manager plus specialists, and handoff version. Compare success, citation correctness, P95 latency, tokens, cost, and maintenance time. If multiple agents improve only style while reducing citation accuracy or adding substantial cost, retain one agent.

Chapter 12 compares the single-agent and multi-agent versions on the same task set, formalizes evaluation and tracing, and connects passing gates to queues, workers, canaries, and release decisions.

REFERENCES

References

  1. 01Architecture Overview | Model Context Protocol
  2. 02MCP and Connectors | OpenAI API
  3. 03Orchestrating Multiple Agents | OpenAI API
  4. 04A Practical Guide to Building Agents | OpenAI

Series

AI AGENT Beginner's Guide

Next step

Continue with related topics

Continue along the same topic.

Browse latest news