Skip to content

Commit be974b1

Browse files
committed
Simplify client samples
- Remove duplicate projects - Rename MEAIToolsConsole to SimpleClient - Simplify Program.cs
1 parent 33b9582 commit be974b1

File tree

10 files changed

+60
-304
lines changed

10 files changed

+60
-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}") = "SimpleClient", "samples\SimpleClient\SimpleClient.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}

samples/README.md

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

samples/SimpleClient/Program.cs

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
using ModelContextProtocol.Client;
2+
using ModelContextProtocol.Protocol.Transport;
3+
using Microsoft.Extensions.AI;
4+
using OpenAI;
5+
6+
Console.WriteLine("Connecting client to MCP 'everything' server");
7+
var mcpClient = await McpClientFactory.CreateAsync(
8+
new()
9+
{
10+
Id = "everything",
11+
Name = "Everything",
12+
TransportType = TransportTypes.StdIo,
13+
TransportOptions = new()
14+
{
15+
["command"] = "npx",
16+
["arguments"] = "-y @modelcontextprotocol/server-everything",
17+
}
18+
},
19+
new()
20+
{
21+
ClientInfo = new() { Name = "SimpleToolsConsole", Version = "1.0.0" }
22+
});
23+
24+
Console.WriteLine("Tools available:");
25+
var tools = await mcpClient.GetAIFunctionsAsync();
26+
foreach (var tool in tools)
27+
{
28+
Console.WriteLine($" {tool}");
29+
}
30+
Console.WriteLine();
31+
32+
// Note: This shows using OpenAIClient, but it could be any other IChatClient implementation.
33+
// Provide your own OPENAI_API_KEY via an environment variable.
34+
using IChatClient chatClient =
35+
new OpenAIClient(Environment.GetEnvironmentVariable("AI:OpenAI:ApiKey")).AsChatClient("gpt-4o-mini")
36+
.AsBuilder()
37+
.UseFunctionInvocation()
38+
.Build();
39+
40+
List<ChatMessage> messages =
41+
[
42+
new(ChatRole.System, "You are a helpful assistant, helping us test MCP server functionality."),
43+
new(ChatRole.User, "Please call the echo tool with the string 'Hello MCP!' and give me the response as-is.")
44+
];
45+
46+
Console.WriteLine("Asking GPT-4o-mini to call the Echo Tool...");
47+
await foreach (var update in chatClient.GetStreamingResponseAsync(messages, new() { Tools = [.. tools] }))
48+
{
49+
Console.Write(update);
50+
}
51+
Console.WriteLine();
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/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)