(opens in a new tab) Skip to main content

AI & Machine Learning

Local LangGraph Agents with MCP

Lex Gaines, 10 parts, 90 min total read time

These are the notes from building a small LangGraph agent that runs entirely on my own machine: a 7B model served by LM Studio, calling real tools through MCP servers. I started knowing almost nothing about LangChain or LangGraph, and I built each piece by hand so I could see what the prebuilt helpers were hiding.

The agent routes each request to the right group of tools, asks me before it changes any file, remembers conversations across restarts, and has a small eval so I can tell when a prompt change breaks it. Along the way a small local model did most of the things small local models do: it picked the wrong tool, invented dates, and told me a website was down when the real problem was a browser driver. Those failures are in the series, because they taught me more than the parts that worked the first time.

Local LangGraph Agents with MCP

Parts

  1. Part 1

    A Local Tool-Using Agent in About 100 Lines

    Wire a 7B model in LM Studio to three MCP servers with LangChain's create_agent, and read the tool calls it makes on a real run.

    9 min read

  2. Part 2

    Why Your Small Model Picks the Wrong Tool

    A 7B model with many tools invents dates, miscounts and misreports errors. What I cut, what the system prompt says line by line, and what stayed broken.

    10 min read

  3. Part 3

    From Prebuilt Agent to a Hand-Built StateGraph

    Rebuild the prebuilt create_agent loop with LangGraph's StateGraph: state, reducer, nodes, edges, ToolNode, a checkpointer, and what the prebuilt hid.

    8 min read

  4. Part 4

    Routing: One Agent per Tool Group

    Add a router node and one agent per tool group in LangGraph so a 7B model sees only the tools it needs. Covers conditional edges and what still goes wrong.

    10 min read

  5. Part 5

    Testing the Router with a Small Eval

    A 21-case eval for a small-model router: how it works, what a 100% score does and does not prove, and a sanity check that shows it can fail.

    10 min read

  6. Part 6

    Human Approval Before Write Tools with interrupt()

    Pause a LangGraph agent before it writes files: interrupt(), Command(resume=...), a real approve and deny run, and the bugs I hit along the way.

    12 min read

  7. Part 7

    Persistent Memory with SQLite, and Trimming What the Model Sees

    Swap LangGraph's in-memory checkpointer for SQLite so a local agent remembers across restarts, then trim old tool results so a 7B model keeps up.

    9 min read

  8. Part 8

    Making the Terminal Usable

    Replace pretty_print with a compact streaming display and silence noisy MCP server logs with a small wrapper, without touching the servers.

    8 min read

  9. Part 9

    Field Log: What Went Wrong and How I Fixed It

    Every failure from building a local LangGraph agent: a stale ChromeDriver that made the model say a site was down, invented dates, and more.

    10 min read

  10. Part 10

    From Starter to Production: Where to Go Next

    What this small LangGraph starter leaves out, a concrete list of next steps, and what I learned and would do differently.

    4 min read

langgraph langchain mcp local-llm lm-studio