WEBVTT

00:00.120 --> 00:05.600
And it's great to be back in cursor for this big moment of making our own MCP server.

00:05.920 --> 00:06.320
All right.

00:06.320 --> 00:09.200
We're going into folder six of course.

00:09.240 --> 00:11.760
And first of all, well let me just bring you to the lab.

00:11.760 --> 00:12.360
Here we go.

00:12.400 --> 00:17.760
So week two, day two about to create and use our own MCP server and client.

00:17.800 --> 00:21.520
I do want to make the point that whilst this is pretty simple to do, it's not like it's incredibly

00:21.520 --> 00:22.120
straightforward.

00:22.120 --> 00:23.920
There is going to be some stuff.

00:24.160 --> 00:29.720
And the important thing to do, it's less about the magic of MCP, is less about whether it's easy to

00:29.760 --> 00:31.000
make your own server.

00:31.000 --> 00:34.680
It's more about how easy it is to share and use other people's servers.

00:34.680 --> 00:37.280
So keep that in again, that context in mind.

00:37.600 --> 00:43.080
The first thing we're going to do is go and look at some code in a in a Python module called accounts.

00:44.440 --> 00:45.840
And this is a code.

00:46.200 --> 00:51.560
This is a module which allows you to manage transactions.

00:51.560 --> 00:57.400
It will keep track of transactions for different people who are buying and selling shares.

00:57.640 --> 01:00.320
Um it has it's it's got a class account.

01:00.480 --> 01:08.630
And that class account has a account name a balance Strategy holdings, a list of transactions, and

01:08.630 --> 01:11.910
a time series of the portfolio value.

01:12.430 --> 01:14.910
So there's quite a lot to this.

01:15.190 --> 01:18.390
Um, and it's an interesting piece of code.

01:18.390 --> 01:26.390
You can buy shares, you can sell shares, you can calculate the portfolio value and do some other things

01:26.390 --> 01:26.870
here.

01:27.150 --> 01:33.550
Um, so a nice little utility for managing, buying and selling shares and maintaining an account.

01:33.550 --> 01:35.550
And maybe you know where this is going.

01:35.590 --> 01:41.950
But if you could cast your mind back a couple of weeks, this of course, this is the code that was

01:41.950 --> 01:45.430
written by our engineering team of agents.

01:45.630 --> 01:51.470
This is one that that, uh, is the fine work of our back end developer, our engineering lead.

01:51.470 --> 01:54.230
And somewhere there's also a test class to test this as well.

01:54.230 --> 01:55.670
And it's being tested.

01:55.710 --> 01:57.910
Now, of course, I've added in a few details here and there.

01:57.910 --> 02:02.670
I actually put in that time series thing I added in the strategy of the portfolio.

02:02.670 --> 02:07.310
So a couple of things I've just gone through and added in and I did, I think I did find a small bug

02:07.310 --> 02:08.630
that I had to fix as well.

02:08.910 --> 02:16.870
But generally speaking, this code was written by our engineering team of agents in Crew Week.

02:17.150 --> 02:19.190
And so this this was the result of week three.

02:19.190 --> 02:23.790
And so if you skipped week three, then you missed out because this was really cool, really fun.

02:23.790 --> 02:28.110
And you could see how to build an engineering team that writes code like this, builds a whole module

02:28.110 --> 02:30.350
and tests it on your behalf.

02:30.950 --> 02:35.790
The other thing I've added at the very top of it is I just put in some SQL which which I hadn't asked

02:35.790 --> 02:42.070
for in the original requirements, so that an account can be written and read from a SQLite database.

02:42.070 --> 02:44.470
But this is just Python code.

02:44.510 --> 02:50.270
This has got nothing to do with MCP, but it's a little tool, a set of tools, some useful code that

02:50.270 --> 02:56.350
we have written or well, we haven't written that our engineering team has written, and we want to

02:56.390 --> 02:59.270
now turn this into an MCP server.

02:59.270 --> 03:05.750
So we want to build an MCP server that can expose this functionality as tools with descriptions.

03:05.750 --> 03:08.670
So imagine you just got this off the shelf from your team.

03:08.670 --> 03:11.230
It's time to turn this into an MCP server.

03:11.230 --> 03:13.860
So this module was called accounts dot Pi.

03:13.900 --> 03:18.420
And for the MCP server I'm going to take you to accounts underscore server dot pi.

03:18.620 --> 03:24.300
So again this is us building our own MCP server to use.

03:24.500 --> 03:27.820
Take advantage of this code in accounts dot pi.

03:27.980 --> 03:29.060
And here it is.

03:29.060 --> 03:33.500
It's it's very short and it's mostly natural language as you might expect.

03:33.500 --> 03:39.060
It's text and it's, it's wrapper code to wrap our Python code.

03:39.060 --> 03:42.540
But you could equally well just have the Python code right here like you don't.

