Skip to content

Commit b75b6bc

Browse files
committed
Updating
1 parent 933f9f6 commit b75b6bc

File tree

9 files changed

+165
-160
lines changed

9 files changed

+165
-160
lines changed
Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
1-
<Project Sdk="Microsoft.NET.Sdk">
2-
3-
<PropertyGroup>
4-
<TargetFramework>net9.0</TargetFramework>
5-
<Nullable>enable</Nullable>
6-
<ImplicitUsings>enable</ImplicitUsings>
7-
<OutputType>Exe</OutputType>
8-
</PropertyGroup>
9-
10-
<ItemGroup>
11-
<PackageReference Include="Microsoft.Extensions.Hosting" />
12-
</ItemGroup>
13-
14-
<ItemGroup>
15-
<ProjectReference Include="..\..\src\ModelContextProtocol\ModelContextProtocol.csproj" />
16-
</ItemGroup>
17-
18-
</Project>
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net9.0</TargetFramework>
5+
<Nullable>enable</Nullable>
6+
<ImplicitUsings>enable</ImplicitUsings>
7+
<OutputType>Exe</OutputType>
8+
</PropertyGroup>
9+
10+
<ItemGroup>
11+
<PackageReference Include="Microsoft.Extensions.Hosting" />
12+
</ItemGroup>
13+
14+
<ItemGroup>
15+
<ProjectReference Include="..\..\src\ModelContextProtocol\ModelContextProtocol.csproj" />
16+
</ItemGroup>
17+
18+
</Project>

