WEBVTT

00:00.280 --> 00:06.000
And now we're going to look at the second configuration, which is when we have a local MCP server that's

00:06.000 --> 00:08.280
going to call out to a web service remotely.

00:08.280 --> 00:11.960
And of course, we have actually already done this with some prior examples.

00:11.960 --> 00:14.280
But put that to one side, we're going to still do another one.

00:14.320 --> 00:19.960
And the one we're going to choose is called Brave Search, which is another of these, uh, web search

00:20.120 --> 00:20.960
APIs.

00:21.120 --> 00:25.160
And apologies, I'm going to ask you to set up another one with another API key.

00:25.200 --> 00:30.880
It's free again, which is a good thing, but sorry for the hassle of this, but this is another of

00:30.880 --> 00:31.840
the MCP servers.

00:31.840 --> 00:34.800
That's a reference implementation from anthropic.

00:34.800 --> 00:40.440
So it's a nice one for us to add to our arsenal of these MCP servers.

00:40.760 --> 00:47.000
So there's a link here to Brave Search API, which takes you to the Brave Search API.

00:47.160 --> 00:50.920
And you will need to sign up the first time a couple of screens to get through.

00:50.960 --> 00:56.400
Once you've done that, you arrive somewhere like here, where you can then go to API keys to set up

00:56.400 --> 00:57.320
an API key.

00:57.520 --> 01:01.400
And as soon as you've done that, you will be able to then use this.

01:01.400 --> 01:09.470
You'll have to add that to AP to to um, this brave underscore API underscore key to your env.

01:09.790 --> 01:11.390
And then you'll be good to go.

01:11.790 --> 01:14.510
And so this shows how we pass in these API keys.

01:14.510 --> 01:19.350
We set up a variable called env which is a dictionary which has brave API key.

01:19.510 --> 01:24.270
And as the value we put in the brave API key, you might want to just print that to make sure that yours

01:24.310 --> 01:25.630
is being set properly.

01:25.950 --> 01:29.630
And then we call MPG as before.

01:29.950 --> 01:36.710
The arguments we pass in is going to be again it's a it's an official package from anthropic.

01:36.750 --> 01:38.510
It's called server brave search.

01:38.710 --> 01:42.030
And we pass in the environment variable and we will get it to list its tools.

01:42.030 --> 01:43.070
Let's have a look at them.

01:43.710 --> 01:45.350
See what we've got access to.

01:45.470 --> 01:46.190
Here we go.

01:47.230 --> 01:49.430
And you can see there's a web search.

01:49.430 --> 01:54.430
There's also something called Brave Local Search which will look for local businesses to you which might

01:54.430 --> 01:55.070
be useful.

01:55.630 --> 01:57.470
But we're going to say instructions.

01:57.470 --> 01:58.870
This is the system prompt.

01:58.870 --> 02:03.900
You're able to search the web for information and briefly summarize the takeaways and then the user

02:03.900 --> 02:04.500
prompt.

02:04.540 --> 02:09.980
Please research the latest news on Amazon's stock price and briefly summarize its outlook.

02:10.020 --> 02:14.140
For context, this is the current date and we give it a model.

02:14.540 --> 02:16.540
Okay so let's run that.

02:16.540 --> 02:18.340
And here we go again.

02:18.340 --> 02:22.660
So it's of course exactly the same as far as MCP is concerned.

02:22.860 --> 02:24.340
It's the same functionality.

02:24.380 --> 02:30.220
It doesn't care whether the process that we're going to spawn the the process, whether that is going

02:30.220 --> 02:35.060
to be, uh, calling out to a web service or just running something locally like before, it's all the

02:35.060 --> 02:35.980
same to it.

02:35.980 --> 02:37.060
So we can run this.

02:37.100 --> 02:42.780
It's hopefully now going to go and collect, go and have a look for the stock price, do some research,

02:42.980 --> 02:44.300
come back with an answer.

02:44.540 --> 02:48.100
Here's the summary of news and outlook of Amazon stock price.

02:48.380 --> 02:50.780
Uh you can see a bunch of stuff.

02:50.780 --> 02:52.740
It's trading around 195.

02:52.900 --> 02:55.020
Jefferies has lowered their target price.

02:55.180 --> 02:57.300
So that all sounds interesting.

02:57.500 --> 03:00.500
Let's go and look at the trace to see whether this is credible.

03:00.940 --> 03:05.450
Uh, go into conversation and see that it got the tools.

03:05.450 --> 03:13.090
It ran a brave web search and it got back some news on Amazon's stock price that it then lots of stuff.

03:13.130 --> 03:16.010
It then used that of course in its response.

03:16.170 --> 03:17.730
So that's a good sign.

03:17.730 --> 03:19.250
It seems to be working well.

03:19.290 --> 03:24.530
And so again the thing to keep in mind is how easy it is to suddenly pull in new capabilities into our

03:24.530 --> 03:25.810
agent framework.

03:26.130 --> 03:31.650
Again, you could you could argue, okay, but it's not so different to being able to pull in capabilities

03:31.650 --> 03:33.290
from long chains, tools say.

