parent
a609aa295e
commit
54576033eb
1 changed files with 94 additions and 0 deletions
30
samples/FileBasedMcpServer/Program.cs
Executable file
30
samples/FileBasedMcpServer/Program.cs
Executable file
|
|
@ -0,0 +1,30 @@
|
|||
#!/usr/bin/env -S dotnet run --
|
||||
#:package Microsoft.Extensions.Hosting
|
||||
#:project ../../src/ModelContextProtocol/ModelContextProtocol.csproj
|
||||
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using ModelContextProtocol.Server;
|
||||
using System.ComponentModel;
|
||||
|
||||
var builder = Host.CreateApplicationBuilder(args);
|
||||
|
||||
builder.Services.AddMcpServer()
|
||||
.WithStdioServerTransport()
|
||||
.WithTools<EchoTool>();
|
||||
|
||||
builder.Logging.AddConsole(options =>
|
||||
{
|
||||
options.LogToStandardErrorThreshold = LogLevel.Trace;
|
||||
});
|
||||
|
||||
await builder.Build().RunAsync();
|
||||
|
||||
// File-scoped tool class
|
||||
[McpServerToolType]
|
||||
file class EchoTool
|
||||
{
|
||||
[McpServerTool(Name = "echo"), Description("Echoes the message back to the client.")]
|
||||
public static string Echo([Description("The message to echo back.")] string message) => $"Echo: {message}";
|
||||
}
|
||||
Loading…
Reference in a new issue