samples/EverythingServer/Program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
builder.Services
99
.AddMcpServer()
1010
.WithStdioServerTransport()
11-
.WithTools()
11+
.WithToolsFromAssembly()
1212
.WithListPromptsHandler((ctx, ct) =>
1313
{
1414
return Task.FromResult(new ListPromptsResult
Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
using ModelContextProtocol.Server;
2-
using System.ComponentModel;
3-
4-
namespace EverythingServer.Tools;
5-
6-
[McpServerToolType]
7-
public static class AddTool
8-
{
9-
[McpServerTool, Description("Adds two numbers.")]
10-
public static string Add(int a, int b) => $"The sum of {a} and {b} is {a + b}";
11-
}
1+
using ModelContextProtocol.Server;
2+
using System.ComponentModel;
3+
4+
namespace EverythingServer.Tools;
5+
6+
[McpServerToolType]
7+
public static class AddTool
8+
{
9+
[McpServerTool, Description("Adds two numbers.")]
10+
public static string Add(int a, int b) => $"The sum of {a} and {b} is {a + b}";
11+
}
Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
1-
using ModelContextProtocol.Server;
2-
using System.ComponentModel;
3-
4-
namespace EverythingServer.Tools;
5-
6-
[McpServerToolType]
7-
public static class AnnotatedMessageTool
8-
{
9-
public enum MessageType
10-
{
11-
Error,
12-
Success,
13-
Debug,
14-
}
15-
16-
[McpServerTool, Description("Generates an annotated message")]
17-
public static IEnumerable<string> AnnotatedMessage(MessageType messageType, bool includeImage = true)
18-
{
19-
return ["incomplete"];
20-
}
21-
}
1+
using ModelContextProtocol.Server;
2+
using System.ComponentModel;
3+
4+
namespace EverythingServer.Tools;
5+
6+
[McpServerToolType]
7+
public static class AnnotatedMessageTool
8+
{
9+
public enum MessageType
10+
{
11+
Error,
12+
Success,
13+
Debug,
14+
}
15+
16+
[McpServerTool, Description("Generates an annotated message")]
17+
public static IEnumerable<string> AnnotatedMessage(MessageType messageType, bool includeImage = true)
18+
{
19+
return ["incomplete"];
20+
}
21+
}
Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
using ModelContextProtocol.Server;
2-
using System.ComponentModel;
3-
4-
namespace EverythingServer.Tools;
5-
6-
[McpServerToolType]
7-
public static class EchoTool
8-
{
9-
[McpServerTool, Description("Echoes the message back to the client.")]
10-
public static string Echo(string message) => $"Echo: {message}";
11-
}
1+
using ModelContextProtocol.Server;
2+
using System.ComponentModel;
3+
4+
namespace EverythingServer.Tools;
5+
6+
[McpServerToolType]
7+
public static class EchoTool
8+
{
9+
[McpServerTool, Description("Echoes the message back to the client.")]
10+
public static string Echo(string message) => $"Echo: {message}";
11+
}
Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,28 @@
1-
//using ModelContextProtocol.Server;
2-
//using System;
3-
//using System.Collections.Generic;
4-
//using System.ComponentModel;
5-
//using System.Linq;
6-
//using System.Text;
7-
//using System.Threading.Tasks;
8-
9-
//namespace EverythingServer.Tools;
10-
11-
//[McpServerToolType]
12-
//public static class LongRunningTool
13-
//{
14-
// [McpServerTool, Description("Demonstrates a long running operation with progress updates")]
15-
// public static async Task<string> LongRunningOperation(int duration, int steps)
16-
// {
17-
// var stepDuration = duration / steps;
18-
19-
// for (int i = 1; i <= steps + 1; i++)
20-
// {
21-
// // Simulate a long-running operation
22-
// await Task.Delay(stepDuration);
23-
// // Report progress
24-
// var progress = (i * 100) / steps;
25-
// Console.WriteLine($"Progress: {progress}%");
26-
// }
27-
// }
28-
//}
1+
//using ModelContextProtocol.Server;
2+
//using System;
3+
//using System.Collections.Generic;
4+
//using System.ComponentModel;
5+
//using System.Linq;
6+
//using System.Text;
7+
//using System.Threading.Tasks;
8+
9+
//namespace EverythingServer.Tools;
10+
11+
//[McpServerToolType]
12+
//public static class LongRunningTool
13+
//{
14+
// [McpServerTool, Description("Demonstrates a long running operation with progress updates")]
15+
// public static async Task<string> LongRunningOperation(int duration, int steps)
16+
// {
17+
// var stepDuration = duration / steps;
18+
19+
// for (int i = 1; i <= steps + 1; i++)
20+
// {
21+
// // Simulate a long-running operation
22+
// await Task.Delay(stepDuration);
23+
// // Report progress
24+
// var progress = (i * 100) / steps;
25+
// Console.WriteLine($"Progress: {progress}%");
26+
// }
27+
// }
28+
//}
Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
1-
using ModelContextProtocol.Server;
2-
using System.ComponentModel;
3-
using System.Diagnostics;
4-
using System.Text.Json;
5-
6-
namespace EverythingServer.Tools;
7-
8-
[McpServerToolType]
9-
public static class PrintEnvTool
10-
{
11-
private static readonly JsonSerializerOptions options = new()
12-
{
13-
WriteIndented = true
14-
};
15-
16-
[McpServerTool, Description("Prints all environment variables, helpful for debugging MCP server configuration")]
17-
public static string PrintEnv()
18-
{
19-
Debugger.Launch();
20-
var envVars = Environment.GetEnvironmentVariables();
21-
return JsonSerializer.Serialize(envVars, options);
22-
}
23-
}
1+
using ModelContextProtocol.Server;
2+
using System.ComponentModel;
3+
using System.Diagnostics;
4+
using System.Text.Json;
5+
6+
namespace EverythingServer.Tools;
7+
8+
[McpServerToolType]
9+
public static class PrintEnvTool
10+
{
11+
private static readonly JsonSerializerOptions options = new()
12+
{
13+
WriteIndented = true
14+
};
15+
16+
[McpServerTool, Description("Prints all environment variables, helpful for debugging MCP server configuration")]
17+
public static string PrintEnv()
18+
{
19+
Debugger.Launch();
20+
var envVars = Environment.GetEnvironmentVariables();
21+
return JsonSerializer.Serialize(envVars, options);
22+
}
23+
}
Lines changed: 43 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,43 @@
1-
using ModelContextProtocol.Protocol.Types;
2-
using ModelContextProtocol.Server;
3-
using System.ComponentModel;
4-
5-
namespace EverythingServer.Tools;
6-
7-
[McpServerToolType]
8-
public class SampleLlmTool(IMcpServer server)
9-
{
10-
private readonly IMcpServer _server = server ?? throw new ArgumentNullException(nameof(server));
11-
12-
[McpServerTool("sampleLLM"), Description("Samples from an LLM using MCP's sampling feature")]
13-
public async Task<string> SampleLLM(
14-
[Description("The prompt to send to the LLM")] string prompt,
15-
[Description("Maximum number of tokens to generate")] int maxTokens,
16-
CancellationToken cancellationToken)
17-
{
18-
var samplingParams = CreateRequestSamplingParams(prompt ?? string.Empty, "sampleLLM", maxTokens);
19-
var sampleResult = await _server.RequestSamplingAsync(samplingParams, cancellationToken);
20-
21-
return $"LLM sampling result: {sampleResult.Content.Text}";
22-
}
23-
24-
private static CreateMessageRequestParams CreateRequestSamplingParams(string context, string uri, int maxTokens = 100)
25-
{
26-
return new CreateMessageRequestParams()
27-
{
28-
Messages = [new SamplingMessage()
29-
{
30-
Role = Role.User,
31-
Content = new Content()
32-
{
33-
Type = "text",
34-
Text = $"Resource {uri} context: {context}"
35-
}
36-
}],
37-
SystemPrompt = "You are a helpful test server.",
38-
MaxTokens = maxTokens,
39-
Temperature = 0.7f,
40-
IncludeContext = ContextInclusion.ThisServer
41-
};
42-
}
43-
}
1+
using ModelContextProtocol.Protocol.Types;
2+
using ModelContextProtocol.Server;
3+
using System.ComponentModel;
4+
5+
namespace EverythingServer.Tools;
6+
7+
[McpServerToolType]
8+
public class SampleLlmTool(IMcpServer server)
9+
{
10+
private readonly IMcpServer _server = server ?? throw new ArgumentNullException(nameof(server));
11+
12+
[McpServerTool("sampleLLM"), Description("Samples from an LLM using MCP's sampling feature")]
13+
public async Task<string> SampleLLM(
14+
[Description("The prompt to send to the LLM")] string prompt,
15+
[Description("Maximum number of tokens to generate")] int maxTokens,
16+
CancellationToken cancellationToken)
17+
{
18+
var samplingParams = CreateRequestSamplingParams(prompt ?? string.Empty, "sampleLLM", maxTokens);
19+
var sampleResult = await _server.RequestSamplingAsync(samplingParams, cancellationToken);
20+
21+
return $"LLM sampling result: {sampleResult.Content.Text}";
22+
}
23+
24+
private static CreateMessageRequestParams CreateRequestSamplingParams(string context, string uri, int maxTokens = 100)
25+
{
26+
return new CreateMessageRequestParams()
27+
{
28+
Messages = [new SamplingMessage()
29+
{
30+
Role = Role.User,
31+
Content = new Content()
32+
{
33+
Type = "text",
34+
Text = $"Resource {uri} context: {context}"
35+
}
36+
}],
37+
SystemPrompt = "You are a helpful test server.",
38+
MaxTokens = maxTokens,
39+
Temperature = 0.7f,
40+
IncludeContext = ContextInclusion.ThisServer
41+
};
42+
}
43+
}

0 commit comments

Comments
 (0)