03:33.570 --> 03:38.850
And the only difference is we've just got access to such a bigger pool of tools and capabilities to

03:38.890 --> 03:43.250
choose from the thousands that we saw on those different marketplaces.

03:43.290 --> 03:48.010
Long chain has lots, but but, uh, the MCP community is even bigger.

03:48.450 --> 03:54.370
Okay, so now is the third one, which is a bit different, which is running remotely.

03:54.690 --> 03:59.130
And here we have uh, we are going to use this one.

03:59.170 --> 04:00.410
Let me bring this up.

04:00.570 --> 04:04.090
So this is the Alpha Vantage stock server.

04:04.330 --> 04:10.360
Alpha vantage gives real time and historic market prices, equity prices like the price of Amazon stock.

04:10.600 --> 04:16.520
And as long as you stick to a certain number a day, it's free and you don't need a credit card to sign

04:16.520 --> 04:16.880
up.

04:17.000 --> 04:19.240
And if you go more than that, you just don't get back a response.

04:19.280 --> 04:21.240
So there's no there's no charge or anything like that.

04:21.240 --> 04:25.880
So it's free service for stock prices, which is convenient for us.

04:26.160 --> 04:29.360
Uh, and this is an MCP server to use it.

04:29.360 --> 04:32.160
So, um, that's this all sounds ideal.

04:32.520 --> 04:35.560
Uh, so but there is a little bit of setting up.

04:35.560 --> 04:39.480
You do have to create that API key, even though you don't need a credit card or anything, but you

04:39.480 --> 04:44.680
will need to go to Alpha Vantage and you just click Create Free key.

04:44.840 --> 04:46.640
And that's really all there is to it.

04:46.680 --> 04:51.800
Once you've gone here, they want to know who you are and optionally an email address.

04:51.960 --> 04:54.360
And then they will give you a key right away.

04:54.360 --> 05:02.120
And of course you will come back and put that key as Alpha Vantage API key into your EMV file.

05:02.600 --> 05:10.150
And once you've done that, you can then uh, import Imports smithery, which is like a service that,

05:10.190 --> 05:18.750
uh, that they use to, um, to sort of manage this process of calling out to remote, uh, MCP servers.

05:19.110 --> 05:26.870
And you can use that to create a URL, which we'll connect to given the Alpha Vantage API key in our

05:26.870 --> 05:27.790
environment.

05:28.070 --> 05:31.670
And doing that will then give a URL.

05:32.190 --> 05:33.630
So I will run this right now.

05:34.830 --> 05:43.070
And then we will actually go ahead and run this as a remote MCP server from our MCP client.

05:43.070 --> 05:50.110
And I'll say that I had a little bit of difficulty using OpenAI agents SDKs client for this.

05:50.150 --> 05:52.230
In theory, it should be super simple.

05:52.390 --> 05:55.150
Their code is the API looks really simple.

05:55.150 --> 06:03.350
It's server s instead of MCP server stuff that we've been using up to this point.

06:03.350 --> 06:07.390
You can just switch it in and pass in the parameters with the URL.

06:07.510 --> 06:09.910
But when I tried this I get errors.

06:09.950 --> 06:11.150
It may be a temporary thing.

06:11.150 --> 06:13.510
I know that this code is all super new as well.

06:13.510 --> 06:15.790
It may be that I'm making a mistake in doing something wrong.

06:16.030 --> 06:16.790
Uh, so.

06:16.870 --> 06:20.110
So I wasn't able to get it to work the really nice way.

06:20.150 --> 06:25.310
So instead I had to do something which is a good exercise, which is nice to show you, which is writing

06:25.310 --> 06:31.470
my own MCP client as we did before, but this time a client for the SSH server.

06:31.870 --> 06:36.990
So I've done it that way so that we can indeed hook up our agent to it.

06:36.990 --> 06:38.630
So it's a little bit more involved.

06:38.630 --> 06:40.470
And it's some interesting code to show you.

06:40.630 --> 06:44.030
So this code it's in Alpha client and here it is.

06:44.350 --> 06:50.470
And as I say in theory you shouldn't need to use this because OpenAI I should figure out what's wrong

06:50.470 --> 06:50.630
there.

06:50.630 --> 06:51.950
Or maybe they'll fix something.

06:51.990 --> 06:54.630
And when you look in the code, you may find that that's already fixed.

06:54.630 --> 06:58.830
Because as soon as I as I get that sorted, I will of course update the code to use their library.

06:58.830 --> 07:02.510
But you can still keep this this code in here so you can look at it if you wish.

07:02.710 --> 07:05.430
Um, but this is what it looks like to have a client.

07:05.430 --> 07:08.110
This is the real client piece right here.

07:08.310 --> 07:13.220
Um, but basically there's two, uh, there's two functions that I've written here.

07:13.260 --> 07:20.380
List stock tools and call stock tool which is making the list tools and call tool, which are the two

07:20.420 --> 07:25.780
kind of core functions that the model context protocol covers.

07:25.780 --> 07:29.220
That is what they do along with the resources and the prompts.

