How to build an AI Agent and MCP Server (step-by-step) — Transcript
Full transcript
- 0:03[music]
- 0:04>> In this video, we are going to connect
- 0:06an AI agent to an MCP server. You will
- 0:09learn what an MCP server is, why it
- 0:12matters, and how to connect it to your
- 0:15ADK agent. By the end, your agent won't
- 0:18just write and plan, it will also pull
- 0:20from an external tool over MCP. So, what
- 0:23exactly is MCP?
- 0:25MCP stands for Model Context Protocol.
- 0:29That sounds complicated, but here's the
- 0:31simple idea. It's a standard way for
- 0:33agents to talk to external tools. Think
- 0:36of it like a translator. On one side,
- 0:38you have your agent, which is powered by
- 0:40a language model, and on the other side,
- 0:42you might have tools that do very
- 0:44specific things like looking up Google
- 0:46Trends, or querying a database, or
- 0:49running code. The agent itself can't do
- 0:51these things directly, so MCP sits in
- 0:54the middle. So, here's how it works. The
- 0:57tool runs as its own little program,
- 1:00usually in its own process. The agent
- 1:02connects to it over standard input and
- 1:04output. And then the agent asks, "What
- 1:07tools do you have?" The MCP server
- 1:09replies with a list of tool names, their
- 1:12arguments, and what they return. Then
- 1:14the agent says, "Okay, call this tool
- 1:17with these arguments." The tool runs,
- 1:20and the result comes back as JSON. The
- 1:23important part is how cleanly this is
- 1:25separated. Each tool runs in its own
- 1:28process, like its own program. The agent
- 1:31doesn't need to know how the tool is
- 1:33built, what libraries it uses, or even
- 1:35what language it's written in. As long
- 1:37as the tool speaks MCP, the agent can
- 1:40use it. So, why is this so powerful?
- 1:42First off, isolation. If a tool crashes,
- 1:45your agent doesn't go down with it.
- 1:48Secondly, it's interoperable. You could
- 1:50write tools in Python, Go, or Node, and
- 1:53the agent doesn't care. Third, it's
- 1:55discoverable.
- 1:57Tools that describe themselves in
- 1:58schemas, so agents can figure out at
- 2:01runtime how to use them. And finally,
- 2:03it's scalable. You can add more tools,
- 2:06swap them out, or version them without
- 2:09rewriting your entire agent code. So, if
- 2:12you think of the agent as the brain, MCP
- 2:14is the wire that connects it to its
- 2:17hands and and eyes in the real world.
- 2:19The brain decides what to do, MCP
- 2:21carries the request across, and the
- 2:24hands do the work.
- 2:25The results come back to the brain.
- 2:27That's the loop that makes agents more
- 2:29than just chatbots. In the last video,
- 2:32we built an agent that writes blog
- 2:34posts. You gave it a topic and it
- 2:36planned out the entire sections, wrote a
- 2:38draft, and even suggested alternative
- 2:40titles. If you haven't seen that yet,
- 2:43check out the first video or grab the
- 2:45link from the repository linked in the
- 2:47description box below. Now, that agent
- 2:49is great, but right now it only relies
- 2:52on the model. It doesn't know what's
- 2:54happening in the real world, what is
- 2:56trending, and what is in the news. So,
- 2:59in this video, we are going to connect
- 3:01it to an MCP server that pulls live data
- 3:04from Google Trends. That way, our
- 3:06blog-writing agent can ground its post
- 3:09in what's actually trending right now.
- 3:12Let's open the project directory and
- 3:14create a server.py file. You We are
- 3:17going to look at one Python file that
- 3:18does one job. It exposes a single tool
- 3:21called Trends over MCP, so our agent can
- 3:24call it in order to see what is trending
- 3:26on Google Trends. Think of this file as
- 3:28a tiny web service, but instead of HTTP,
- 3:31it talks over standard input and output
- 3:34using the Model Context Protocol. Let's
- 3:36zoom in on four pieces of code that make
- 3:39this MCP server work with our ADK agent.
- 3:43First, we wrap our plain Python function
- 3:45Trends as an ADK tool. This line is
- 3:48doing a lot for us. We wrote a normal
- 3:50Python function that takes JSON-friendly
- 3:52arguments and returns a JSON-friendly
- 3:55dictionary. Function tool inspects that
- 3:58function's signature and docstring, and
- 4:01it builds a schema and gives the tool a
- 4:03name. From this point on, ADK knows what
- 4:07arguments the tool expects and what it
- 4:09returns. So, there's no manual schema
- 4:12writing, which is needed. Next, we
- 4:14create the MCP server object. Think of
- 4:17this as a tiny program that sits between
- 4:20the agent and our tool. It speaks a
- 4:23model context protocol over standard
- 4:25input and output. The name is just an
- 4:27identifier the client will see during
- 4:29the handshake. Now, the two handlers
- 4:32that matter, which is listing tools and
- 4:35calling a tool. So, listing tools is how
- 4:38the agent discovers what this server can
- 4:41do, and when the agent connects to it,
- 4:43it asks, "What tools do you have?" We
- 4:46answer with a list containing one item,
- 4:49which is the trends tool, converted into
- 4:52an MCP tool schema. And then the helper
- 4:56ADK to MCP tool type function takes the
- 4:59ADK function tool metadata and turns it
- 5:02into exactly what the MCP client
- 5:04expects. That means the agent can see
- 5:07the tool's names, its parameters, their
- 5:10types, and description.
- 5:12Everything it needs to construct a valid
- 5:14call at runtime. The agent sends a tool
- 5:17name and a JSON dictionary of arguments.
- 5:20We sanity check the name and then
- 5:22forward those arguments straight into
- 5:24our Python function by calling run
- 5:27{underscore} async on the function tool.
- 5:30Whatever the function returns, we JSON
- 5:32dump it and then send it back as a text
- 5:35content payload. If anything goes wrong,
- 5:38we return a small JSON error and log the
- 5:41details to standard error. The important
- 5:44idea here is that the protocol is really
- 5:47simple.
- 5:48Name plus arguments in and JSON results
- 5:51out. Finally, we attach the server to
- 5:54standard input and output and run the
- 5:56handshake. This function opens the
- 5:58standard input-output transport and
- 6:01hands the read and write streams to the
- 6:04MCP server. Initialization options
- 6:06contain metadata and the capabilities
- 6:09that the client will see. In the main
- 6:11block, we call async io.run, which
- 6:14starts the server process. From there,
- 6:17ADK can launch the script, ask for the
- 6:20tools, and call trends like any other
- 6:22tool. Finally, in the main agent.py
- 6:25file, we just add trends_mcp
- 6:29to the root agents' list of tools, right
- 6:32next to the planner and the writer. From
- 6:35the agents' perspective, there's no
- 6:37difference. Calling trends looks exactly
- 6:40like calling a local function tool.
- 6:42But now, instead of making something up,
- 6:45the agent can fetch real trending
- 6:47queries before it starts writing a blog
- 6:49post. Now, let's open up ADK web UI with
- 6:53this command
- 6:54and interact with our agent that is now
- 6:56connected to the MCP server.
- 6:59And that's how you connect with your AI
- 7:01agent to an MCP server.
- 7:03We started with the blog writing agent
- 7:06from the last video, then added a new
- 7:08server that exposes a trend tool.
- 7:11[music]
- 7:12By wiring that into our root agent, we
- 7:14gave it the ability to pull in live
- 7:16Google Trends data before it even
- 7:18started writing. [music] This pattern is
- 7:20powerful because it keeps your agent
- 7:22lightweight while letting it reach out
- 7:24to the real world through external
- 7:25tools.
- 7:26Thank you for watching, and you can
- 7:28check out the description box below for
- 7:30all the resources and [music] code
- 7:31mentioned in this video. Check out the
- 7:33next video to learn how to build
- 7:35multi-agent systems with ADK.
- 7:42>> We are one.
- 7:45We are one.
- 7:46>> [music]
- 7:47>> We are one.
- 7:50We are one.
- 7:52We are one.
About this transcript
This page contains the full transcript of How to build an AI Agent and MCP Server (step-by-step) by Google Cloud Tech, generated from the public captions YouTube serves with the video. The transcript has 1,256 words across 190 segments, with the original timestamps preserved so you can click any line to jump to that moment in the embedded player.
What you can do with it
Use the transcript to take notes, quote the speaker, build a study guide, generate a summary with ChatGPT or Claude via the YouTube Summary tool, or export it as a timed subtitle file with YouTube to SRT. You can also re-open it in the transcriber to translate the transcript into 100+ languages.
Free YouTube transcript tool
YouTube2Text is a free YouTube transcript generator — no signup, no daily limit. Paste any YouTube link and get the full transcript instantly, with timestamps, click-to-jump, translation to 100+ languages, AI prompts for ChatGPT, Claude, and Gemini, and exports to TXT, SRT, VTT, or Markdown.