Skip to content

Commit b9dfc51

Browse files
committed
Completing the tools as best as possible
1 parent 3203b80 commit b9dfc51

File tree

7 files changed

+45
-42
lines changed

7 files changed

+45
-42
lines changed

samples/EverythingServer/Program.cs

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -42,17 +42,6 @@
4242
{
4343
Messages = messages
4444
});
45-
})
46-
.WithCallToolHandler((request, ct) =>
47-
{
48-
if (request.Params?.Name == "tiny_image")
49-
{
50-
return Task.FromResult(new CallToolResponse
51-
{
52-
Content = [new Content { Type = "image", Data = TinyImageTool.MCP_TINY_IMAGE, MimeType = "image/png" }]
53-
});
54-
}
55-
throw new NotSupportedException($"Unknown tool name: {request.Params?.Name}");
5645
});
5746

5847
await builder.Build().RunAsync();

samples/EverythingServer/Tools/AddTool.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@ namespace EverythingServer.Tools;
66
[McpServerToolType]
77
public static class AddTool
88
{
9-
[McpServerTool, Description("Adds two numbers.")]
9+
[McpServerTool("add"), Description("Adds two numbers.")]
1010
public static string Add(int a, int b) => $"The sum of {a} and {b} is {a + b}";
1111
}

samples/EverythingServer/Tools/AnnotatedMessageTool.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ public enum MessageType
1313
Debug,
1414
}
1515

16-
[McpServerTool, Description("Generates an annotated message")]
16+
[McpServerTool("annotatedMessage"), Description("Generates an annotated message")]
1717
public static IEnumerable<string> AnnotatedMessage(MessageType messageType, bool includeImage = true)
1818
{
19-
return ["incomplete"];
19+
throw new NotSupportedException("Unable to write annotations to the output.");
2020
}
2121
}

samples/EverythingServer/Tools/EchoTool.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@ namespace EverythingServer.Tools;
66
[McpServerToolType]
77
public static class EchoTool
88
{
9-
[McpServerTool, Description("Echoes the message back to the client.")]
9+
[McpServerTool("echo"), Description("Echoes the message back to the client.")]
1010
public static string Echo(string message) => $"Echo: {message}";
1111
}
Lines changed: 39 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,42 @@
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;
1+
using ModelContextProtocol.Protocol.Messages;
2+
using ModelContextProtocol.Protocol.Types;
3+
using ModelContextProtocol.Server;
4+
using System.ComponentModel;
85

9-
//namespace EverythingServer.Tools;
6+
namespace EverythingServer.Tools;
107

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;
8+
[McpServerToolType]
9+
public static class LongRunningTool
10+
{
11+
[McpServerTool("longRunningOperation"), Description("Demonstrates a long running operation with progress updates")]
12+
public static async Task<string> LongRunningOperation(
13+
IMcpServer server,
14+
RequestContext<CallToolRequestParams> context,
15+
int duration = 10,
16+
int steps = 5)
17+
{
18+
var progressToken = context.Params?.Meta?.ProgressToken;
19+
var stepDuration = duration / steps;
1820

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-
//}
21+
for (int i = 1; i <= steps + 1; i++)
22+
{
23+
await Task.Delay(stepDuration * 1000);
24+
25+
if (progressToken is not null)
26+
{
27+
await server.SendMessageAsync(new JsonRpcNotification
28+
{
29+
Method = "notifications/progress",
30+
Params = new
31+
{
32+
Progress = i,
33+
Total = steps,
34+
progressToken
35+
}
36+
});
37+
}
38+
}
39+
40+
return $"Long running operation completed. Duration: {duration} seconds. Steps: {steps}.";
41+
}
42+
}

samples/EverythingServer/Tools/PrintEnvTool.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public static class PrintEnvTool
1313
WriteIndented = true
1414
};
1515

16-
[McpServerTool, Description("Prints all environment variables, helpful for debugging MCP server configuration")]
16+
[McpServerTool("printEnv"), Description("Prints all environment variables, helpful for debugging MCP server configuration")]
1717
public static string PrintEnv()
1818
{
1919
Debugger.Launch();

samples/EverythingServer/Tools/TinyImageTool.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public static IEnumerable<AIContent> GetTinyImage()
1414
Debugger.Launch();
1515
return [
1616
new TextContent("This is a tiny image:"),
17-
new DataContent(MCP_TINY_IMAGE, "image/png"),
17+
new DataContent(MCP_TINY_IMAGE),
1818
new TextContent("The image above is the MCP tiny image.")
1919
];
2020
}

0 commit comments

Comments
 (0)