Part 9 · Agents · Lesson 9.3

MCP and agent protocols

The Model Context Protocol for exposing tools and data to any compatible client, plus agent-to-agent and agent-to-UI protocols, and their security implications.

L4 · Applied AI engineer≈ 5 min read
Key points · the two-minute version
  1. MCP standardises tools, resources and prompts for any client, turning M×N integrations into M+N.
  2. Use stdio for local servers and HTTP for remote ones, which need real auth (OAuth) and per-call authorisation.
  3. Every MCP server is new attack surface, so treat third-party tool descriptions as untrusted.
  4. A2A connects agents to agents; AG-UI connects agents to UIs.
  5. Separate read and write tools, require approval for side effects, and log every call.
You should be able to
  • Explain what MCP standardises and why it matters
  • Build and secure a small MCP server
  • Recognise A2A and AG-UI and what they're for

Why this matters

Before MCP, every AI client needed custom integration code for every tool. MCP is now widely supported by assistants, IDEs and agent platforms, and exposing your service as an MCP server is an increasingly common requirement.

Q33. MCP?

An open protocol exposing tools, resources and prompts to any compatible client: M×N integrations become M+N. Every MCP server is new attack surface. Casebook example: FastMCP tool servers with a shared secret required beyond loopback (P8). Managed agent gateways can turn existing APIs and functions into MCP tools with central authentication (9.4).

Core ideas

  • Server exposes tools (actions), resources (readable data) and prompts (templates).
  • Client (an assistant, IDE or agent) discovers and calls them.
  • Transports: local (stdio) for tools on your machine; HTTP for remote servers.
  • Auth: remote servers need real authentication and per-user authorization (OAuth is the common choice).

How to do it

from fastmcp import FastMCP

mcp = FastMCP("orders")

@mcp.tool()
async def get_order_status(order_id: int) -> str:
    """Return the status of one of the current user's orders."""
    user = current_user()                      # from the authenticated session
    order = await orders.get(order_id)
    if order is None or order.customer_id != user.id:
        return "not found"
    return order.status
Protocol Connects Use
MCP Model/agent ↔ tools and data Tool and context integration
A2A Agent ↔ agent Delegating tasks between independent agents
AG-UI Agent ↔ user interface Streaming agent events and state to frontends

Security checklist for MCP servers

  • Authenticate every remote connection; never expose an unauthenticated server beyond localhost.
  • Authorize per tool call with the user's identity.
  • Treat tool descriptions from third-party servers as untrusted (they're text the model reads).
  • Least privilege: separate read-only and write tools; approval for side effects.
  • Log every call (who, which tool, arguments without secrets, outcome).

Interview follow-ups

  • "MCP vs plain function calling?" Function calling is how a model asks for a tool within one app; MCP is how tools are packaged and discovered across apps and clients. MCP servers still surface as function calls to the model.
  • "How do you authenticate a remote MCP server per user?" OAuth for the client connection, the user's identity propagated to every tool call, and per-tool authorisation server-side.

Check yourself

What problem does MCP solve?

It standardises how AI clients discover and call tools and data, so each tool is implemented once as a server and works with every compatible client: M clients × N tools becomes M + N integrations.

Why is a third-party MCP server a security risk?

Its tool descriptions and outputs are text the model reads (an injection channel), its tools may have broad side effects, and it may receive sensitive data. Vet it like any dependency, restrict its permissions and require approval for risky calls.

Build it

Expose two tools from your project as an MCP server, connect it to an MCP-capable client, and add authentication for the HTTP transport.

What comes next

9.4 Frameworks and runtimes.

Build it to remember

Two hands-on projects that exercise this lesson. Pick one, build it end to end, and keep it in your portfolio.

Project 1

MCP server for your own app

Expose read tools and one write tool (with confirmation) from an app you've built, over authenticated HTTP, and use it from an MCP client.

  • Python
  • FastMCP
  • FastAPI
  • OAuth

Practises Building and securing MCP.

Project 2

Docs MCP server

A search-docs tool and a read-page resource over your RAG index, usable from an IDE assistant.

  • TypeScript
  • MCP TypeScript SDK
  • pgvector

Practises Resources vs tools; reuse of RAG.

Can you answer every check-yourself question out loud without opening the answer?