MCP · Lesson 59 of 120
A Gemini Agent
Over MCP.
With the tools wrapped, a LangChain agent can use any MCP server. Create agent handles the whole loop for us, so our code gets very short.

- Wrapped tools
- create_agent
- Short code
An agent in a few lines
We load the Northwind tools, and give them to create agent, with a short system prompt. We ask a two part question. Run it. The agent called both tools, and answered both parts.
gemini_agent.pypython
import asyncio
from mcp import Client
from langchain.agents import create_agent
from mcp_tools import load_tools
from northwind import mcp
async def main():
async with Client(mcp) as client:
agent = create_agent("google_genai:gemini-flash-lite-latest", tools=await load_tools(client),
system_prompt="You are Northwind's support assistant. Be brief, plain text.")
q = "Has order 1043 shipped? And is delivery free on a £75 order?"
out = await agent.ainvoke({"messages": [{"role": "user", "content": q}]})
print("tools used:", [m.name for m in out["messages"] if m.type == "tool"])
print(out["messages"][-1].text)
asyncio.run(main())Output
tools used: ['order_status', 'delivery_cost'] Order 1043 has not shipped yet; it is currently packing. And yes, delivery is free on a £75 order.
Also uses northwind.py
from mcp.server.mcpserver import MCPServer
from mcp.server.mcpserver.exceptions import ToolError
mcp = MCPServer("northwind")
ORDERS = {1042: "shipped", 1043: "packing", 1044: "delivered"}
@mcp.tool()
def order_status(order_id: int) -> str:
"""Look up the status of a Northwind order by its number."""
if order_id not in ORDERS:
raise ToolError(f"Order {order_id} not found")
return ORDERS[order_id]
@mcp.tool()
def delivery_cost(order_total: float) -> str:
"""UK delivery cost for an order total in pounds."""
return "free" if order_total >= 50 else "£4.99"
@mcp.resource("policy://returns")
def returns_policy() -> str:
"""Northwind's returns policy."""
return "You can return any unused item within 30 days of delivery."
@mcp.prompt()
def support_reply(question: str) -> str:
"""Draft a polite reply to a customer."""
return f"Write a short, polite reply to this Northwind customer: {question}"
if __name__ == "__main__":
mcp.run()Also uses mcp_tools.py
from langchain_core.tools import StructuredTool
def to_langchain(client, t):
async def call(**args):
result = await client.call_tool(t.name, args)
return result.content[0].text
return StructuredTool(name=t.name, description=t.description,
args_schema=t.input_schema, coroutine=call)
async def load_tools(client):
listed = await client.list_tools()
return [to_langchain(client, t) for t in listed.tools]Why this matters
The agent knows nothing about Northwind's code. It only sees MCP tools. Swap in another server, and the same agent works with it. That's the whole promise of MCP.
| key | value |
|---|---|
| Agent knows | only MCP tools |
| Swap servers | same agent |
| Server knows | nothing about the model |
| Promise | build once |
Summary
A LangChain agent plus wrapped MCP tools gives a working assistant in a few lines. Next, choosing tools when there are many.
Key takeaways- create_agent
- load_tools
- Any server
Next up: Choosing Tools — when there are many