WEBVTT

00:00.240 --> 00:02.730
-: So I remind you this is the implementation

00:02.730 --> 00:04.530
of our SSE server

00:04.530 --> 00:05.700
and in order to run it

00:05.700 --> 00:08.820
all we need to do is run the command uv run

00:08.820 --> 00:11.643
then servers and the weather_server.

00:12.540 --> 00:15.630
So we can see now it's running on port 8000.

00:15.630 --> 00:18.120
And now I want to create a new MCP client

00:18.120 --> 00:20.280
that is going to use this SSE server

00:20.280 --> 00:23.130
and it's going to use the STDIO server

00:23.130 --> 00:25.890
we had from before with the math operations.

00:25.890 --> 00:28.290
So let me open another terminal

00:28.290 --> 00:30.150
and let me run the math server.

00:30.150 --> 00:35.150
So uv run servers/math py

00:37.707 --> 00:39.150
and it's running around.

00:39.150 --> 00:41.790
So let me go now and create a new file

00:41.790 --> 00:44.090
and let me call this file langchain_client.py.

00:45.570 --> 00:48.210
And the reason why I'm calling it that

00:48.210 --> 00:50.430
is because we're going now to implement

00:50.430 --> 00:53.490
a langchain multi-server client.

00:53.490 --> 00:56.700
So the langchain multi MCP servers client

00:56.700 --> 00:59.730
is a new client that langchain wrote for us

00:59.730 --> 01:03.840
that is able to connect to multiple MCP servers.

01:03.840 --> 01:06.330
So remember I told you there is a one-to-one connection

01:06.330 --> 01:08.460
between a client and an MCP server.

01:08.460 --> 01:09.870
So this is still the case.

01:09.870 --> 01:11.670
Langchain abstracted for us

01:11.670 --> 01:15.060
and inside it we're going to have multiple MCP clients

01:15.060 --> 01:17.490
but we can use that to easily connect

01:17.490 --> 01:21.060
to multiple MCP servers without explicitly writing

01:21.060 --> 01:23.493
the clients for each one of those servers.

01:26.220 --> 01:29.160
So to do that we'll start by importing

01:29.160 --> 01:32.160
from langchain_mcp_adapters.client.

01:32.160 --> 01:35.053
We want to import the MultiServerMCPClient.

01:36.000 --> 01:38.670
Let's go and import from langgraph.prebuilt,

01:38.670 --> 01:42.150
the create_react_agent like we did before.

01:42.150 --> 01:45.180
And let's import OpenAI, ChatOpenAI

01:45.180 --> 01:46.683
exactly like we did before.

01:49.950 --> 01:54.930
And of course we want to implement from dotenv load_dotenv.

01:54.930 --> 01:56.763
And we also initialized the llm.

02:00.240 --> 02:02.640
And let me open a new terminal

02:02.640 --> 02:05.236
and let's run this file for a sanity check.

02:05.236 --> 02:09.630
uv run langchain_client.py

02:09.630 --> 02:11.880
and we can see it ran successfully.

02:11.880 --> 02:15.180
Let's also define a async function, main,

02:15.180 --> 02:19.590
and let's write here print("hello langchain mcp")

02:19.590 --> 02:22.473
and we're also running it with the asyncio.

02:24.090 --> 02:27.393
And of course I need to import asyncio.

02:28.350 --> 02:29.313
And yeah.

02:31.470 --> 02:32.880
So this is the boiler plate code.

02:32.880 --> 02:34.563
Let's run it as a sanity check.

02:35.550 --> 02:39.930
uv run langchain_client.py.

02:39.930 --> 02:41.913
So this is working as expected.
