Agents with MCP Tools

You have a real MCP server. Now the agent uses it.

Same tool-call loop you already know — but each tool run goes across stdio to the server, not to a local Python function.


Use case

Customer: “Can I get a refund on order 4412? It arrived broken.”

The agent should:

  1. get_order → see amount $12, item laptop stand
  2. get_refund_policy → see “under $100 may auto-refund”
  3. Answer clearly (yes for this small order)
LLM loop + MCP tools.
  Customer question


   Agent (Gemini)
        │  tool call?

   MCP client  ──stdio──►  shoptiny_server


   Final reply

What changes vs in-process tools

In-process With MCP
TOOLS["get_order"](…) session.call_tool("get_order", …)
Same file as the agent Server can restart / live elsewhere
Hard to share across apps Any MCP client can attach

The model still only sees tool names and descriptions. MCP is how your code fetches the result.


What you should remember

  1. Discover tools with list_tools, then bind them for the model.
  2. On each tool call from the model, call MCP, return the result as the observation.
  3. Keep dangerous actions behind policy (later chapters) — MCP does not replace guardrails.

See it in Code

Paste your API key. Run the Python or TypeScript agent demo (official MCP + Gemini).
Java / Go are empty on this chapter — framework labs only.