-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
64 lines (54 loc) · 2.37 KB
/
Program.cs
File metadata and controls
64 lines (54 loc) · 2.37 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
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.AI;
using SqlSchemaBridgeMCP.Repositories;
using SqlSchemaBridgeMCP.Services;
using SqlSchemaBridgeMCP.Services.Database;
using SqlSchemaBridgeMCP.Tools;
using ModelContextProtocol.Protocol;
var builder = Host.CreateApplicationBuilder(args);
builder.Logging.AddConsole(o => o.LogToStandardErrorThreshold = LogLevel.Trace);
builder.Services.AddSingleton<ProfileManager>();
builder.Services.AddSingleton<SchemaProvider>();
builder.Services.AddSingleton<SchemaEditorService>();
builder.Services.AddSingleton<CsvConverterService>();
builder.Services.AddSingleton<ProfileValidationService>();
builder.Services.AddSingleton<ISchemaRepository, SchemaRepository>();
builder.Services.AddSingleton<SqlSchemaBridgeTools>();
builder.Services.AddSingleton<SqlSchemaEditorTools>();
builder.Services.AddSingleton<WebDebugService>();
// Database connection services
builder.Services.AddSingleton<DatabaseSchemaProviderFactory>();
builder.Services.AddSingleton<DatabaseSchemaImportService>();
builder.Services.AddSingleton<DatabaseConnectionTools>();
builder.Services
.AddMcpServer()
.WithStdioServerTransport()
.WithTools<SqlSchemaBridgeTools>()
.WithTools<SqlSchemaEditorTools>()
.WithTools<ProfileValidationTools>()
.WithTools<ProfileManagementTools>()
.WithTools<DatabaseConnectionTools>()
.WithListResourcesHandler(SqlSchemaBridgeMCP.Resources.ResourceHandlers.HandleListResources)
.WithReadResourceHandler(SqlSchemaBridgeMCP.Resources.ResourceHandlers.HandleReadResource);
var app = builder.Build();
// Configure and start web debug interface based on configuration
var webConfig = WebDebugConfiguration.FromCommandLineArgs(args);
if (webConfig.EnableWebDebugInterface && webConfig.AutoStartWithMCP)
{
try
{
var webDebugService = app.Services.GetRequiredService<WebDebugService>();
webDebugService.StartInBackground();
// Give the web server a moment to start and report its URL
await Task.Delay(1000);
}
catch (Exception ex)
{
var logger = app.Services.GetRequiredService<ILogger<Program>>();
logger.LogError(ex, "Failed to start web debug interface");
Console.Error.WriteLine($"Warning: Web debug interface failed to start: {ex.Message}");
}
}
await app.RunAsync();