WEBVTT

1
00:00:00.000 --> 00:00:05.500
Hi, and welcome to this AI and C-Sharp video on the Microsoft Agent Framework.

2
00:00:05.500 --> 00:00:11.500
Today we're going to look how you can create your own remote MCP server.

3
00:00:11.500 --> 00:00:19.000
And MCP is as such not AI-based, but we are going to use one of the tools

4
00:00:19.000 --> 00:00:21.000
and have an AI behind the scenes.

5
00:00:21.000 --> 00:00:25.500
But as such, not too much about AI, it's just a protocol.

6
00:00:25.500 --> 00:00:27.000
But let's go in and see.

7
00:00:28.000 --> 00:00:33.000
So in here we have, under tools, calling and MCP,

8
00:00:33.000 --> 00:00:37.000
we have an exposure agent as remote MCP.

9
00:00:37.000 --> 00:00:44.000
And this is a web API, ASP.NET Core.

10
00:00:44.000 --> 00:00:49.000
And in terms of NuGet package that we need,

11
00:00:49.000 --> 00:00:53.000
we can see that we use OpenAI, Azure OpenAI,

12
00:00:53.000 --> 00:00:55.000
but you can, of course, use whatever.

13
00:00:55.000 --> 00:00:59.000
And then we're using the package called

14
00:00:59.000 --> 00:01:07.000
ModelContextProtocol, ASP.NET Core, which is the one for hosting MCPs.

15
00:01:07.000 --> 00:01:10.000
And MCPs is fairly simple.

16
00:01:10.000 --> 00:01:16.000
In our case, the first thing we do is we make our client for the agent

17
00:01:16.000 --> 00:01:19.000
and register that as a singleton.

18
00:01:19.000 --> 00:01:23.000
But then we say, builder.services.addMCP

19
00:01:23.000 --> 00:01:27.000
with HTTP transport, meaning remote,

20
00:01:27.000 --> 00:01:33.000
and take all tools that are in disassembly and add them to the system.

21
00:01:33.000 --> 00:01:39.000
We can also say with tool, if we want to specify each tool.

22
00:01:42.000 --> 00:01:48.000
But in our case, we'll just take everything that have a certain attribute here.

23
00:01:48.000 --> 00:01:54.000
Then we map MCP, and we give it slash MCP at the end.

24
00:01:54.000 --> 00:01:58.000
Sort of a standard by many people, but we could call it whatever.

25
00:01:58.000 --> 00:02:03.000
It's just a map point as normal.

26
00:02:03.000 --> 00:02:07.000
And we have our tools, and I've made three tools.

27
00:02:07.000 --> 00:02:12.000
So I just put them in a class that we don't really knew up by ourselves.

28
00:02:12.000 --> 00:02:16.000
MCP will do that for us.

29
00:02:16.000 --> 00:02:21.000
And we give it this MCP server tool type,

30
00:02:21.000 --> 00:02:24.000
meaning that it should look in this class.

31
00:02:24.000 --> 00:02:28.000
And we have our first MCP tool here,

32
00:02:28.000 --> 00:02:32.000
which is just not using AI in any way.

33
00:02:32.000 --> 00:02:36.000
And it's just a get the secret word, which is banana cake here.

34
00:02:36.000 --> 00:02:41.000
We tell it that it's an MCP server tool, that the name is this.

35
00:02:41.000 --> 00:02:45.000
And read only, meaning that it doesn't need to ask commissions

36
00:02:45.000 --> 00:02:51.000
because it will only give back data, it will not change data.

37
00:02:51.000 --> 00:02:53.000
And we can give it a description.

38
00:02:53.000 --> 00:02:58.000
We'll see that when we use it in the various clients.

39
00:02:58.000 --> 00:03:03.000
Then we have a tool more called Ask John the Pirate.

40
00:03:03.000 --> 00:03:08.000
Just giving it a name, and again, it's read only.

41
00:03:08.000 --> 00:03:13.000
So we just tell that John the Pirate can talk about pirate life.

42
00:03:13.000 --> 00:03:16.000
And inside we're just newing up an agent,

