Besides us making our own tools, it is
also possible to consume MCP tools.
MCP, or Model Context Protocol, you might have
heard of.
If you haven't, it's a protocol where others
can expose their code, their actions, their information,
and you to consume, so you don't need
to use their APIs.
A good example is GitHub, where if you
use your GitHub MCP, it can list issues,
create branches, and stuff like that.
In our case, we are going to use
the Microsoft Learn MCP server.
So they show that they have an MCP
server.
There are two types of MCP servers.
There are remote MCP servers and local MCP
servers.
In our case, we are going to show
a remote MCP server because I think they
are the future, and local MCPs are for
niche areas in general.
Beyond that, I'm not going to go into
what MCP is in general unless you report
back that you want a dedicated video on
it.
But just see it as someone who has
written some code that you would not have
had access to.
So what we can see here is I
have put in one more NuGet package, and
that NuGet package is the modelcontextprotocol.
Once we have that, we can do something
like this.
Await MCP client.create a new client.
We want an HTTP client with the options
of the endpoint being the Microsoft Learn MCP
and its streamable HTTP.
So here we can choose between some older
models, and up here we can choose between
HTTP and STDIO, which is the local.
MCP clients come back, and you need to
expose them, so I'm doing an await using
here.
But what we can do is we set
a breakpoint here.
We can see that whenever we have an
MCP server, we can get what tools it
has.
So just like we've written some tools, Microsoft
Learn have written some tools and exposed it
to this URL.
That's all there is to MCP, to be
honest.
So if we run it here and get
the tools, we can see they have three
tools.
They have a tool for doc search, meaning
searching the entire Microsoft Learn site, a tool
for finding code samples, and a tool for
fetching a specific Learn site.
Right now, I have not given the tools.
You can see I've commented them out here
on purpose.
That is to show what we can do
with the tools and without the tools.
So I am here, and if I go
in and ask the question, make a –
oh, I didn't show that.
The instructions here are you are an expert
in the C-Sharp version of Microsoft Agent
Framework.
Use tools to find your knowledge, and assume
Azure OpenAI with API key is used.
So a little like we do up here.
And if we ask that without – we
just add to LLM, which, by the way,
is 4.1 nano.
That was released about one and a half
years before Microsoft Agent Framework came along.
It will not know anything about what this
is.
But if we say make an example on
how to make an agent, it will not
say I do not know.
It will come back and say it's this
made-up nonsense.
So it wants to use Windows Forms.
It wants to use Newtonsoft.
It do something with OpenAI here, and then
it does all kinds of things that doesn't
exist.
It has just made stuff up trying to
go to OpenAI.
I have also seen it make some agent
packages and so on.
So if we start it again and try
to ask the same question, it will come
up with something new.
Let me ask the same question again.
So now it wants to use some COM
import in order to make an AI agent
trooper.
This probably doesn't exist in the world, or
if it does, it's certainly not what we
want.
So this is Hallucination's big style because it's
in an area it doesn't know anything about.
But if we give to the tool, which
is essentially give it access to the entire
Microsoft Learn portal, which of course also have
Microsoft agent framework, among other things, it will
become much better at this.
Not perfect, but much better.
So if we ask the same, make an
example on how to make an agent.
Let me make it big so we can
see it better.
It will now call the tool and look
at the code and so on, and now
it suddenly knows Microsoft agent framework.
So it now knows it needs to use
Azure OpenAI and stuff like that.
It gets it from environment variables.
We did it a bit different.
And it's using not the API key, but
now we can actually use it as a
teaching experiment on how you instead use the
role-based access control for Azure by simply
just giving up the default.
And the reason for this is that all
the Microsoft samples use this, and they don't
actually give a sample on how to get
it with an API key because they don't
want to have API keys rolling around in
their samples.
But beyond that, it gets an Azure client.
It turns it into a chat client, and
it says create agent, uses instructions and names,
and do exactly as we have learned over
the last few lectures.
And then it gives links to where we
can find information about this further on into
the system.
So that is the power of MCP, that
we can, with just these few lines of
code, have the entire system.
Had Microsoft learned, had an API, we could
have probably have built a lot of code
and exposed that as a tool, but we
don't need to because of MCP.
GitHub in the same manner, and so on
and so forth.
MCP can do much, much more.
Again, there's local tools for controlling browsers and
stuff like that, but it's a bit beyond
the scope of this introduction video at least.
But all we do is we make our
tools, and conveniently, those tools can be cast
into those AI tools that we need down
here.
So very, very easy to do.
One thing that are difficult to do right
now is authentication against MCP servers.
It's easy to do with API keys and
stuff like that, but the entire OAuth part
of it is very, very brand new in
this package, so many of the OAuth options
don't work as of this recording.
But these open and free ones are very
easy to use, as you can see.