[00:04] In this video, we are going to connect an AI agent to an MCP [00:08] server. [00:09] You will learn what an MCP server is, why it matters, [00:13] and how to connect it to your ADK agent. [00:16] By the end, your agent won't just write and plan, [00:20] it will also pull from an external tool over MCP. [00:23] So what exactly is MCP. [00:25] MCP stands for Model context protocol. [00:29] That sounds complicated, but here's the simple idea. [00:32] It's a standard way for agents to talk to external tools. [00:36] Think of it like a translator. [00:38] On one side, you have your agent, which [00:40] is powered by a language model. [00:41] And on the other side, you might have [00:43] tools that do very specific things, looking up Google Trends [00:47] or querying a database or running code. [00:50] The agent itself can't do these things directly, [00:53] so MCP sits in the middle. [00:55] So here's how it works. [00:57] The tool runs as its own little program, [01:00] usually in its own process. [01:01] The agent connects to it over a standard input and output, [01:05] and then the agent asks, what tools do you have. [01:08] The MCP server replies with a list of tool names, [01:12] their arguments, and what they return. [01:14] Then the agent says, OK, call this tool. [01:17] With these arguments, the tool runs [01:20] and the result comes back as JSON. [01:23] The important part is how cleanly this is separated. [01:26] Each tool runs in its own process, like its own program. [01:30] The agent doesn't need to know how [01:32] the tool is built, what libraries it uses, [01:35] or even what language it's written in. [01:37] As long as the tool speaks MCP, the agent can use it. [01:41] So why is this so powerful. [01:42] First off, isolation. [01:44] If a tool crashes, your agent doesn't go down with it. [01:48] Secondly, it's interoperable. [01:50] You could write tools in Python go or node [01:53] and the agent doesn't care. [01:55] Third, it's discoverable tools describe themselves in schemas [01:59] so agents can figure out at runtime how to use them. [02:03] And finally, it's scalable. [02:05] You can add more tools, swap them out, [02:07] or version them without rewriting your entire agent [02:10] code. [02:11] So if you think of the agent as the brain, [02:14] MCP is the wire that connects it to its hands [02:18] and eyes in the real world, the brain decides what to do. [02:21] MCP carries the request across and the hands do the work. [02:25] The results come back to the brain. [02:27] That's the loop that makes agents more than just chatbots. [02:31] In the last video, we built an agent that writes blog posts. [02:35] You gave it a topic and it planned out the entire sections, [02:38] wrote a draft, and even suggested alternative titles. [02:41] If you haven't seen that yet, check out the first video [02:44] or grab the link from the repository LinkedIn [02:47] the description box below. [02:48] Now that agent is great, but right now [02:51] it only relies on the model. [02:53] It doesn't know what's happening in the real world, what [02:56] is trending and what is in the news. [02:59] So in this video, we are going to connect it [03:01] to an MCP server that pulls live data from Google Trends. [03:06] That way, our blog writing agent can ground its posts [03:09] in what's actually trending right now. [03:12] Let's open the project directory and create a file. [03:17] We are going to look at one Python file that does one job. [03:20] It exposes a single tool called trends over MCP. [03:23] So our agent can call it in order [03:25] to see what is trending on Google Trends. [03:27] Think of this file as a tiny web service, but instead of HTTP, [03:31] it talks over a standard input and output using the model [03:35] context protocol. [03:36] Let's Zoom in on four pieces of code [03:38] that make this MCP server work with our ADK agent. [03:43] First, we wrap our plain Python function trends as an SDK tool. [03:48] This line is doing a lot for us. [03:49] We wrote a normal Python function [03:51] that takes JSON friendly arguments and returns a JSON [03:55] friendly dictionary function tool inspects that function's [03:59] signature and docstring, and it builds a schema [04:02] and gives the tool a name. [04:04] From this point on, ADK knows what arguments a tool expects [04:09] and what it returns, so there's no manual schema [04:12] writing which is needed. [04:13] Next, we create the MCP server object. [04:16] Think of this as a tiny program that sits [04:19] between the agent and our tool. [04:22] It speaks the model context protocol over a standard input [04:25] and output. [04:26] The name is just an identifier. [04:28] The client will see during the handshake. [04:30] Now the two handlers that matter which [04:33] is listing tools and calling a tool. [04:36] So listing tools is how the agent discovers [04:40] what this server can do. [04:41] And when the agent connects to it, [04:43] it asks, what tools do you have. [04:46] We answer with a list containing 1 item, which [04:50] is the trends tool. [04:51] Convert it into an MCP tool schema [04:54] and then the helper ADK to MCP tool type [04:58] function takes the ADK function tool metadata [05:01] and turns it into exactly what the MCP client expects. [05:05] That means the agent can see the tools names, its parameters, [05:09] their types, and a description everything [05:12] it needs to construct a valid call at runtime. [05:16] The agent sends a tool name and a JSON dictionary of arguments. [05:20] We sanity check the name and then forward [05:23] those arguments straight into our Python function [05:26] by calling async on the function tool. [05:30] Whatever the function returns, we [05:32] JSON dump it and then send it back as a text content payload. [05:37] If anything goes wrong, we return a small JSON error [05:40] and log the details to standard error. [05:43] The important idea here is that the protocol is really simple. [05:48] Name plus arguments in and JSON results out. [05:52] Finally, we attach the server to standard input and output [05:56] and run the handshake. [05:57] This function opens the standard input output [06:00] transport and hence the read and write streams to the MCP server. [06:05] Initialization options contain metadata and the capabilities [06:09] that the client will see in the main block. [06:12] We call async I/O run, which starts the server process [06:16] from there. [06:17] ADK can launch the script, ask for the tools, [06:20] and call trends like any other tool. [06:23] Finally, in the main agent py file, [06:26] we just add trends MCP to the root agents list of tools [06:32] right next to the planner and the writer. [06:35] From the agent's perspective, there's no difference. [06:38] Calling trends looks exactly like calling a local function [06:42] tool. [06:42] But now, instead of making something up, [06:45] the agent can fetch real trending queries [06:48] before it starts writing a blog post. [06:50] Now let's open up ADK web UI with this command [06:54] and interact with our agent that is now [06:57] connected to the MCP server. [06:59] And that's how you connect with your AI agent to an MCP server. [07:03] We started with the blog writing agent from the last video, [07:07] then added a new server that exposes a trend tool by wiring [07:13] that into our root agent. [07:14] We gave it the ability to pull in live Google Trends data [07:18] before it even started writing. [07:19] This pattern is powerful because it keeps your agent lightweight [07:22] while letting it reach out to the real world [07:25] through external tools. [07:26] Thank you for watching, and you can check out the description [07:29] box below for all the resources and code [07:31] mentioned in this video. [07:33] Check out the next video to learn [07:34] how to build multi-agent systems with SDK.