using System; using System.ComponentModel; using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Logging; using Microsoft.Extensions.DependencyInjection; using ModelContextProtocol.Server; namespace McpStudy.McpServerStdIO { internal class Program { static async Task Main(string[] args) { try { var builder = Host.CreateApplicationBuilder(args); builder.Logging.AddConsole(options => { options.LogToStandardErrorThreshold = LogLevel.Trace; }); builder.Services .AddMcpServer() .WithStdioServerTransport() .WithToolsFromAssembly(); await builder.Build().RunAsync(); } catch (Exception e) { Console.WriteLine(e.Message); } finally { } } } } [McpServerToolType] public static class TimeTool { [McpServerTool, Description("Get the current time for a city")] public static string GetCurrentTime(string city) { var message = $"It is {DateTime.Now.Hour}:{DateTime.Now.Minute} in {city}."; File.AppendAllText("Mcplog.txt", $"{message}{System.Environment.NewLine}"); return message; } }