43
00:03:16.000 --> 00:03:26.000
and telling that he should answer children's questions about pirates.

44
00:03:26.000 --> 00:03:30.000
So this is the only thing we're actually doing using Agent Framework 4,

45
00:03:30.000 --> 00:03:34.000
because again, MCP is just a protocol.

46
00:03:34.000 --> 00:03:38.000
The last tool we're making, we make read only equals false

47
00:03:38.000 --> 00:03:41.000
because this is an add order, simulate something,

48
00:03:41.000 --> 00:03:46.000
put something into a sales order, into an ERP system.

49
00:03:46.000 --> 00:03:50.000
We're not really going to do it, but that would just be normal C-sharp code.

50
00:03:50.000 --> 00:03:58.000
And we're returning the number of that order back to the system.

51
00:03:58.000 --> 00:04:03.000
And that is actually everything we need in terms of code in order to do this.

52
00:04:03.000 --> 00:04:10.000
So if we run it, we will see that it's just a normal,

53
00:04:10.000 --> 00:04:13.000
once we get it up and running here.

54
00:04:26.000 --> 00:04:30.000
Yeah, so we have it running here. It's both SMCP.

55
00:04:30.000 --> 00:04:37.000
And now if we want to use it, we can use it in the various clients.

56
00:04:37.000 --> 00:04:41.000
So let me show you three different clients,

57
00:04:41.000 --> 00:04:46.000
but you can use all the clients that support MCP remote.

58
00:04:46.000 --> 00:04:53.000
So the best tool to test MCPs in my book is Visual Studio Code,

59
00:04:53.000 --> 00:04:59.000
because it has by far the best implementation of MCP.

60
00:04:59.000 --> 00:05:02.000
It's been there the longest, and it shows.

61
00:05:02.000 --> 00:05:09.000
The only thing MCP here can't do is, if we look at our tool here,

62
00:05:09.000 --> 00:05:13.000
it's exposing itself on this port.

63
00:05:13.000 --> 00:05:19.000
But as of this recording, there is a bug in Visual Studio Code

64
00:05:19.000 --> 00:05:24.000
that it can't use these local hosts for MCPs as testing.

65
00:05:24.000 --> 00:05:32.000
So what I have done here is I have turned on DevTunnels,

66
00:05:32.000 --> 00:05:37.000
and I created a tunnel called AI Samples.

67
00:05:37.000 --> 00:05:44.000
AI DevTunnels is a way of you getting a remote URL

68
00:05:44.000 --> 00:05:50.000
that make a reverse proxy down to your local host.

69
00:05:50.000 --> 00:05:54.000
So if we look here, it might say local host,

70
00:05:54.000 --> 00:06:02.000
but if we go to our output and look under DevTunnels,

71
00:06:02.000 --> 00:06:09.000
it will actually also be on this URL that is unique to me.

72
00:06:09.000 --> 00:06:16.000
So if we take that URL and go to Visual Studio Code,

73
00:06:16.000 --> 00:06:24.000
and say add MCP server, it needs to be an HTTP,

74
00:06:24.000 --> 00:06:28.000
and we have this slash MCP.

75
00:06:28.000 --> 00:06:34.000
We can call it myMCP,

76
00:06:34.000 --> 00:06:37.000
and we just put it for this workspace.

77
00:06:37.000 --> 00:06:39.000
This is just a folder called Hello MCP,

78
00:06:39.000 --> 00:06:43.000
and what we see is it makes a mcp.json,

79
00:06:43.000 --> 00:06:47.000
and it has started our tool, which will have the three tools,

80
00:06:47.000 --> 00:06:53.000
and we can see down here in our copilot that our tool is here,

81
00:06:53.000 --> 00:06:57.000
and we can see that our name of the tool is here,

82
00:06:57.000 --> 00:07:01.000
and our description of a tool is here.

83
00:07:01.000 --> 00:07:04.000
So now we can use it,

84
00:07:04.000 --> 00:07:13.000
and we can, for example, say what is the secret word,

85
00:07:13.000 --> 00:07:19.000
and if we do that, it runs the MCP tool,

