You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

53 lines
1.3 KiB
C#

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}.";
return message;
}
}