-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
61 lines (52 loc) · 2.57 KB
/
Program.cs
File metadata and controls
61 lines (52 loc) · 2.57 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
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using PilotMCP;
var builder = Host.CreateApplicationBuilder(args);
builder.Logging.ClearProviders();
builder.Logging.AddConsole(options =>
{
options.LogToStandardErrorThreshold = LogLevel.Trace;
});
builder.Logging.SetMinimumLevel(LogLevel.Warning);
var connection = new PilotConnection();
builder.Services.AddSingleton(connection);
// Автоподключение из переменных окружения
var serverUrl = Environment.GetEnvironmentVariable("PILOT_SERVER_URL");
var login = Environment.GetEnvironmentVariable("PILOT_LOGIN");
var password = Environment.GetEnvironmentVariable("PILOT_PASSWORD");
var database = Environment.GetEnvironmentVariable("PILOT_DATABASE");
var licenseStr = Environment.GetEnvironmentVariable("PILOT_LICENSE_TYPE");
int licenseType = 100;
if (!string.IsNullOrEmpty(licenseStr))
int.TryParse(licenseStr, out licenseType);
var readonlyStr = Environment.GetEnvironmentVariable("PILOT_READONLY");
bool isReadOnly = string.Equals(readonlyStr, "true", StringComparison.OrdinalIgnoreCase)
|| readonlyStr == "1";
connection.IsReadOnly = isReadOnly;
var serverInstructions = isReadOnly
? "РЕЖИМ ТОЛЬКО ЧТЕНИЯ АКТИВЕН (PILOT_READONLY=true). " +
"Все операции записи, создания, удаления и изменения данных заблокированы. " +
"Доступны только инструменты чтения: GetObject, Search, GetChildren, GetDocumentText, GetHistory и т.д. " +
"Если пользователь просит что-то изменить/создать/удалить — сообщи ему, что сервер работает в режиме только чтения " +
"и попроси отключить PILOT_READONLY для выполнения операций записи."
: null;
builder.Services.AddMcpServer(options =>
{
options.ServerInstructions = serverInstructions;
})
.WithStdioServerTransport()
.WithToolsFromAssembly();
if (!string.IsNullOrEmpty(serverUrl) && !string.IsNullOrEmpty(login) && !string.IsNullOrEmpty(password))
{
try
{
var msg = connection.Connect(serverUrl, login, password, database, licenseType);
Console.Error.WriteLine($"[PilotMCP] {msg}");
}
catch (Exception ex)
{
Console.Error.WriteLine($"[PilotMCP] Ошибка автоподключения: {ex.Message}");
}
}
await builder.Build().RunAsync();