Starting…

No run yet. Write your code, then click Run.

Lesson

MCP, connecting external tools

Already connecting an MCP client and calling remote tools? Skip to the next lesson.

So far every tool has been a function you wrote. Now the tool belongs to someone else, and lives on another machine.

The idea

MCP stands for Model Context Protocol. It is an agreed way for one program to ask another "what tools do you have?" and then use them.

Your agent is the client. The other system, the ticket system here, runs the server. Whoever owns ticketing maintains the tool, and every agent in the company can use it without anyone copying a description around.

Discovery is the whole point

Look at how tool descriptions have arrived so far:

  • Module 3: you wrote the JSON by hand
  • Module 14: MAF built it from your function
  • Here: you ask the server and it tells you
tickets = MCPStreamableHTTPTool(name="tickets", url=MCP_SERVER_URL)
print(tickets.list_tools())

That is the difference worth understanding. The server is the source of truth about what it offers, so it can add a tool tomorrow and you do not redeploy.

Two practical notes

Transport is how you reach the server. Use https for a remote one. stdio is for a server running as a program on the same machine.

Trust. A tool description is text written by another system, and it goes straight into your model's prompt. Treat a third-party MCP server the way you would treat any other input you did not write.

What to write

  1. Build the chat client as in Module 14
  2. Build the MCP tool against MCP_SERVER_URL
  3. Call list_tools() and print what comes back
  4. Pass the MCP tool into create_agent(tools=[...]) and run it

The point

MCP is a socket for tools. Your agent loop does not change at all.

Break it on purpose

Hand the tool to the agent without calling list_tools() first, and read the error. Then point the URL at http:// instead of https://.

Check yourself

Answer out loud first. Reading the answer without trying is where the learning leaks out.

  1. 1. Who implements the tool body, your agent or the MCP server?

  2. 2. When would you pick stdio over sse?

  3. 3. What stays the same in your agent loop when tools arrive via MCP?