86
00:07:19.000 --> 00:07:24.000
and what we can do if we want to

87
00:07:24.000 --> 00:07:32.000
is, of course, that we can set some breakpoints to see what's going on,

88
00:07:32.000 --> 00:07:40.000
and let me take this and ask a new sign,

89
00:07:40.000 --> 00:07:46.000
so it hit the breakpoint,

90
00:07:46.000 --> 00:07:49.000
and come back with the secret word.

91
00:07:49.000 --> 00:08:04.000
Similar, we can say, ask John why it's green.

92
00:08:10.000 --> 00:08:13.000
Again, hit the breakpoint.

93
00:08:13.000 --> 00:08:17.000
In this case, it will then run an AI, of course,

94
00:08:17.000 --> 00:08:21.000
and it comes back with an answer,

95
00:08:21.000 --> 00:08:28.000
and finally, if we say add order

96
00:08:28.000 --> 00:08:36.000
to ACME for 10 anvils,

97
00:08:36.000 --> 00:08:40.000
because this is a destructive tool or non-read-only tool,

98
00:08:40.000 --> 00:08:42.000
it will come up and ask us,

99
00:08:42.000 --> 00:08:46.000
are you sure you want to send customer ACME items to buy anvil,

100
00:08:46.000 --> 00:08:53.000
and quantity 10, which was what we had for the three inputs for the order,

101
00:08:53.000 --> 00:08:57.000
and if we say allow, it will be hit,

102
00:08:57.000 --> 00:09:02.000
and will come back that the order has been added.

103
00:09:02.000 --> 00:09:08.000
So Visual Studio Code is really, really good for testing this.

104
00:09:08.000 --> 00:09:14.000
Another tool is, of course, Visual Studio Code itself.

105
00:09:14.000 --> 00:09:18.000
And Visual Studio, yeah, they have the tool here in Copilot,

106
00:09:18.000 --> 00:09:21.000
and you can say add,

107
00:09:21.000 --> 00:09:25.000
and 9 out of 10 times this doesn't work.

108
00:09:25.000 --> 00:09:32.000
It is fairly new, and they simply have done a very poor implementation.

109
00:09:32.000 --> 00:09:37.000
The best way to actually get MCP working in Visual Studio

110
00:09:37.000 --> 00:09:45.000
is to go to the Visual Studio part of it.

111
00:09:45.000 --> 00:09:49.000
So it made this VS Code and MCP,

112
00:09:49.000 --> 00:09:53.000
and take this folder,

113
00:09:53.000 --> 00:09:58.000
and put it over in your Visual Studio project.

114
00:09:58.000 --> 00:10:02.000
So I have my Visual Studio project here, and just put that in.

115
00:10:03.000 --> 00:10:09.000
Second you do that, our tool appears here.

116
00:10:09.000 --> 00:10:13.000
Don't ask why, this is the easy way when they have a register for it,

117
00:10:13.000 --> 00:10:17.000
but as of this recording, this is the best way.

118
00:10:17.000 --> 00:10:26.000
So we can again ask here, what is the secret word,

119
00:10:26.000 --> 00:10:33.000
and see if it picks it up.

120
00:10:33.000 --> 00:10:37.000
And all depending on how good they are,

121
00:10:37.000 --> 00:10:45.000
they get this wrong, often you need to say, use tools.

122
00:10:45.000 --> 00:10:51.000
So now it found it, and it want us to confirm it.

123
00:10:51.000 --> 00:10:53.000
Hit the breakpoint.

124
00:10:53.000 --> 00:10:58.000
Let me just get rid of the breakpoint, so we don't go back and forward.

125
00:10:58.000 --> 00:11:06.000
We come back, and in the same manner we can ask John,

126
00:11:06.000 --> 00:11:15.000
what the heck is use tools.

127
00:11:15.000 --> 00:11:19.000
So this use tools is all depending on how good

128
00:11:19.000 --> 00:11:22.000
the implementation of the AI is,

129
00:11:22.000 --> 00:11:25.000
and Visual Studio Code is one of the best for tools,

