-
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathProgram.cs
More file actions
68 lines (53 loc) · 1.91 KB
/
Program.cs
File metadata and controls
68 lines (53 loc) · 1.91 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
// This Source Code Form is subject to the terms of the MIT License.
// If a copy of the MIT was not distributed with this file, You can obtain one at https://opensource.org/licenses/MIT.
// Copyright (C) Leszek Pomianowski and OpenAPI Client Contributors.
// All Rights Reserved.
WebApplicationBuilder builder = WebApplication.CreateBuilder(args);
builder.Logging.AddConsole(consoleLogOptions =>
{
// Configure all logs to go to stderr
consoleLogOptions.LogToStandardErrorThreshold = LogLevel.Trace;
});
#if DEBUG
builder
.Services.AddOpenTelemetry()
.WithTracing(b => b.AddSource("*").AddAspNetCoreInstrumentation().AddHttpClientInstrumentation())
.WithMetrics(b => b.AddMeter("*").AddAspNetCoreInstrumentation().AddHttpClientInstrumentation())
.WithLogging()
.UseOtlpExporter();
#endif
builder.Services.AddTransient<IOpenApiService, OpenApiService>();
builder.Services.AddHttpClient();
ServerOptions serverOptions = new();
IConfigurationSection section = builder.Configuration.GetSection("Server");
section.Bind(serverOptions);
string? mode = Environment.GetEnvironmentVariable("mode") ?? Environment.GetEnvironmentVariable("MODE");
if (mode?.Contains("both", StringComparison.InvariantCultureIgnoreCase) ?? false)
{
serverOptions.Mode = McpMode.Both;
}
else if (mode?.Contains("http", StringComparison.InvariantCultureIgnoreCase) ?? false)
{
serverOptions.Mode = McpMode.Http;
}
IMcpServerBuilder mcpBuilder = builder.Services.AddMcpServer();
if (serverOptions.Mode == McpMode.Both)
{
_ = mcpBuilder.WithHttpTransport().WithStdioServerTransport();
}
else if (serverOptions.Mode == McpMode.Stdio)
{
_ = mcpBuilder.WithStdioServerTransport();
}
else
{
_ = mcpBuilder.WithHttpTransport();
}
_ = mcpBuilder.WithTools<OpenApiTools>();
await using WebApplication app = builder.Build();
if (serverOptions.Mode is McpMode.Http or McpMode.Both)
{
app.MapMcp();
}
await app.RunAsync();
return;