forked from microsoft/mcp-for-beginners
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
47 lines (40 loc) · 1.23 KB
/
Program.cs
File metadata and controls
47 lines (40 loc) · 1.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/**
* MCP stdio server example - Updated for MCP Specification 2025-06-18
*
* This server demonstrates the recommended stdio transport instead of the
* deprecated SSE transport. The stdio transport is simpler, more secure,
* and provides better performance.
*/
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using server;
// Create host builder for stdio transport
var builder = Host.CreateApplicationBuilder(args);
// Configure services
builder.Services
.AddMcpServer()
.WithStdioServerTransport()
.WithTools<Tools>();
// Configure logging to stderr (never stdout for MCP servers)
builder.Services.AddLogging(logging =>
{
logging.ClearProviders();
logging.AddConsole();
logging.SetMinimumLevel(LogLevel.Information);
});
// Build and run the application
var app = builder.Build();
// Log startup information to stderr
var logger = app.Services.GetRequiredService<ILogger<Program>>();
logger.LogInformation("Starting MCP stdio server...");
logger.LogInformation("Server configured for stdio transport (MCP 2025-06-18)");
try
{
await app.RunAsync();
}
catch (Exception ex)
{
logger.LogError(ex, "Server encountered an error");
throw;
}