YouTube2Text

How to build an AI Agent and MCP Server (step-by-step) — Transcript

by Google Cloud Tech · 1,256 words · 190 segments · language en · Watch on YouTube

Full transcript

  1. 0:03[music]
  2. 0:04>> In this video, we are going to connect
  3. 0:06an AI agent to an MCP server. You will
  4. 0:09learn what an MCP server is, why it
  5. 0:12matters, and how to connect it to your
  6. 0:15ADK agent. By the end, your agent won't
  7. 0:18just write and plan, it will also pull
  8. 0:20from an external tool over MCP. So, what
  9. 0:23exactly is MCP?
  10. 0:25MCP stands for Model Context Protocol.
  11. 0:29That sounds complicated, but here's the
  12. 0:31simple idea. It's a standard way for
  13. 0:33agents to talk to external tools. Think
  14. 0:36of it like a translator. On one side,
  15. 0:38you have your agent, which is powered by
  16. 0:40a language model, and on the other side,
  17. 0:42you might have tools that do very
  18. 0:44specific things like looking up Google
  19. 0:46Trends, or querying a database, or
  20. 0:49running code. The agent itself can't do
  21. 0:51these things directly, so MCP sits in
  22. 0:54the middle. So, here's how it works. The
  23. 0:57tool runs as its own little program,
  24. 1:00usually in its own process. The agent
  25. 1:02connects to it over standard input and
  26. 1:04output. And then the agent asks, "What
  27. 1:07tools do you have?" The MCP server
  28. 1:09replies with a list of tool names, their
  29. 1:12arguments, and what they return. Then
  30. 1:14the agent says, "Okay, call this tool
  31. 1:17with these arguments." The tool runs,
  32. 1:20and the result comes back as JSON. The
  33. 1:23important part is how cleanly this is
  34. 1:25separated. Each tool runs in its own
  35. 1:28process, like its own program. The agent
  36. 1:31doesn't need to know how the tool is
  37. 1:33built, what libraries it uses, or even
  38. 1:35what language it's written in. As long
  39. 1:37as the tool speaks MCP, the agent can
  40. 1:40use it. So, why is this so powerful?
  41. 1:42First off, isolation. If a tool crashes,
  42. 1:45your agent doesn't go down with it.
  43. 1:48Secondly, it's interoperable. You could
  44. 1:50write tools in Python, Go, or Node, and
  45. 1:53the agent doesn't care. Third, it's
  46. 1:55discoverable.
  47. 1:57Tools that describe themselves in
  48. 1:58schemas, so agents can figure out at
  49. 2:01runtime how to use them. And finally,
  50. 2:03it's scalable. You can add more tools,
  51. 2:06swap them out, or version them without
  52. 2:09rewriting your entire agent code. So, if
  53. 2:12you think of the agent as the brain, MCP
  54. 2:14is the wire that connects it to its
  55. 2:17hands and and eyes in the real world.
  56. 2:19The brain decides what to do, MCP
  57. 2:21carries the request across, and the
  58. 2:24hands do the work.
  59. 2:25The results come back to the brain.
  60. 2:27That's the loop that makes agents more
  61. 2:29than just chatbots. In the last video,
  62. 2:32we built an agent that writes blog
  63. 2:34posts. You gave it a topic and it
  64. 2:36planned out the entire sections, wrote a
  65. 2:38draft, and even suggested alternative
  66. 2:40titles. If you haven't seen that yet,
  67. 2:43check out the first video or grab the
  68. 2:45link from the repository linked in the
  69. 2:47description box below. Now, that agent
  70. 2:49is great, but right now it only relies
  71. 2:52on the model. It doesn't know what's
  72. 2:54happening in the real world, what is
  73. 2:56trending, and what is in the news. So,
  74. 2:59in this video, we are going to connect
  75. 3:01it to an MCP server that pulls live data
  76. 3:04from Google Trends. That way, our
  77. 3:06blog-writing agent can ground its post
  78. 3:09in what's actually trending right now.
  79. 3:12Let's open the project directory and
  80. 3:14create a server.py file. You We are
  81. 3:17going to look at one Python file that
  82. 3:18does one job. It exposes a single tool
  83. 3:21called Trends over MCP, so our agent can
  84. 3:24call it in order to see what is trending
  85. 3:26on Google Trends. Think of this file as
  86. 3:28a tiny web service, but instead of HTTP,
  87. 3:31it talks over standard input and output
  88. 3:34using the Model Context Protocol. Let's
  89. 3:36zoom in on four pieces of code that make
  90. 3:39this MCP server work with our ADK agent.
  91. 3:43First, we wrap our plain Python function
  92. 3:45Trends as an ADK tool. This line is
  93. 3:48doing a lot for us. We wrote a normal
  94. 3:50Python function that takes JSON-friendly
  95. 3:52arguments and returns a JSON-friendly
  96. 3:55dictionary. Function tool inspects that
  97. 3:58function's signature and docstring, and
  98. 4:01it builds a schema and gives the tool a
  99. 4:03name. From this point on, ADK knows what
  100. 4:07arguments the tool expects and what it
  101. 4:09returns. So, there's no manual schema
  102. 4:12writing, which is needed. Next, we
  103. 4:14create the MCP server object. Think of
  104. 4:17this as a tiny program that sits between
  105. 4:20the agent and our tool. It speaks a
  106. 4:23model context protocol over standard
  107. 4:25input and output. The name is just an
  108. 4:27identifier the client will see during
  109. 4:29the handshake. Now, the two handlers
  110. 4:32that matter, which is listing tools and
  111. 4:35calling a tool. So, listing tools is how
  112. 4:38the agent discovers what this server can
  113. 4:41do, and when the agent connects to it,
  114. 4:43it asks, "What tools do you have?" We
  115. 4:46answer with a list containing one item,
  116. 4:49which is the trends tool, converted into
  117. 4:52an MCP tool schema. And then the helper
  118. 4:56ADK to MCP tool type function takes the
  119. 4:59ADK function tool metadata and turns it
  120. 5:02into exactly what the MCP client
  121. 5:04expects. That means the agent can see
  122. 5:07the tool's names, its parameters, their
  123. 5:10types, and description.
  124. 5:12Everything it needs to construct a valid
  125. 5:14call at runtime. The agent sends a tool
  126. 5:17name and a JSON dictionary of arguments.
  127. 5:20We sanity check the name and then
  128. 5:22forward those arguments straight into
  129. 5:24our Python function by calling run
  130. 5:27{underscore} async on the function tool.
  131. 5:30Whatever the function returns, we JSON
  132. 5:32dump it and then send it back as a text
  133. 5:35content payload. If anything goes wrong,
  134. 5:38we return a small JSON error and log the
  135. 5:41details to standard error. The important
  136. 5:44idea here is that the protocol is really
  137. 5:47simple.
  138. 5:48Name plus arguments in and JSON results
  139. 5:51out. Finally, we attach the server to
  140. 5:54standard input and output and run the
  141. 5:56handshake. This function opens the
  142. 5:58standard input-output transport and
  143. 6:01hands the read and write streams to the
  144. 6:04MCP server. Initialization options
  145. 6:06contain metadata and the capabilities
  146. 6:09that the client will see. In the main
  147. 6:11block, we call async io.run, which
  148. 6:14starts the server process. From there,
  149. 6:17ADK can launch the script, ask for the
  150. 6:20tools, and call trends like any other
  151. 6:22tool. Finally, in the main agent.py
  152. 6:25file, we just add trends_mcp
  153. 6:29to the root agents' list of tools, right
  154. 6:32next to the planner and the writer. From
  155. 6:35the agents' perspective, there's no
  156. 6:37difference. Calling trends looks exactly
  157. 6:40like calling a local function tool.
  158. 6:42But now, instead of making something up,
  159. 6:45the agent can fetch real trending
  160. 6:47queries before it starts writing a blog
  161. 6:49post. Now, let's open up ADK web UI with
  162. 6:53this command
  163. 6:54and interact with our agent that is now
  164. 6:56connected to the MCP server.
  165. 6:59And that's how you connect with your AI
  166. 7:01agent to an MCP server.
  167. 7:03We started with the blog writing agent
  168. 7:06from the last video, then added a new
  169. 7:08server that exposes a trend tool.
  170. 7:11[music]
  171. 7:12By wiring that into our root agent, we
  172. 7:14gave it the ability to pull in live
  173. 7:16Google Trends data before it even
  174. 7:18started writing. [music] This pattern is
  175. 7:20powerful because it keeps your agent
  176. 7:22lightweight while letting it reach out
  177. 7:24to the real world through external
  178. 7:25tools.
  179. 7:26Thank you for watching, and you can
  180. 7:28check out the description box below for
  181. 7:30all the resources and [music] code
  182. 7:31mentioned in this video. Check out the
  183. 7:33next video to learn how to build
  184. 7:35multi-agent systems with ADK.
  185. 7:42>> We are one.
  186. 7:45We are one.
  187. 7:46>> [music]
  188. 7:47>> We are one.
  189. 7:50We are one.
  190. 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.