Skip to main content

10. Agent Communication Protocols

Model Context Protocol (MCP)

Model Context Protocol (MCP) is an open standard for connecting AI hosts — IDEs, chat apps, agent runners — to external MCP servers that expose tools, resources, and prompts over a shared client–server contract. Instead of wiring every app to every data source with custom glue, hosts speak MCP once and reuse servers across products. MCP standardizes discovery and invocation; your allowlists, HITL, and budgets still govern what runs.

What you will learn

  • Explain what MCP is and why hosts adopt it
  • Distinguish tools, resources, and prompts
  • Describe connect-initialize-list-call session flow
  • Contrast MCP with ad-hoc function calling and A2A
  • Answer interview questions with short, solid answers
Host MCP client to MCP server tools resources prompts
Interview staple: MCP is the USB-C of AI context — one plug for many servers.

Definition

Model Context Protocol (MCP) defines how an AI application (the host) runs an MCP client that connects to one or more MCP servers. Servers advertise capabilities — tools the model can invoke, resources the app can read as context, and prompt templates users can start — using structured messages (commonly JSON-RPC style) over agreed transports such as stdio or HTTP/SSE.

MCP does not decide the agent’s plan. It standardizes how context and actions are plugged into whatever planning loop the host already uses.

Introduction

This lesson (#2 in Agent Communication Protocols) follows the module intro. You know why protocols exist; MCP is the main host↔tool/context contract in this curriculum.

Next: MCP Architecture, Clients, Servers, Tools and Resources — roles and message shapes in more depth.

Why MCP

  • One integration surface across IDEs, chat, and batch runners
  • Servers reusable by many hosts without rewriting connectors
  • Discovery of tools/resources instead of hard-coded lists only
  • Clearer separation: host policy vs server implementation
  • Ecosystem of shared servers for DBs, repos, browsers, SaaS

Roles

  • Host - product that embeds the LLM and MCP client(s)
  • MCP client - speaks the protocol, manages sessions
  • MCP server - exposes tools, resources, and/or prompts
  • User - consents to servers and high-risk actions
  • Policy layer - allowlists which servers/tools are enabled

Primitives

Three capability types cover most integrations.

MCP tools resources prompts primitives
Tools act; resources supply context; prompts package reusable workflows.
  • Tools - model-invoked actions with arguments and results (may have side effects)
  • Resources - URI-addressed data the host/app can fetch into context
  • Prompts - reusable templates/workflows users (or hosts) can trigger
  • A server may expose any subset of the three
  • Hosts map tools into the model’s function/tool API

Session flow

A typical session is discover-then-invoke under host policy.

Connect initialize list call tool result flow
Listing a tool does not grant use — the host still filters and may require HITL.
  • Connect - open transport (stdio, HTTP, SSE, etc.)
  • Initialize - capability/version handshake
  • List - tools, resources, prompts available
  • Call / read - invoke tools or fetch resources
  • Result - structured content back to host/model
  • Teardown - end session; revoke temporary creds

MCP vs function calling vs A2A

  • Function calling - model↔host schema for tools inside one app
  • MCP - host↔external servers with discovery and reusable servers
  • A2A - agent↔agent discovery and task delegation
  • Hosts often: MCP for tools/context + function calling to the LLM
  • Multi-agent products may add A2A alongside MCP

Safety and controls

  • User approval to install/enable each MCP server
  • Allowlist tools; disable destructive ones by default
  • Treat tool/resource output as untrusted (injection risk)
  • Prefer least-privilege credentials inside servers
  • Log every tool call with server id and arguments (redacted)
  • HITL for write tools that touch money, email, or prod systems

Failure modes

  • Running untrusted community servers with broad OS access
  • Assuming discovery equals authorization
  • No version negotiation — host/server skew
  • Dumping huge resources into context and blowing tokens
  • Confusing MCP with a full agent framework

Map to this module

  • Next: architecture of clients, servers, tools, resources
  • Then: building and integrating MCP with agents
  • Later: A2A and MCP vs A2A interoperability
  • Earlier: tool safety and workflows still apply on top of MCP

Program / implementation notes

Try a reference MCP server (e.g. filesystem or fetch) in a compliant host. Inspect listed tools, call one read-only tool, and note how the host surfaces consent. Sketch your own thin server that wraps one internal API as an MCP tool.

  • Start read-only; add write tools only with HITL
  • Next: MCP Architecture, Clients, Servers, Tools and Resources

Advantages and limitations

  • Advantage: portable tools/context across hosts
  • Advantage: clearer server boundaries and discovery
  • Advantage: growing ecosystem of ready servers
  • Limitation: host support and UX still vary
  • Limitation: security depends on who you trust to run servers
  • Limitation: not a substitute for agent planning or eval

Key points

  • MCP: host client ↔ MCP servers for tools, resources, prompts.
  • Tools act; resources provide context; prompts package workflows.
  • Flow: connect → initialize → list → call/read → result.
  • MCP complements function calling; it is not A2A.
  • Allowlists, consent, and HITL sit above the protocol.
  • Treat server output as untrusted content.

FAQs

Is MCP an agent framework?

No. MCP is an integration protocol for tools and context. Agent frameworks decide planning, memory, and loops; they can consume MCP servers as tool backends.

Tools vs resources?

Tools are actions the model can invoke (often with side effects). Resources are readable context addressed by URI that the host fetches into the session.

Does MCP replace OpenAPI?

Not always. Many MCP servers wrap OpenAPI/HTTP APIs. MCP adds a standard discovery and host integration layer on top of those backends.

Can one host use many MCP servers?

Yes. Hosts typically attach multiple servers and merge their listed capabilities under user/policy allowlists.

Interview questions

  1. What is Model Context Protocol (MCP)?

    Answer An open client–server standard that lets AI hosts discover and use external tools, resources, and prompts through a shared message contract.

  2. What are the three main MCP primitives?

    Answer Tools (invocable actions), resources (readable context via URIs), and prompts (reusable templates/workflows).

  3. Describe a typical MCP session.

    Answer Connect over a transport, initialize/handshake, list capabilities, then call tools or read resources and return structured results to the host/model.

  4. How does MCP relate to function calling?

    Answer Function calling is how the host exposes tools to the LLM. MCP is how the host talks to external servers that provide those tools and context.

  5. How do you keep MCP safe in production?

    Answer User consent per server, tool allowlists, least-privilege credentials, treat outputs as untrusted, log calls, and HITL for high-risk writes.

  6. MCP vs A2A?

    Answer MCP connects hosts to tool/context servers. A2A connects agents to other agents for discovery and task delegation. They can be used together.

Related topics

Practice task

Complete each numbered practice step in a notebook or doc before opening the next lesson.

  1. Write a one-paragraph definition of MCP in your own words.
  2. Map three internal capabilities to tool, resource, or prompt.
  3. List allowlist rules for enabling a new MCP server in a team IDE.
  4. Sketch connect → initialize → list → call for a read-only “get_order” tool.
  5. Answer interview questions 1, 2, and 5 in two sentences each.