Skip to content

Commit 3e4dd01

Browse files
authored
Simplify client samples (#14)
- Remove duplicate projects - Replace client sample with a simple chat app
1 parent 33b9582 commit 3e4dd01

File tree

10 files changed

+61
-304
lines changed

10 files changed

+61
-304
lines changed

ModelContextProtocol.sln

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,6 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ModelContextProtocol", "src
77
EndProject
88
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ModelContextProtocol.Tests", "tests\ModelContextProtocol.Tests\ModelContextProtocol.Tests.csproj", "{FF41F619-833D-4FA2-8C53-04D0A1D5AA61}"
99
EndProject
10-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MEAIToolsConsole", "samples\microsoft.extensions.ai\tools\ToolsConsole\MEAIToolsConsole.csproj", "{76E295FA-9E85-7B99-332A-2CDBFCD5860A}"
11-
EndProject
12-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AnthropicToolsConsole", "samples\anthropic\tools\ToolsConsole\AnthropicToolsConsole.csproj", "{CA0BB450-1903-2F92-A68D-1285976551D6}"
13-
EndProject
1410
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ModelContextProtocol.TestServer", "tests\ModelContextProtocol.TestServer\ModelContextProtocol.TestServer.csproj", "{7C229573-A085-4ECC-8131-958CDA2BE731}"
1511
EndProject
1612
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestServerWithHosting", "samples\TestServerWithHosting\TestServerWithHosting.csproj", "{6499876E-2F76-44A8-B6EB-5B889C6E9B7F}"
@@ -47,6 +43,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "workflows", "workflows", "{
4743
.github\workflows\ci.yml = .github\workflows\ci.yml
4844
EndProjectSection
4945
EndProject
46+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ChatWithTools", "samples\ChatWithTools\ChatWithTools.csproj", "{0C6D0512-D26D-63D3-5019-C5F7A657B28C}"
47+
EndProject
5048
Global
5149
GlobalSection(SolutionConfigurationPlatforms) = preSolution
5250
Debug|Any CPU = Debug|Any CPU
@@ -61,14 +59,6 @@ Global
6159
{FF41F619-833D-4FA2-8C53-04D0A1D5AA61}.Debug|Any CPU.Build.0 = Debug|Any CPU
6260
{FF41F619-833D-4FA2-8C53-04D0A1D5AA61}.Release|Any CPU.ActiveCfg = Release|Any CPU
6361
{FF41F619-833D-4FA2-8C53-04D0A1D5AA61}.Release|Any CPU.Build.0 = Release|Any CPU
64-
{76E295FA-9E85-7B99-332A-2CDBFCD5860A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
65-
{76E295FA-9E85-7B99-332A-2CDBFCD5860A}.Debug|Any CPU.Build.0 = Debug|Any CPU
66-
{76E295FA-9E85-7B99-332A-2CDBFCD5860A}.Release|Any CPU.ActiveCfg = Release|Any CPU
67-
{76E295FA-9E85-7B99-332A-2CDBFCD5860A}.Release|Any CPU.Build.0 = Release|Any CPU
68-
{CA0BB450-1903-2F92-A68D-1285976551D6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
69-
{CA0BB450-1903-2F92-A68D-1285976551D6}.Debug|Any CPU.Build.0 = Debug|Any CPU
70-
{CA0BB450-1903-2F92-A68D-1285976551D6}.Release|Any CPU.ActiveCfg = Release|Any CPU
71-
{CA0BB450-1903-2F92-A68D-1285976551D6}.Release|Any CPU.Build.0 = Release|Any CPU
7262
{7C229573-A085-4ECC-8131-958CDA2BE731}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
7363
{7C229573-A085-4ECC-8131-958CDA2BE731}.Debug|Any CPU.Build.0 = Debug|Any CPU
7464
{7C229573-A085-4ECC-8131-958CDA2BE731}.Release|Any CPU.ActiveCfg = Release|Any CPU
@@ -85,20 +75,23 @@ Global
8575
{B6F42305-423F-56FF-090F-B7263547F924}.Debug|Any CPU.Build.0 = Debug|Any CPU
8676
{B6F42305-423F-56FF-090F-B7263547F924}.Release|Any CPU.ActiveCfg = Release|Any CPU
8777
{B6F42305-423F-56FF-090F-B7263547F924}.Release|Any CPU.Build.0 = Release|Any CPU
78+
{0C6D0512-D26D-63D3-5019-C5F7A657B28C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
79+
{0C6D0512-D26D-63D3-5019-C5F7A657B28C}.Debug|Any CPU.Build.0 = Debug|Any CPU
80+
{0C6D0512-D26D-63D3-5019-C5F7A657B28C}.Release|Any CPU.ActiveCfg = Release|Any CPU
81+
{0C6D0512-D26D-63D3-5019-C5F7A657B28C}.Release|Any CPU.Build.0 = Release|Any CPU
8882
EndGlobalSection
8983
GlobalSection(SolutionProperties) = preSolution
9084
HideSolutionNode = FALSE
9185
EndGlobalSection
9286
GlobalSection(NestedProjects) = preSolution
9387
{12260CD2-AFFC-4B2E-8898-F442CAA1FA0F} = {A2F1F52A-9107-4BF8-8C3F-2F6670E7D0AD}
9488
{FF41F619-833D-4FA2-8C53-04D0A1D5AA61} = {2A77AF5C-138A-4EBB-9A13-9205DCD67928}
95-
{76E295FA-9E85-7B99-332A-2CDBFCD5860A} = {02EA681E-C7D8-13C7-8484-4AC65E1B71E8}
96-
{CA0BB450-1903-2F92-A68D-1285976551D6} = {02EA681E-C7D8-13C7-8484-4AC65E1B71E8}
9789
{7C229573-A085-4ECC-8131-958CDA2BE731} = {2A77AF5C-138A-4EBB-9A13-9205DCD67928}
9890
{6499876E-2F76-44A8-B6EB-5B889C6E9B7F} = {02EA681E-C7D8-13C7-8484-4AC65E1B71E8}
9991
{79B94BF9-E557-33DB-3F19-B2C7D9BF8C56} = {2A77AF5C-138A-4EBB-9A13-9205DCD67928}
10092
{B6F42305-423F-56FF-090F-B7263547F924} = {02EA681E-C7D8-13C7-8484-4AC65E1B71E8}
10193
{20AACB9B-307D-419C-BCC6-1C639C402295} = {1288ADA5-1BF1-4A7F-A33E-9EA29097AA40}
94+
{0C6D0512-D26D-63D3-5019-C5F7A657B28C} = {02EA681E-C7D8-13C7-8484-4AC65E1B71E8}
10295
EndGlobalSection
10396
GlobalSection(ExtensibilityGlobals) = postSolution
10497
SolutionGuid = {384A3888-751F-4D75-9AE5-587330582D89}
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,12 @@
1010
<ItemGroup>
1111
<PackageReference Include="Microsoft.Extensions.AI" />
1212
<PackageReference Include="Microsoft.Extensions.AI.OpenAI" />
13+
<PackageReference Include="Anthropic.SDK" />
1314
<PackageReference Include="System.Linq.AsyncEnumerable" />
1415
</ItemGroup>
1516

1617
<ItemGroup>
17-
<ProjectReference Include="..\..\..\..\src\ModelContextProtocol\ModelContextProtocol.csproj" />
18+
<ProjectReference Include="..\..\src\ModelContextProtocol\ModelContextProtocol.csproj" />
1819
</ItemGroup>
1920

2021
</Project>

samples/ChatWithTools/Program.cs

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
using ModelContextProtocol.Client;
2+
using ModelContextProtocol.Protocol.Transport;
3+
using Microsoft.Extensions.AI;
4+
using OpenAI;
5+
6+
// Connect to an MCP server
7+
Console.WriteLine("Connecting client to MCP 'everything' server");
8+
var mcpClient = await McpClientFactory.CreateAsync(
9+
new()
10+
{
11+
Id = "everything",
12+
Name = "Everything",
13+
TransportType = TransportTypes.StdIo,
14+
TransportOptions = new()
15+
{
16+
["command"] = "npx", ["arguments"] = "-y @modelcontextprotocol/server-everything",
17+
}
18+
},
19+
new() { ClientInfo = new() { Name = "ChatClient", Version = "1.0.0" } });
20+
21+
// Get all available tools
22+
Console.WriteLine("Tools available:");
23+
var tools = await mcpClient.GetAIFunctionsAsync();
24+
foreach (var tool in tools)
25+
{
26+
Console.WriteLine($" {tool}");
27+
}
28+
Console.WriteLine();
29+
30+
// Create an IChatClient. (This shows using OpenAIClient, but it could be any other IChatClient implementation.)
31+
// Provide your own OPENAI_API_KEY via an environment variable.
32+
using IChatClient chatClient =
33+
new OpenAIClient(Environment.GetEnvironmentVariable("OPENAI_API_KEY")).AsChatClient("gpt-4o-mini")
34+
.AsBuilder().UseFunctionInvocation().Build();
35+
36+
// Have a conversation, making all tools available to the LLM.
37+
List<ChatMessage> messages = [];
38+
while (true)
39+
{
40+
Console.Write("Q: ");
41+
messages.Add(new(ChatRole.User, Console.ReadLine()));
42+
43+
List<ChatResponseUpdate> updates = [];
44+
await foreach (var update in chatClient.GetStreamingResponseAsync(messages, new() { Tools = [.. tools] }))
45+
{
46+
Console.Write(update);
47+
updates.Add(update);
48+
}
49+
Console.WriteLine();
50+
51+
messages.AddMessages(updates);
52+
}

samples/README.md

Lines changed: 0 additions & 41 deletions
This file was deleted.

samples/anthropic/tools/ToolsConsole/AnthropicToolsConsole.csproj

Lines changed: 0 additions & 19 deletions
This file was deleted.

samples/anthropic/tools/ToolsConsole/McpToolExtensions.cs

Lines changed: 0 additions & 37 deletions
This file was deleted.

samples/anthropic/tools/ToolsConsole/Program.cs

Lines changed: 0 additions & 99 deletions
This file was deleted.

samples/anthropic/tools/ToolsConsole/Properties/launchSettings.json

Lines changed: 0 additions & 7 deletions
This file was deleted.

0 commit comments

Comments
 (0)