ms에 예제 따라 구현

This commit is contained in:
2025-05-29 23:00:05 +09:00
parent b90820172a
commit c8f39f11fb

View File

@@ -1,7 +1,40 @@
internal class Program using Microsoft.Extensions.DependencyInjection;
{ using Microsoft.Extensions.Hosting;
private static void Main(string[] args) using Microsoft.Extensions.Logging;
{ using ModelContextProtocol.Server;
Console.WriteLine("Hello, World!"); using System.ComponentModel;
}
} internal class Program
{
private static async Task Main(string[] args)
{
var builder = Host.CreateApplicationBuilder(args);
builder.Logging.AddConsole(consoleLoggerOptions =>
{
consoleLoggerOptions.LogToStandardErrorThreshold = LogLevel.Trace;
});
builder.Services.
AddMcpServer().
WithStdioServerTransport().
WithToolsFromAssembly();
await builder.Build().RunAsync();
}
}
[McpServerToolType]
public static class EchoTool
{
[McpServerTool, Description("Echoes the message back to the client.")]
public static string Echo(string message) => $"Hello from C#: {message}";
[McpServerTool, Description("Echoes in reverse the message sent by the client.")]
public static string ReverseEcho(string message)
{
char[] charArray = message.ToCharArray();
Array.Reverse(charArray);
var reversed = new string(charArray);
return reversed;
}
}