Model Context Protocol (MCP) & Agentic RAG
Master Model Context Protocol (MCP) and Agentic RAG in LangGraph — connect stdio/SSE servers, build async execution loops, and implement retriever tools.
This module explores connecting your compiled graphs to external tools using the Model Context Protocol (MCP) and fusing document vectorstores as retriever tools (Agentic RAG).
Model Context Protocol (MCP)
Why this matters
MCP standardizes tool access so agents connect to external systems without brittle custom wrappers.
MCP (Model Context Protocol) exposes tools/resources via a standard client-server protocol — reduces one-off integrations.
from langchain_mcp_adapters.client import MultiServerMCPClient
client = MultiServerMCPClient({
"filesystem": {"command": "npx", "args": ["-y", "@modelcontextprotocol/server-filesystem", "/tmp"]},
})
tools = await client.get_tools()- Traditional tools: ad-hoc Python functions; MCP: discoverable, typed servers.
- Wire MCP tools into LangGraph agent nodes like any other tool.
Common mistakes
- Forgetting to compile the graph with a checkpointer when persistence is required.
- List state fields without reducers — updates overwrite instead of append.
- Infinite loops in cyclic graphs with no max iteration or termination edge.
Interview checkpoints
- Q: Explain mcp in LangGraph. A: One-sentence definition + one API.
- Q: Common bug? A: State, checkpointer, or routing loop issue.
Practice
- Basic: Sketch a minimal mcp example.
- Intermediate: Run a notebook cell demonstrating MCP.
- Advanced: Break MCP intentionally and read the LangSmith trace.
Recap
- You can explain mcp clearly.
- You know one mistake to avoid.
- You see how this connects to the next lesson.
Next: Agentic RAG
Agentic RAG Patterns
Why this matters
Agentic RAG lets the agent decide when to retrieve — more flexible than fixed retrieve-then-generate.
Agentic RAG lets the agent decide when to query a vector store vs answer from context — more adaptive than fixed pipelines.
- RAG as tool: retriever returns docs; LLM synthesizes with citations.
- Combine MCP file servers with vector search for hybrid knowledge access.
Common mistakes
- Forgetting to compile the graph with a checkpointer when persistence is required.
- List state fields without reducers — updates overwrite instead of append.
- Infinite loops in cyclic graphs with no max iteration or termination edge.
Interview checkpoints
- Q: Explain agentic rag in LangGraph. A: One-sentence definition + one API.
- Q: Common bug? A: State, checkpointer, or routing loop issue.
Practice
- Basic: Sketch a minimal agentic rag example.
- Intermediate: Run a notebook cell demonstrating Agentic RAG.
- Advanced: Break Agentic RAG intentionally and read the LangSmith trace.
Recap
- You can explain agentic rag clearly.
- You know one mistake to avoid.
- You see how this connects to the next lesson.
Next: Subgraphs
