Building AI Agents with MCP and LangGraph: Local LLMs to Production
Build a small AI agent that uses a local language model, accesses tools through Model Context Protocol (MCP), and coordinates its workflow with LangGraph. Learn essential concepts through guided code, diagrams, and labs, then add validation, testing, and operational safeguards. Complete a compact capstone and prepare a production deployment plan without requiring a paid cloud service.
Level: beginner · 24 lessons · about 8 h · Free · AI-assisted course created by Sandip Das
What you will learn
Explain how language models, agents, MCP clients and servers, and LangGraph fit together.
Run a local language model and connect it to a minimal Python agent.
Expose a constrained tool through an MCP server and invoke it from an agent.
Build a LangGraph workflow with explicit state, conditional routing, and bounded tool execution.
Apply input validation, secrets handling, and approval checks to tool access.
Test successful and failing agent runs and inspect structured execution logs.
Deliver a runnable local capstone with a deployment checklist covering configuration, health checks, and recovery.
Course outline
1. Foundations: Python and the Agent System
Build the minimum Python and API skills needed to understand a local agent, using guided code and an architecture diagram.
Create Your Python Project(20 min)· free preview Guided setup introduces Python 3.11+, virtual environments, package installation, functions, imports, and a reproducible project layout without becoming a full Python course.
Move Data Between Python and an API(20 min) Practice dictionaries, lists, basic error handling, JSON serialization, and a small HTTP request with synthetic data.
Map the Model, Agent, MCP, and Graph(20 min) Trace a request through a labeled architecture diagram and distinguish fixed workflows from dynamic agent decisions.
2. Run and Verify a Local Language Model
Use Ollama for a local-first model workflow and verify both basic inference and structured tool calling on the available hardware.
Start Ollama and Choose a Model That Fits(20 min) Guided lab selects an available small tool-capable model, checks hardware placement and memory constraints, and keeps the endpoint local; artifact size is not treated as runtime RAM.
Call the Local Model from Python(20 min) Configure ChatOllama with the downloaded model tag and a short prompt; outline a compatible hosted-endpoint fallback without requiring a paid service or silently sending data off-device.
Verify a Bounded Tool-Calling Loop(20 min) Use a harmless typed function to practice model request, application dispatch, tool observation, and final answer before introducing MCP.
3. Expose and Call a Constrained MCP Tool
Build a small read-only synthetic-data service using current MCP SDK conventions and distinguish local stdio from remote HTTP transport.
Understand the MCP Contract and Transports(20 min) Diagram tools/list and tools/call, input and output schemas, stdio versus Streamable HTTP, and current per-request version metadata without teaching the legacy initialization handshake as current behavior.
Build a Read-Only MCP Server(20 min) Guided lab exposes a bounded lookup over synthetic records using MCPServer, typed arguments, and validation, with a main guard and stderr-only diagnostics.
Discover and Invoke the Tool with a Client(20 min) Launch the server as a managed subprocess, list tools, call the lookup, inspect the result, and confirm cleanup and explicit environment configuration.
4. Coordinate the Agent with LangGraph
Build a visible state machine and adapt the MCP tool into a bounded model-tool workflow using one consistent, pinned integration path.
Build and Run Your First StateGraph(20 min) Use a diagram and a small deterministic graph to introduce shared state, updates, reducers, START and END boundaries, compilation, and invocation.
Connect MCP Tools to Graph Nodes(20 min) Use the current langchain.mcp MCPAdapter path with pinned dependencies, discover tools, and wire model and execution nodes while making connection ownership explicit.
Add Conditional Routing and Execution Budgets(20 min) Guided graph lab routes between answer, permitted tool execution, and controlled termination, including unknown-tool and repeated-call cases.
5. Persist State and Recover from Failures
Add durable local checkpoints, finite retries, and timeouts while distinguishing recoverable service failures from invalid requests.
Save and Inspect a Local Run(20 min) Add AsyncSqliteSaver, inspect a checkpoint, and keep the saver connection open for the graph's lifetime.
Handle Timeouts and Transient Failures(20 min) Inject a simulated slow or unavailable tool and configure bounded retries, explicit retry predicates, and a controlled error path.
Resume Safely After an Interrupted Run(20 min) Practice restarting a local process and recovering its thread, then use a replay diagram to explain duplicate work and idempotency before introducing approval interrupts.
6. Validate, Isolate, and Approve Tool Access
Treat model requests and external content as untrusted, enforce least privilege, and add a durable human decision before protected tool execution.
Keep Secrets and Host Access Narrow(20 min) Configure only the environment variables a local server needs, avoid embedded credentials and sensitive logs, and compare local stdio security with protected HTTP deployment requirements.
Pause for Approval Before a Protected Call(20 min) Add a review gate even for the harmless capstone lookup, with approve and reject paths, stable thread selection, and no consequential action before interrupt.
7. Test Runs and Inspect Execution Evidence
Build deterministic checks, privacy-conscious structured logs, and a small outcome-and-trajectory evaluation without a paid model judge.
Test Nodes and Complete Graph Paths(20 min) Use synthetic fixtures and controlled model responses to test success, invalid inputs, tool failure, budget exhaustion, and approval rejection; keep live local-model checks separate.
Follow a Run Through Structured Logs(20 min) Emit JSONL events with correlation identifiers, node and tool names, duration, call counts, status, and stop reasons, then inspect a failed run without full prompt or result logging.
Evaluate Answers and Tool Trajectories(20 min) Create a compact synthetic evaluation set, distinguish deterministic assertions from nondeterministic live-model observations, and close with a quiz, debugging cheat sheet, and interview-style trade-off prompts.
8. Deliver the Local Capstone and Deployment Plan
Assemble a runnable, security-conscious local prototype, document packaging and health checks, and demonstrate recovery within a cloud-neutral deployment plan.
Assemble the Local Lookup Agent(25 min) Integrate earlier lab artifacts rather than start a large new application: a synthetic read-only lookup service, local model, bounded graph, SQLite state, validation, approval, tests, and redacted logs.
Write the Packaging and Deployment Checklist(20 min) Record dependency locks, model and endpoint configuration, startup and readiness probes, state and recovery handling, and local-process versus optional Compose trade-offs; remote HTTP remains a plan, not a required cloud build.
Demonstrate the Capstone and Explain Its Limits(15 min) Use a compact acceptance checklist and rubric to present the runnable artifact, architecture diagram, test and log evidence, recovery steps, and remaining production limitations.