0:02 mCP or the model context protocol it's
0:04 what everybody's talking about and here
0:06 is your executive summary what it is why
0:08 it's important how it works how it
0:11 Compares with other protocols and some
0:15 key takeaways let's get right into [Music]
0:18 [Music]
0:20 it all right let's start with breaking
0:22 down the name mCP stands for model
0:25 context protocol and the m4 model in
0:27 this case is an AI model and while you
0:29 can use it on image models and text to
0:31 speech models and really all kinds of
0:33 models it's really most useful for llms
0:36 or large language models like open AI
0:40 gbd4 Google's Gemini and anthropics CLA
0:42 and when it comes to AI models context
0:44 is everything let's take a query like
0:46 this one have a look at my sqlite
0:47 database and make sure that the sum of
0:49 all the orders is correct and matches
0:51 what's in my presentation no model by
0:53 itself is going to be able to do this it
0:55 lack context it needs to be able to
0:57 query the database to get the orders and
0:58 it needs to be able to read the
1:00 presentation which is in a file
1:02 and then when it has both of those then
1:04 it can answer your question so that's
1:06 where the C in mCP comes from that
1:09 stands for context and what mCP servers
1:12 do is they provide a way for AI models
1:15 to access the context they need to
1:17 accomplish tasks in the case of this
1:19 query you probably have one mCP server
1:21 that can access the database and another
1:22 mCP server that can access your
1:25 presentation file maybe from the cloud
1:27 and the model can use both of those mCP
1:29 servers to accomplish that single task
1:31 askk now there are four types of context
1:33 Primitives that an mCP server can
1:37 provide to an AI model first is tools
1:39 these are functions that the model can
1:41 use to perform actions like creating a
1:45 database or updating a database or
1:47 anything really there's also resources
1:49 resources are essentially attachments
1:51 that you're providing to the model in
1:53 our case that would be the presentation
1:55 file now resources and tools are by far
1:57 the most common that I've seen But there
1:59 are two others there sampling which is a
2:01 way for the model to query other models
2:04 and then there are parameterized prompts
2:06 that clients can use as templates when
2:09 making requests to the model and these
2:10 two are less commonly used but they're
2:12 still part of mCP and we might see them
2:15 being used more in the future now I've
2:16 been talking a lot about mCP servers and
2:19 clients so let's dig into that mCP
2:22 servers are programs or servers that
2:25 handle requests from mCP clients the mCP
2:27 server implements the tools or provides
2:30 the resources and the mCP client is what
2:32 makes the request to the server for
2:34 those tools and those resources so
2:36 here's a site that has a list of all the
2:39 MCB clients as well as a massive list of
2:41 mCP servers I put a link to that in the
2:42 description right down below and you can
2:45 have a look for yourself in the case of
2:47 our example the mCP client is the chat
2:50 interface that we're typing into Claude
2:52 desktop and the mCP server would be a
2:54 program that we're running on our own
2:56 computer or hosted in the cloud and
2:58 would give us access to the SQL database
3:00 and the presentation
3:03 now the p and mCP means protocol and the
3:05 mCP protocol defines the structure of
3:07 the messages that are sent between the
3:08 client and the server and honestly you
3:09 don't really need to know all the
3:11 details of the messages themselves but
3:13 what is important to know is that there
3:14 it is well defined and it supports
3:15 something called
3:18 reflection and reflection is the ability
3:20 for the client to ask the server for
3:22 information about The Primitives that
3:25 the server provides like the tools and
3:27 the resources reflection is a critical
3:29 part of mCP and it's what makes mCP
3:31 different from other API protocols like
3:35 trpc grpc and rest now I mentioned that
3:36 mCP servers are programs that you can
3:38 run or they can be deployed as a service
3:40 and that's because the protocol is
3:41 designed to be used with different types of
3:42 of
3:45 transports and there are two main ones
3:46 take from the start the first is the
3:48 standard IO transport and that's where
3:51 the mCP client runs the mCP server as a
3:54 program on your own computer directly
3:56 and then the mCP client communicates
3:58 with the mCP server using the built-in
4:00 Unix or window
4:02 standard input and output mechanisms or
4:05 standard IO for short the other
4:07 transport mechanism is ssse or server
4:09 sent events this is network based so
4:11 your mCP client is configured with a
4:14 remote URL and then messages are sent
4:17 back and forth using SS events over HTTP
4:20 or https now which one of these
4:22 transport mechanisms you use depends on
4:24 your use case in our example we'll
4:26 probably use standard IO for both of
4:28 these because our local machine has
4:29 access to our sqlite database as as well
4:31 as our presentation file all right now
4:33 let's actually try out an mCP server in
4:36 fact let's try out an sqlite server that
4:38 fits with our example and for an mCP
4:41 client we'll use Claude desktop now this
4:42 is actually going to get pretty complex
4:45 mCP is still new and so these flows are
4:47 still a little rough first you need to
4:49 download the source code onto your
4:52 server which I've already done then you
4:53 need to configure the client and each
4:55 client handles this a little differently
4:57 for CLA desktop that actually means
5:00 editing a Json config file
5:03 and adding a new server configuration
5:04 and because we're using standard IO
5:06 transport we're going to need to run the
5:08 server as a program so we specify the
5:10 command and the arguments and then
5:13 Claude desktop handles booting that
5:15 application now we can reboot Claude
5:16 with a new configuration and we can see
5:18 this little connector icon and when we
5:20 click on that we can see that we have a
5:23 server running and now we can type in a
5:25 request to use a sqlite database and at
5:27 each point it's prompting us to confirm
5:29 whether it's doing the right thing
5:30 because this MC server could actually
5:32 make changes to the database and so we
5:33 want to make sure that those
5:34 confirmations help you understand what's
5:37 happening and stop it if it's not doing
5:39 what you want now that we understand
5:40 more about how the client Works let's
5:43 dig a little deeper into the server and
5:45 I'll do that for two reasons the first I
5:47 do want to show you how mCP servers work
5:49 and secondly I want to encourage you to
5:52 build your own mCP server to fit your
5:54 specific use case so this is the code
5:56 for a very simple server example written
5:58 in typescript you can see at the top
5:59 here we Define the server with it name
6:02 and its version and then down the bottom
6:04 we run that server using standard IO
6:06 transports that means that it's going to
6:08 be a program that you're going to run on
6:10 your own computer and in between
6:12 defining those two things we add our
6:15 tools and our resources for each tool we
6:16 give it a name and a description and
6:17 those should be written in a way that
6:20 makes it easy for the AI to understand
6:21 what the tool is and when it should use
6:23 it then we Define the parameters to the
6:26 function but again we add descriptions
6:28 so that we can hint to the AI what each
6:30 parameter is for and what the format of
6:32 the parameter is then we Define the
6:34 function body and this is where you
6:35 actually have like your custom query
6:37 code which would connect to your
6:39 database or your API to go and get the
6:41 orders the cool thing is we can test all
6:44 this out without an AI we actually can
6:45 run this server in What's called the
6:47 inspector and then you can see up at the
6:48 top here we've got all the different
6:50 types of Primitives and we can click on
6:53 tools and check those out now notice
6:54 that we got a list of all the tools
6:56 available and that's because the mCP
6:58 protocol supports reflection so the
7:00 first thing the client does is ask a
7:03 server for its tools and resources and
7:05 whatever Primitives so it knows what it
7:07 has access to then this is super
7:09 important because not many protocols
7:11 support reflection we can even run the
7:12 tool in the inspector which is certainly
7:14 cheaper than testing it out in an AI and
7:16 we can make sure that we're giving the
7:18 AI the right results now back in the
7:20 code we can also Define resources where
7:21 you provide a list of all the possible
7:23 resources for example this might be a
7:25 list of files or a directory and then we
7:27 have a method that gets it when a
7:30 specific resource is requested and of
7:31 course we can test out those resources
7:33 in the inspector so now that we know
7:36 broadly what mCP is and how it works
7:38 let's answer the first question that
7:41 everyone asks which is why use mCP
7:43 instead of a more generalized API
7:45 standard like graphql I mean graphql has
7:48 reflection just like mCP although it can
7:51 be turned off and graph is a really
7:53 well- defined protocol so why not just
7:55 use that well it helps to understand the
7:56 difference by looking at it from the
8:00 perspective of the AI model llms support
8:03 tools graphql doesn't have tools as a
8:05 primitive it's got entities and it's got
8:08 Fields but no direct remote procedure
8:11 call or RPC mechanism akin to tools so
8:13 if you want to connect an llm model to a
8:16 graphql API you have to create tools
8:18 that query the entities in those fields
8:21 and then give the tools to the model mCP
8:22 is just a standardized mechanism for
8:24 doing that so how about other grpc
8:27 mechanisms like trpc grpc well these are
8:28 all great but they don't inherently
8:31 provide reflection there's no way for an
8:32 AI model to directly connect to one of
8:34 them and ask hey what tools and
8:36 resources are available to me so again
8:38 you have to create that mapping layer
8:41 from the AI tools to RPC calls in your
8:44 code and this see me my first key
8:45 takeaway which is that you should use
8:48 mCP in conjunction with a backend API
8:51 not as a replacement for that API you
8:53 can think of mCP as a more efficient
8:56 user interface for the AI model not as a
8:58 new generalized API standard for
9:00 everything another key takeaway is you
9:02 shouldn't try to do everything with a
9:05 single mCP server just do your unique
9:07 thing and let the mCP client use your
9:10 mCP server in conjunction with other mCP
9:13 servers mCP is designed for that so a
9:15 client can and should talk to multiple
9:18 mCP servers to accomplish a given task
9:20 and my final key takeaway is that you
9:22 should keep your mCP server at as high a
9:24 level of abstraction as possible if you
9:27 want the AI to create for orders then
9:28 don't give it full access to your
9:30 database and your schemas and all those
9:33 lowlevel details give it a tool to query
9:35 for the orders and add more tools as you
9:38 need again this is about giving AI
9:39 models context and giving it to them in
9:42 a way that is as time and cost efficient
9:44 as possible all right that's my highle
9:46 overview of the model context protocol
9:47 in subsequent videos we be digging more
9:49 into the details of it if any questions
9:51 or comments please put that in the
9:52 comment section right down below and if
9:54 you like this video hit that like button
9:55 if you really like the video hit the
9:57 Subscribe button and click on that Bell
9:58 and be notified the next time new blue