WEBVTT

00:00.160 --> 00:03.560
And so we create another a new agent.

00:03.600 --> 00:05.200
The name is account manager.

00:05.240 --> 00:08.760
The instructions as are system prompt, the model as the model.

00:08.760 --> 00:10.120
And the tools we're passing in.

00:10.120 --> 00:12.520
We're no longer passing in an MCP server.

00:12.560 --> 00:17.120
We're passing in the tools that we've just reconstituted here.

00:17.440 --> 00:21.480
And the thing and this might be a little bit of a of a of a leap.

00:21.520 --> 00:28.880
The thing to keep in mind is that within those tools there is the function to be called, and that function

00:28.880 --> 00:31.440
to be called if the tool needs to be triggered.

00:31.560 --> 00:36.760
If I go back to the client, the function to be called that we've set up here, you'll need to look

00:36.760 --> 00:37.800
through this code.

00:38.000 --> 00:45.040
But it is to to to call back to this call accounts tool with the tool name in question and its arguments.

00:45.440 --> 00:53.080
So the bottom line is that if the LM chooses to run one of these tools, that's going to end up calling

00:53.240 --> 00:59.360
our MCP client, which is going to call our MCP server, which is going to call our business logic for

00:59.400 --> 01:00.920
that particular tool.

01:01.130 --> 01:05.970
All of that is going to happen, but this time it's going through our MCP client.

01:06.370 --> 01:08.330
And so we're still asking the same question.

01:08.330 --> 01:10.890
We're asking the my name is Ed.

01:10.930 --> 01:11.930
My account is under the name Ed.

01:11.930 --> 01:14.090
What's my balance and my holdings.

01:14.090 --> 01:20.130
But rather than using the MCP client that OpenAI provides us, we've built our own.

01:20.370 --> 01:22.370
And let's see if it works.

01:22.410 --> 01:29.170
So now going through our MCP client, spawning the MCP server and we get back the right balance.

01:29.170 --> 01:31.130
And that I have three shares of Amazon.

01:31.130 --> 01:35.770
So yes it works going through our MCP client and server together.

01:36.210 --> 01:39.730
And I can also show you how what it looks like to read a resource.

01:39.730 --> 01:46.650
So it's using the read accounts resource method function that we have in our client right here.

01:46.810 --> 01:54.370
Read accounts resource which launches a client uh and then creates a session with a server.

01:54.370 --> 02:01.370
So a Python process will launch to run this code right here, which is going to run our MCP server,

02:01.410 --> 02:03.970
which within it imports our business logic.

02:04.450 --> 02:11.490
And then we're going to call Read resource with this with Ed instead of name with this.

02:11.490 --> 02:14.370
And that is going to go to the server on the server.

02:14.370 --> 02:18.650
It's going to call this this read resource function.

02:18.650 --> 02:19.850
You see right here.

02:19.850 --> 02:25.890
And because name is is in the decorator at that point, that is how name is going to be provided.

02:25.890 --> 02:29.650
That is going to call account dot get for the name okay.

02:29.690 --> 02:30.690
What does that do.

02:30.810 --> 02:36.210
Let's go in here that calls uh this method get right here.

02:36.610 --> 02:38.570
And then it will call report on that.

02:38.570 --> 02:43.970
And you can see that the report down here is going to return a string representing the account.

02:43.970 --> 02:48.170
So that is the chain of events that's going to happen if it all works.

02:48.170 --> 02:51.010
When I simply call read accounts resource.

02:51.290 --> 02:54.290
And let's see and there is the result.

02:55.410 --> 03:00.690
And now if you're following all this, if you're not following all this it doesn't massively matter.

03:00.690 --> 03:07.420
The purpose of this is to show you the what goes on behind the scenes, the plumbing behind MCP.

03:08.180 --> 03:13.140
If you are following all this, you might be thinking to yourself, hang on a second.

03:13.420 --> 03:24.020
Okay, I see this, but surely I can also just say from accounts import account like the way it does

03:24.020 --> 03:30.380
that account get from accounts, accounts get report.

03:30.420 --> 03:33.540
I can just run that and I'll get the same thing.

03:34.500 --> 03:35.900
And you're absolutely right.

03:35.900 --> 03:36.500
You can.

03:36.540 --> 03:41.620
This is a rather faster way of doing it than going through an MCB client to an MCP server, to launching

03:41.620 --> 03:47.180
a Python process, to attaching to its input and output, to making that same call and to bringing back

03:47.180 --> 03:48.340
all of the results.

03:48.340 --> 03:55.540
And that's why I say that the magic of MCP is more about how this allows you to share tools and resources

03:55.540 --> 04:01.420
across different places, because if you're just writing it for your own purpose, then this just writing

04:01.420 --> 04:05.620
the business logic and just getting the resource is an easier way to do it, frankly.

04:06.260 --> 04:13.260
The reason you would want to build all of this scaffolding around MCP is because then you've got this

04:13.260 --> 04:22.420
consistent, universal USB-C way that anybody can read the ads account details, uh, just using this

04:22.460 --> 04:23.140
interface.

04:23.140 --> 04:24.580
And that's the big point.

04:25.420 --> 04:28.660
And so for the exercises to wrap it up, a couple of them here.

04:28.700 --> 04:30.700
Make your own MCP server.

04:30.740 --> 04:32.620
There's something you could do that's really simple.

04:32.620 --> 04:38.740
You can make a Python function to return the current date, expose it as an MCP tool, bring it into

04:38.740 --> 04:42.620
an agent and ask the agent the current date and make sure it works all the way through.

04:42.900 --> 04:46.980
It's easy to do, and it's really nice to show you to connect the dots.

04:47.100 --> 04:52.820
And then optionally, if you wanted, you could put an MCP client on top of that as well.

04:52.820 --> 04:54.140
So you can go through an MCP client.

04:54.140 --> 05:01.940
And then what you could do is use a native approach for calling OpenAI's code directly, just as we

05:02.070 --> 05:03.110
did in week one.

05:03.110 --> 05:10.270
Go through and make the JSON stuff and use the handle tool calls and see it working that way through

05:10.310 --> 05:16.910
your client and server so you're not taking advantage of the stuff that comes with the OpenAI agents

05:16.950 --> 05:17.510
SDK.

05:17.630 --> 05:22.750
And then you will really have seen you'll have connected the dots all the way through to what's going

05:22.750 --> 05:25.550
on behind the scenes, but that's an optional exercise.

05:25.550 --> 05:27.870
If you if you get it, you don't need to do that unless you really want to.

05:27.910 --> 05:29.030
The gory detail.

05:29.030 --> 05:35.910
But hopefully this lab has helped you to understand how things work behind the scenes and what it is

05:35.910 --> 05:39.830
that MCP is so good at, and where you perhaps don't need it as much.

05:39.990 --> 05:45.510
Well, with that, we've built an MCP server and MCP client, and we've used it with an agent, and

05:45.510 --> 05:46.630
it was great.

05:47.110 --> 05:51.910
And I hope you now have a pretty decent understanding of how to connect the dots.

05:52.190 --> 05:59.230
Next time we're just going to go crazy and use a bunch of local and remote MCP servers to get to get

05:59.230 --> 06:01.590
into this and to enjoy the ecosystem.

06:01.870 --> 06:03.110
I will see you then.
