AI Agent Interoperability in Practice
Getting agents from different frameworks to work together is not about standardizing on one framework. It takes two protocols: MCP for tool reuse, A2A for handing whole tasks between agents. Here is a minimal working setup - one FastMCP server, one Agent Card, one cross-framework handoff - plus auth, timeout and error handling pitfalls.
📜 Table of Contents
📖 Keep reading
Agent Interoperability in Practice: MCP and A2A Across Frameworks
Most teams run three things at once: a LangGraph main flow, a colleague's CrewAI research agent, and a pile of internal systems. The lazy fix is rewriting everything into one framework. The cheaper fix is two interfaces - tools exposed over MCP, tasks handed over A2A.
Specs and SDK interfaces keep changing. Check official docs before you copy code.
Which protocol for what
| You want to | Use | Why |
|---|---|---|
| Let any client query your knowledge base | MCP | Implement once, reuse everywhere |
| Outsource a whole "write competitor research" job | A2A | You pass responsibility, not parameters |
| Call a function in the same process | Neither | Plain code is faster |
| Two agents negotiating over several rounds | A2A | Task states and input-required turns |
The test: are you passing data or responsibility? Data goes over MCP, responsibility goes over A2A.
Build an MCP server in 15 minutes
The official Python SDK ships FastMCP, which is the least boilerplate path.
# pip install mcp
from mcp.server.fastmcp import FastMCP
mcp = FastMCP("kb-server")
@mcp.tool()
def search_docs(query: str, top_k: int = 5) -> list[dict]:
"""Search the internal knowledge base.
Args:
query: Natural-language search phrase
top_k: Number of results, default 5, max 20
"""
top_k = min(max(top_k, 1), 20)
rows = kb.search(query, limit=top_k)
return [{"title": r.title, "snippet": r.text[:400], "url": r.url} for r in rows]
if __name__ == "__main__":
mcp.run() # stdio by default
Three rules: the docstring is the model's manual, so make it explicit about when to call; return small payloads, because full documents blow up the context; clamp parameters yourself, because the model will send top_k=500 or the string "5".
Use stdio locally, switch to the HTTP transport when many clients share one server.
Wire it into a client
Desktop clients read a JSON config:
{
"mcpServers": {
"kb": {
"command": "python",
"args": ["C:/work/kb_server/server.py"],
"env": { "KB_TOKEN": "xxx" }
}
}
}
If the tool does not appear, check the path, the Python environment, and the startup log. In stdio mode logs must go to stderr - one print to stdout breaks the protocol stream. That is the most common failure.
A2A: let another agent take the job
Step one is publishing an Agent Card. Approximate shape:
{
"name": "research-agent",
"description": "Competitor research agent: company name in, structured report out",
"url": "https://agents.example.com/research",
"version": "1.0.0",
"capabilities": { "streaming": true },
"defaultInputModes": ["text/plain"],
"defaultOutputModes": ["text/plain", "application/json"],
"skills": [
{ "id": "competitor-report", "name": "Competitor research",
"description": "Positioning, pricing, channels, recent moves",
"tags": ["research", "competitor"] }
]
}
Tasks then move through submitted, working, input-required, completed, failed or canceled. Four things you actually have to engineer:
- Idempotency: a resent task must not produce a second report; dedupe on caller-supplied task_id.
- Timeout and cancellation: external agents hang; propagate cancel signals.
- Persisted state: store task state so a restart does not lose work.
- Result validation: "done" is not "well-formed"; validate against the agreed schema.
What a real composition looks like
- LangGraph main graph handles planning and human approval
- Research, drafting and proofreading are three separate agents with their own cards
- Shared retrieval is one MCP server everyone attaches to
- Each node calls its agent, retries twice, then degrades to "skip and flag the gap"
Swapping any agent leaves the rest untouched. The price is a network hop and task-state bookkeeping.
Five common pitfalls
| Symptom | Cause | Fix |
|---|---|---|
| Client cannot connect | Logs on stdout broke stdio | Log to stderr only |
| Model never calls the tool | Vague description or too many params | Say when to use it; keep params under three |
| Context explodes | Tool returns whole documents | Return snippets with truncation |
| Task runs twice | No idempotency | task_id dedupe table |
| Privilege escalation | External agent holds over-broad credentials | One credential per tool class |
FAQ
Must MCP servers be deployed separately? No. Local stdio with one script is fine; deploy over HTTP only for shared or cross-machine access.
How is A2A different from plain HTTP? It standardizes discovery, the task state machine, input-required turns and streaming. You can rebuild that yourself, but cross-team integration will not line up.
Does running both double maintenance? No - MCP usually removes duplicated tool adapters.
Can local models do this? Yes. Both protocols are model-agnostic; Ollama-hosted models can call tools fine.
Note: import paths, transport names and Agent Card fields shift between versions. Defer to the official repo and spec.
Related
Written by our editorial team; tools listed here are tested or verified against public sources. Links point to official sites or GitHub repos for reference only — no paid placements.