⑥ MCP & A2A

Course path (9 chapters)
  1. LLM
  2. RAG
  3. Agent Core
  4. Retrieval Engineering
  5. LangChain & LangGraph
  6. MCP & A2A
  7. OpenClaw & Hermes
  8. Multi-agent & KG
  9. Multimodal
Chapter 6

MCP & A2A

How agents connect to tools (vertical) and to other agents (horizontal)

Prev: LangChain & LangGraph. Next: OpenClaw & Hermes.

Problem

Why protocols exist

Before MCP: every IDE, every chat app, every agent framework wrote custom integrations for GitHub, Postgres, filesystem...

Before A2A: Agent A could not hand off a subtask to Agent B from another vendor.

MCP

MCP architecture (Model Context Protocol)

By Anthropic. Standard wire format between host (app with LLM) and servers (tool providers).

RoleExamplesJob
HostClaude Desktop, Cursor, IDERuns LLM, shows UI
ClientInside host1:1 connection to a server
Serverfilesystem, postgres, githubExposes tools/resources/prompts

Three primitives MCP servers expose

PrimitiveLLM seesExample
tools/listCallable functionsread_file(path), query(sql)
resources/listReadable URIsfile:///project/README.md
prompts/listTemplate namescode-review, summarize-diff
MCP

Build an MCP server (Python)

pip install mcp

from mcp.server import Server
from mcp.types import Tool, TextContent
import mcp.server.stdio

app = Server("demo-server")

@app.list_tools()
async def list_tools():
    return [Tool(
        name="get_policy",
        description="Get refund policy text",
        inputSchema={"type":"object","properties":{"sku":{"type":"string"}},"required":["sku"]},
    )]

@app.call_tool()
async def call_tool(name: str, arguments: dict):
    if name == "get_policy":
        return [TextContent(type="text", text=f"Refund for {arguments['sku']}: 30 days")]

async def main():
    async with mcp.server.stdio.stdio_server() as (read, write):
        await app.run(read, write, app.create_initialization_options())

# Run: python server.py — host connects via stdio or HTTP

Connect in Claude Desktop

// ~/.claude/claude_desktop_config.json (Windows: %APPDATA%\Claude\)
{
  "mcpServers": {
    "demo": {
      "command": "python",
      "args": ["C:/path/to/server.py"]
    },
    "filesystem": {
      "command": "npx",
      "args": ["-y", "@modelcontextprotocol/server-filesystem", "C:/allowed/folder"]
    }
  }
}

Step-by-step: filesystem MCP (class demo)

  1. Install Node.js (for npx).
  2. Create folder e.g. C:/demo-docs with one README.md.
  3. Edit claude_desktop_config.json — add filesystem server block above; use your folder path.
  4. Quit Claude Desktop completely (tray icon → Exit), then reopen.
  5. Settings → Developer → confirm server shows green / connected.
  6. Ask: "Summarize README.md in my demo folder" — model should call read_file.
  7. If fail: check path slashes, restart again, read Claude Desktop logs.

Transport: stdio vs HTTP (SSE)

TransportHow host starts serverTypical use
stdioSpawns child process; JSON-RPC over stdin/stdoutClaude Desktop, local dev
SSE / HTTPServer runs separately; host connects to URLRemote team servers, Docker

Most tutorials use stdio because zero networking setup. Production often wraps the same server in HTTP for auth + scaling.

Use MCP tools inside LangGraph (your product)

# langchain-mcp-adapters (conceptual flow)
from langchain_mcp_adapters.client import MultiServerMCPClient

client = MultiServerMCPClient({
    "policy": {"command": "python", "args": ["policy_server.py"]},
})
tools = await client.get_tools()  # LangChain Tool objects from MCP list_tools
llm_with_mcp = llm.bind_tools(tools)
# Feed into your LangGraph ToolNode — same as native @tool

Pattern: MCP for shared infra plugins; native @tool for business logic only your app needs.

Troubleshooting checklist

MCP

MCP vs in-app tools

In-app Python @toolMCP server
ProcessSame as agentSeparate process
ReuseThis codebase onlyClaude Desktop + Cursor + any MCP host
Security boundaryWeakerOS-level separation possible
WhenYour product backendDeveloper tools, shared infra plugins
A2A

A2A (Agent-to-Agent Protocol)

By Google. Lets agents discover and delegate to other agents over HTTP.

Agent Card (like openapi.json for agents)

{
  "name": "HotelBookingAgent",
  "description": "Books hotel rooms given city and dates",
  "url": "https://hotels.example.com/a2a",
  "skills": [{
    "id": "book_hotel",
    "name": "Book Hotel",
    "input_schema": {
      "type": "object",
      "properties": {
        "city": {"type": "string"},
        "check_in": {"type": "string", "format": "date"}
      }
    }
  }]
}

Task lifecycle

  1. Travel agent finds Hotel agent via Agent Card URL
  2. Sends Task: { skill: book_hotel, input: { city: "Paris", ... } }
  3. Hotel agent works async, streams status updates
  4. Returns Artifact: confirmation JSON
  5. Travel agent continues itinerary with artifact in context

Example HTTP messages (simplified)

POST https://hotels.example.com/a2a/tasks
{
  "skill_id": "book_hotel",
  "input": {"city": "Paris", "check_in": "2025-07-01", "nights": 3},
  "context_id": "trip-abc-123"
}

# Response (in progress)
{"task_id": "t-884", "state": "working", "status": "Searching availability..."}

# Poll or webhook when done
{"task_id": "t-884", "state": "completed", "artifacts": [{
  "type": "application/json",
  "data": {"confirmation": "HTL-991", "hotel": "Le Marais", "total_usd": 420}
}]}

When to use A2A vs in-process LangGraph

SituationPick
All agents in your Python monolithLangGraph supervisor subgraph
Partner runs their agent; you only have URL + contractA2A Agent Card + Task API
Same company, different teams / languagesA2A or internal gRPC — A2A if you want standard discovery
Compare

MCP vs A2A — when to use

ScenarioProtocol
Read company wiki, query SQL, call REST APIMCP
Delegate to legal-review agent at another companyA2A
Cursor coding assistant + local filesystemMCP
Supervisor agent + specialist microservicesA2A (or internal LangGraph)
Analogy: MCP = USB devices plugged into one computer. A2A = two colleagues emailing task handoffs.
Lab

Lab: MCP + mock A2A

  1. Run official filesystem MCP server; connect Claude Desktop; ask to summarize a local file.
  2. Write minimal Python MCP server with one custom tool (get_policy).
  3. Sketch Agent Card JSON for a fake "WeatherAgent"; document what Task/Artifact would look like.
  4. Diagram your product: which capabilities are MCP (tools) vs A2A (remote agents).