03:42.580 --> 03:45.420
You don't need to do it the way I've done it, but I've I've kept them separate.

03:45.420 --> 03:53.140
So you can clearly delineate the business logic in accounts dot pi from the MCP server in this accounts

03:53.180 --> 03:54.380
server dot pi.

03:54.700 --> 03:59.660
So this from MCP server fast import fast MCP.

04:00.180 --> 04:02.380
This is an anthropic code.

04:02.380 --> 04:04.740
This is nothing to do with OpenAI agents SDK.

04:04.940 --> 04:11.260
This is MCP code a way to build your own quickly build your own MCP server.

04:11.620 --> 04:17.490
And we are then importing Business logic accounts.

04:18.130 --> 04:22.210
We're importing the class account that was set in in that package.

04:22.330 --> 04:25.210
And as I say equally, you could just write the code right here.

04:25.210 --> 04:27.570
But but we're separating out the logic.

04:27.930 --> 04:34.250
So here's an example of a tool that we want to make available through our MCP server.

04:34.250 --> 04:36.050
And it is pretty simple.

04:36.050 --> 04:37.530
There's very little to it.

04:37.530 --> 04:41.010
You put a decorator MCP tool like that.

04:41.290 --> 04:45.810
And then here we have our the function that is going to become our tool.

04:46.010 --> 04:47.210
It's async.

04:47.570 --> 04:51.210
We we give it an the function name of course.

04:51.530 --> 04:53.890
And then this is the one parameter.

04:54.130 --> 04:57.970
We have docstrings to say what it does.

04:58.170 --> 05:01.610
And we use docstrings to state the parameters.

05:01.930 --> 05:08.410
And then this is the logic which in our case is just delegating to our business logic to get the name

05:08.410 --> 05:09.770
and return the balance.

05:09.770 --> 05:13.370
So that will become a get balanced tool.

05:13.410 --> 05:18.810
Given a name, it will create a new account for, or it will access the account for that person and

05:18.810 --> 05:19.880
get their balance.

05:20.200 --> 05:21.120
That's the tool.

05:21.400 --> 05:22.120
This is it.

05:22.160 --> 05:22.960
With this, we have.

05:23.000 --> 05:25.360
We could have we could just stick with get balanced.

05:25.360 --> 05:26.880
And that could be our MCP server.

05:26.880 --> 05:30.320
We're going to add some more functions but that's all there is to it.

05:30.600 --> 05:35.640
So then we're going to have like Get Holdings which just does the same thing for Holdings by shares

05:35.640 --> 05:36.840
which does the same thing.

05:37.000 --> 05:37.960
Sell shares.

05:38.280 --> 05:41.800
And then we've got a resource at the end of it.

05:41.800 --> 05:47.440
So I as I explained MCP servers have tools, resources and prompts.

05:47.480 --> 05:51.240
We're not going to cover prompts because they're just not not that that great to use.

05:51.240 --> 05:53.360
But it's very similar concept to this.

05:53.360 --> 06:02.160
But we've shown tools and used sometimes as resources and with resources you have like a, like a URL

06:02.200 --> 06:06.320
kind of construct that describes the resource that will be asked for.

06:06.520 --> 06:10.120
And I'm suggesting it's, you know, there's some discretion as to how you do this.

06:10.160 --> 06:13.920
You sort of put here what kind of thing are you talking about?

06:13.960 --> 06:17.680
And then your MCP server and then any arguments.

06:17.760 --> 06:20.560
So in our case we've got a URL we've constructed here.

06:20.560 --> 06:25.360
If someone looks for accounts Account server and then passes in someone's name.

06:25.560 --> 06:29.240
It will look up their account and return a report of it.

06:29.720 --> 06:31.960
So that is it.

06:32.120 --> 06:41.160
And if this is run, then it just calls MCP and it selects the transport as standard input output.

06:41.200 --> 06:46.760
The basic, simple uh, type that you use for local MCP servers.

06:47.240 --> 06:48.880
And this this is it.

06:48.880 --> 06:50.680
This is building your MCP server.

06:51.000 --> 06:52.200
That's all there is.

06:52.200 --> 06:55.560
You could do this yourself with just one tool and just see it working.

06:55.800 --> 06:56.640
You can also see.

06:56.640 --> 06:57.840
I hope you understand what I mean.

06:57.840 --> 07:03.400
We could equally have just simply put these decorators directly into accounts dot pi.

07:03.440 --> 07:04.960
We didn't really need the separation.

07:04.960 --> 07:12.000
We could have just put the MCP decorators all the way through this and instantly exposed these functions.

07:12.240 --> 07:14.120
I just separated out because that's a bit cleaner.

07:14.120 --> 07:19.720
And that means that you can apply this to any of your own code to build an MCP server just like that.

07:20.160 --> 07:26.160
Okay, if it's really that easy, then we should be able to just use this in our in our notebook.

07:26.440 --> 07:27.360
Let's see if we can.
