WEBVTT

00:00.320 --> 00:00.840
Cool.

00:00.840 --> 00:06.680
So before we write our MCP clients, we want to first write our MCP servers.

00:06.680 --> 00:09.320
So we'll be able to connect them to our clients.

00:09.320 --> 00:12.760
And we're going to write two very simple MCP servers.

00:13.000 --> 00:19.720
One is going to expose mathematic tools to add numbers and multiply them, which is going to communicate

00:19.720 --> 00:21.000
via Stdio.

00:21.320 --> 00:28.400
And the other server is going to be a very dumbed down weather server, which is simply going to output

00:28.400 --> 00:28.640
that.

00:28.640 --> 00:29.960
It's very hot outside.

00:30.120 --> 00:36.880
But the interesting fact about this server is that it's going to communicate via SSH server sent events.

00:36.880 --> 00:40.000
And this is the first time we introduce how to do that.

00:40.000 --> 00:41.720
And I'll give you a very quick spoiler.

00:41.720 --> 00:43.040
It's going to be very easy.

00:43.760 --> 00:44.360
All righty.

00:44.360 --> 00:46.880
So let's go and create a new package.

00:46.880 --> 00:49.200
And I'm going to call it servers.

00:49.200 --> 00:50.960
So this is now a new directory.

00:50.960 --> 00:56.800
And let's make it a package by creating an empty underscore init.py file.

00:57.000 --> 00:59.480
So this is now our servers package here.

00:59.680 --> 01:05.240
And now I want to create a new file which I'm going to call math server dot Pi.

01:05.680 --> 01:11.840
And here we're going to have the implementation of an SMTP server, which exposes two tools, one to

01:11.880 --> 01:15.920
add numbers and the other tool to multiply those numbers.

01:15.920 --> 01:23.640
And by the way, when making this course, I started by naming this file math.pi and eventually what

01:23.640 --> 01:24.080
happened?

01:24.080 --> 01:30.840
It turns out that it collided with the built in math package in Python, and it really took me some

01:30.840 --> 01:32.040
time to figure it out.

01:32.040 --> 01:37.680
And once I gave up, I simply dumped my error to cursor and it was able to point that out.

01:37.920 --> 01:44.880
So the TLDR here called this file math server.py, because this is a very simple amqp server, and we've

01:44.880 --> 01:47.120
already done how to do very similar things.

01:47.160 --> 01:54.320
I'm simply going to copy paste it from the LinkedIn adapters repository, and we can skim this implementation

01:54.320 --> 01:54.600
here.

01:54.600 --> 01:56.640
And this is a very simple implementation.

01:56.640 --> 02:00.680
But what's important to note is this transport layer which is stdio.

02:01.320 --> 02:02.000
All right.

02:02.000 --> 02:05.320
So let me copy that and let's go to cursor and paste it.

02:05.560 --> 02:08.600
And let's try to run it now in our terminal.

02:10.120 --> 02:15.000
And I'm going to do it by running UV run server math server dot pi.

02:15.400 --> 02:20.050
We can see that it is running successfully with this blinking square over here.

02:23.090 --> 02:23.570
All right.

02:23.570 --> 02:28.490
So let's now create the second server which is going to be a server which outputs the weather.

02:28.490 --> 02:31.570
But it's going to be a very damped version of the server.

02:31.570 --> 02:34.810
And it's always going to output that it's hot as hell.

02:34.970 --> 02:37.650
So maybe it's going to be relevant only for Dubai.

02:37.890 --> 02:39.530
And here's a clip from me in Dubai.

02:39.930 --> 02:44.290
But the cool thing about this server, and this is the first time I was covering it, it's going to

02:44.290 --> 02:48.650
be a server which the transport is going to be via SSH.

02:48.850 --> 02:52.570
So it's going to be a server sent event MCP server.

02:52.570 --> 02:58.010
And this means that the communication between the client and the server, it's not going to happen via

02:58.050 --> 02:58.890
Stdio.

02:59.050 --> 03:01.210
It's going to happen via HTTP.

03:01.450 --> 03:05.450
And the client is going to make http post request to the server.

03:05.450 --> 03:08.970
And of course we don't really need to handle this communication over here.

03:08.970 --> 03:12.570
We get this out of the box when we use the MCP SDK.

03:13.410 --> 03:18.170
Just need to specify to the server that we want that the transport to be SSH.

03:18.410 --> 03:19.570
And this is super easy.

03:19.610 --> 03:22.610
It's just a flag that we pass when we run the server.

03:23.050 --> 03:23.810
Alrighty.

03:23.850 --> 03:26.850
So we're back in cursor and we want to create a new file.

03:26.850 --> 03:31.130
And let's call this file weather underscore server dot p y.

03:31.930 --> 03:35.410
And it's going to hold the implementation of our weather and CP.

03:35.730 --> 03:39.530
And let's go back to the link chain MCP open source.

03:39.730 --> 03:42.330
And let me copy this dummy server they have here.

03:42.610 --> 03:44.010
And I'm going to copy it.

03:44.010 --> 03:50.850
And we can see it's a very simple implementation of a server which exposes the Get weather tool.

03:51.050 --> 03:54.330
And it's going to return always the same static string.

03:54.730 --> 03:57.770
So just for the fun, let's go and change the string.

03:57.770 --> 04:01.810
And let's say that it is always hot as hell.

04:03.930 --> 04:04.810
Sorry about that.

04:04.810 --> 04:07.810
Let me just correct it to hot as hell.

04:08.010 --> 04:08.570
All right.

04:08.570 --> 04:11.210
So now we are done with the server.

04:11.210 --> 04:16.450
And the important thing to notice is that transport here the transport here is SSE.

04:16.930 --> 04:20.010
So this is how we communicate with this MCP server.

04:20.170 --> 04:22.690
And let me show you how it's different when we run it.

04:22.890 --> 04:30.330
If we go now and create a new terminal instance let me split here this view and let me run our UV run

04:30.330 --> 04:34.380
and then weather sorry servers weather server server.py.

04:35.660 --> 04:40.460
We can see now that the server is actually running in localhost port 8000.

04:40.900 --> 04:45.460
If we want to change the ports to run on a different port, we can totally do that.

04:45.460 --> 04:49.580
We simply need to specify and tell via the MCP SDK.

04:50.220 --> 04:53.460
And that's pretty much it for this video.

04:53.580 --> 05:01.220
So we created two simple web servers, one running in SDL and the other the transport is via SSH.

05:01.660 --> 05:04.780
So let's go and let's commit this code over here.

05:05.940 --> 05:09.580
So let me go now and see which files changed.

05:09.860 --> 05:11.660
Only the servers directory.

05:11.660 --> 05:12.780
And I added it.

05:13.100 --> 05:16.300
And let's go and use cursor to commit this code here.

05:17.100 --> 05:20.100
So cursor is going to auto generate the commit message.

05:21.540 --> 05:26.180
Let me commit that and let's push it to the repository.

05:27.740 --> 05:36.300
And if we go back now to the repository then we can see right now we have the new directory here.

05:36.300 --> 05:38.140
And we can see we have now two commits.

05:38.140 --> 05:41.860
We have the first commit from the previous video and this commit from this video.
