25 lines
735 B
C#
25 lines
735 B
C#
using Microsoft.Extensions.DependencyInjection;
|
|
using Microsoft.Extensions.Hosting;
|
|
using Microsoft.Extensions.Logging;
|
|
using ModelContextProtocol.Server;
|
|
using System.ComponentModel;
|
|
|
|
var builder = Host.CreateApplicationBuilder(args);
|
|
builder.Logging.AddConsole(consoleLogOptions =>
|
|
{
|
|
// Configure all logs to go to stderr
|
|
consoleLogOptions.LogToStandardErrorThreshold = LogLevel.Trace;
|
|
});
|
|
|
|
builder.Services
|
|
.AddMcpServer()
|
|
.WithStdioServerTransport()
|
|
.WithToolsFromAssembly();
|
|
await builder.Build().RunAsync();
|
|
|
|
[McpServerToolType]
|
|
public static class CalculatorTool
|
|
{
|
|
[McpServerTool, Description("Adds two numbers")]
|
|
public static string Add(int a, int b) => $"Sum {a + b}";
|
|
} |