07:29.660 --> 07:38.340
So essentially all I do is create a WebSocket client and then use the MCP client session to allow me

07:38.340 --> 07:44.300
to make this call remotely to this server running, running remotely.

07:44.540 --> 07:48.900
Uh, and I do that for both the list and the call functions.

07:49.220 --> 07:51.580
And then this one here is just as before.

07:51.620 --> 07:53.900
This is a little bit of of messiness.

07:54.020 --> 08:00.220
This is because OpenAI expects their tools using this particular object, the function tool.

08:00.220 --> 08:01.780
And it's not exactly the same.

08:01.780 --> 08:05.500
And so there had to be a little bit of mapping around to get this to work properly.

08:05.660 --> 08:11.050
Uh, but that that is how I, I pulled this together that you can look through, but it's not all that

08:11.050 --> 08:17.610
important to the point, because the point is that when you've done that, we can simply pull in that

08:17.610 --> 08:25.370
that code I was just showing you right there and call open AI tools that is running right now, and

08:25.370 --> 08:25.930
it's done.

08:25.930 --> 08:31.530
And when I look at open AI tools, we're now seeing get stock data, get stock alerts and get daily

08:31.530 --> 08:32.450
stock data.

08:32.450 --> 08:37.730
And these three tools have been retrieved from the remote server.

08:37.730 --> 08:41.610
That's what's running over SSH which is exciting.

08:41.810 --> 08:44.650
So this was not planned, but I have something interesting to show you.

08:44.770 --> 08:52.210
So, uh, as it happens right now, it appears that the Alpha Vantage server isn't is down, is not

08:52.210 --> 08:53.170
responding properly.

08:53.170 --> 08:54.890
It's not giving stock prices.

08:55.170 --> 08:56.650
Our infrastructure is working.

08:56.650 --> 08:58.210
We're going to make the call to our client.

08:58.210 --> 09:01.490
It's going to go to the and call the remote server.

09:01.490 --> 09:06.330
And the response is going to say that it isn't able to provide share prices right now.

09:06.570 --> 09:08.890
Uh, so let me just show you that happening.

09:08.890 --> 09:10.250
So you get a sense of this.

09:10.490 --> 09:13.840
Uh, so so the system prompts you can use tools to get stock prices.

09:13.840 --> 09:14.400
The request.

09:14.440 --> 09:15.040
Please let me know.

09:15.040 --> 09:16.240
The share price of Amazon.

09:16.240 --> 09:17.840
We've got our tools properly.

09:17.840 --> 09:19.040
And then we're making the request.

09:19.040 --> 09:23.080
And I put a couple of print statements in our client so we could see what happens.

09:23.520 --> 09:24.800
And but we're calling.

09:24.800 --> 09:26.080
So the LLM responded.

09:26.080 --> 09:34.760
And as a result we um we did make a call to, to Amazon, uh, sorry to collect the share price for

09:34.760 --> 09:38.600
Amazon to our, uh, MCP server.

09:38.760 --> 09:45.520
The response that came back from the remote server was error fetching stock data, no time series found

09:45.520 --> 09:46.560
in the response.

09:46.920 --> 09:52.480
And, uh, that was coming back from the MCP server that was itself calling out to the Alpha Vantage

09:52.720 --> 09:54.640
API, uh, remotely.

09:55.000 --> 10:00.520
And uh, our LLM tried a second time and got the same response, and it says, I'm currently unable

10:00.520 --> 10:01.880
to fetch the share price from Amazon.

10:01.880 --> 10:04.080
You might want to check financial news website.

10:04.080 --> 10:10.040
So I guess what we're seeing here is that our infrastructure worked, our remote MCP server worked,

10:10.040 --> 10:16.070
and that it was called, uh, but it was not able to actually get the right price from the API.

10:16.230 --> 10:19.430
And so that was the response that it gave us.

10:19.470 --> 10:24.190
Hopefully by the time you try this, you'll get a good response, which is nice, but that's what I,

10:24.230 --> 10:25.950
what I have right here.

10:26.030 --> 10:26.950
It's still quite useful.

10:26.950 --> 10:29.510
It's interesting for us to see the plumbing holding together.

10:29.510 --> 10:35.590
And it's interesting because I guess it does serve to show that it's more stable to be running this

10:35.590 --> 10:39.670
stuff yourself locally and to have complete management over it.

10:39.710 --> 10:45.230
If you are running it in a remote MCP server, then you're at the mercy of how that handles things and

10:45.230 --> 10:46.990
how it handles something like an exception.

10:47.230 --> 10:50.750
Um, but let's look at the trace to see this in action.

10:51.030 --> 10:54.990
Uh, and we can go into conversation and we can see that it did try.

10:55.030 --> 10:58.710
It tried both the stock data and the daily stock data APIs.

10:58.830 --> 11:01.270
It just passed in Amazon as a symbol.

11:01.270 --> 11:07.150
And it got back exactly the response that we saw from the remote MCP server.

11:07.150 --> 11:14.350
And the same when trying the other API that our agents faithfully tried both but had no joy and nor

11:14.350 --> 11:14.990
did we.
