Building AI Agents with MCP, PydanticAI and OpenAI
Full workshop writeup
Pages, code repo, and split-level access for Main and above.
We build a course FAQ assistant from the bottom up. First we expose a
plain Python search(query) function to the OpenAI Responses API. Then
we turn the same idea into a reusable agent loop, compare toyaikit,
OpenAI Agents SDK, and PydanticAI, and finally move the FAQ tools behind
an MCP server that can be used from a notebook, PydanticAI, Cursor, and
VS Code.
Links
The main resources:
- Workshop recording
- Workshop code
- AI Bootcamp: From RAG to Agents
- Prerequisite workshop: Building a Coding Agent
- Data Engineering Zoomcamp FAQ source document
- Parsed FAQ JSON
- FAQ parsing notebook
The system you will build
The final setup looks like this:
The FAQ data comes from the Data Engineering Zoomcamp FAQ. The first
half of the workshop keeps the tools inside the notebook so you can see
the agent loop directly. The second half moves the same tools into
mcp_faq/, which makes them reusable by any MCP client.
Walkthrough
Follow the numbered files in order. Each file is self-contained enough to read on its own.
- Overview and setup - prerequisites, environment setup, and the shape of the project.
- Part 1: Load the FAQ documents - load the parsed FAQ, build a
minsearchindex, and create the firstsearchtool. - Part 2: Start with a plain model call - describe
searchto the OpenAI Responses API and run one manual tool-call round. - Part 3: Make the instructions stronger - add a developer prompt, support multiple tool calls, and turn the manual round into a loop.
- Part 4: Replace the loop with ToyAIKit - use
toyaikitto run the same loop with a notebook chat interface. - Part 5: Infer tool schemas from Python functions - infer schemas
from docstrings, add
add_entry, and move tool state into aSearchToolsclass. - Part 6: Install the framework - recreate the FAQ assistant with OpenAI Agents SDK.
- Part 7: Create the same agent with PydanticAI - recreate the assistant with PydanticAI and switch from OpenAI to Anthropic by changing the model string.
- Part 8: Move the FAQ tools into a project - create the
mcp_faqproject and expose the FAQ tools with FastMCP. - Part 9: Connect from Python over stdio - connect to the MCP server from Python, convert MCP tools for OpenAI, and use PydanticAI over SSE.
- Part 10: Use the FAQ server from Cursor - connect the same MCP server to Cursor and VS Code.
- Q&A - Q&A from the live workshop.
- Appendix: file list - file list and final command recap.