130
00:11:25.000 --> 00:11:37.000
compared to the others, but now it even didn't find that.

131
00:11:37.000 --> 00:11:41.000
So we might want to say...

132
00:11:41.000 --> 00:11:51.000
Oh, that's because they are disabled, that's the reason.

133
00:11:51.000 --> 00:12:00.000
So now it comes and asks, and we get our answer back.

134
00:12:00.000 --> 00:12:04.000
One client I want to show is ChatGBT,

135
00:12:04.000 --> 00:12:10.000
and ChatGBT is hopelessly behind on MCP at the moment,

136
00:12:10.000 --> 00:12:13.000
because they don't support it here.

137
00:12:13.000 --> 00:12:20.000
They have a beta version of it, or preview version,

138
00:12:20.000 --> 00:12:25.000
that we can turn on if you are an admin,

139
00:12:25.000 --> 00:12:31.000
and then we can go in and add a tool,

140
00:12:31.000 --> 00:12:40.000
because so far most MCP clients is developer tools,

141
00:12:40.000 --> 00:12:47.000
and that's a real shame, because it's not all developers who need MCP servers.

142
00:12:47.000 --> 00:12:52.000
So hopefully at some point things like this will become better at it.

143
00:12:52.000 --> 00:13:01.000
I need the URL, so we go back and find that here.

144
00:13:01.000 --> 00:13:07.000
We say MCP, I have no authentication on this,

145
00:13:07.000 --> 00:13:13.000
and I understand it's dangerous.

146
00:13:13.000 --> 00:13:20.000
You will see that ChatGBT is endlessly slow at doing this,

147
00:13:20.500 --> 00:13:25.000
and this beta version has been there for quite a while now,

148
00:13:25.000 --> 00:13:29.000
so I don't know why they are so slow at doing this.

149
00:13:29.000 --> 00:13:33.000
But what we can do is we can go in and take our MCP server,

150
00:13:33.000 --> 00:13:40.500
and again, what is the secret word?

151
00:13:40.500 --> 00:13:44.000
And I know for a fact I need to say use tools here.

152
00:13:50.500 --> 00:13:53.500
So hopefully we should hit our tool.

153
00:13:53.500 --> 00:13:56.000
This is very hit and miss if it works,

154
00:13:56.000 --> 00:14:08.000
but some of the tools can call, and some of them will also fail.

155
00:14:08.000 --> 00:14:13.000
But they called the tool, and now it failed.

156
00:14:13.000 --> 00:14:17.500
Let's try again.

157
00:14:17.500 --> 00:14:23.500
So there's a reason why it's in beta.

158
00:14:31.000 --> 00:14:37.500
Now it appears to want to call it two times for some reason.

159
00:14:37.500 --> 00:14:42.000
Yes, they don't really have the act to get on MCP yet,

160
00:14:42.000 --> 00:14:45.500
but hopefully they will at some point.

161
00:14:45.500 --> 00:14:50.500
But as you can see, MCP is very easy.

162
00:14:50.500 --> 00:14:56.500
Write your tools,

163
00:14:56.500 --> 00:14:59.500
write these three lines of code, and this one,

164
00:14:59.500 --> 00:15:03.000
and you are more or less done.

165
00:15:03.000 --> 00:15:08.500
If you want to see videos about local tools, I will also make that,

166
00:15:08.500 --> 00:15:12.500
but to me, honestly, local tools really don't exist.

167
00:15:12.500 --> 00:15:19.000
I don't think they are worth doing, especially not in a .NET space,

168
00:15:19.000 --> 00:15:21.000
but it is possible, and if you had something

169
00:15:21.000 --> 00:15:23.500
like a command line tool, you might do it,

170
00:15:23.500 --> 00:15:28.000
but my recommendation would be always to do remote tools,

171
00:15:28.000 --> 00:15:33.000
and as an example, ChatGPT, when they get better,

172
00:15:33.000 --> 00:15:37.000
they will only work with remote tools, not local tools,

173
00:15:37.000 --> 00:15:42.000
because they are a remote system.

174
00:15:42.000 --> 00:15:46.000
But that is everything for this time. See you in the next one.

