-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
71 lines (66 loc) · 3.82 KB
/
Program.cs
File metadata and controls
71 lines (66 loc) · 3.82 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
69
70
71
using System.Collections.Frozen;
using System.Text.Json;
using DotnetDebugMcp;
using ModelContextProtocol.Protocol;
using ModelContextProtocol.Server;
// MCP-сервер для отладки .NET: DAP + интеграция с Visual Studio (DTE).
// Сейчас: хранение брейкпоинтов (set/list/clear); DAP launch + continue/next.
var toolsList = ToolCatalog.Build();
var options = new McpServerOptions
{
ServerInfo = new Implementation { Name = "DotnetDebugMcp", Version = "0.3.0" },
ProtocolVersion = "2024-11-05",
Capabilities = new ServerCapabilities { Tools = new ToolsCapability { ListChanged = false } },
Handlers = new McpServerHandlers
{
ListToolsHandler = (_, _) => ValueTask.FromResult(new ListToolsResult { Tools = toolsList }),
CallToolHandler = async (request, cancellationToken) =>
{
var name = request.Params?.Name ?? "";
var args = request.Params?.Arguments is IReadOnlyDictionary<string, JsonElement> a
? a
: FrozenDictionary<string, JsonElement>.Empty;
try
{
cancellationToken.ThrowIfCancellationRequested();
string text = name switch
{
"debug_ping" => $"OK {DateTime.UtcNow:O} — DotnetDebugMcp. Tools: {string.Join(", ", toolsList.Select(t => t.Name))}.",
"debug_set_breakpoints" => BreakpointToolHandlers.HandleSetBreakpoints(args),
"debug_list_breakpoints" => BreakpointToolHandlers.HandleListBreakpoints(args),
"debug_clear_breakpoints" => BreakpointToolHandlers.HandleClearBreakpoints(args),
"debug_launch" => await DebugLaunchToolHandlers.HandleDebugLaunch(args),
"debug_attach" => await DebugLaunchToolHandlers.HandleDebugAttach(args),
"debug_continue" => await DebugControlToolHandlers.HandleDebugContinue(args),
"debug_step_over" => await DebugControlToolHandlers.HandleDebugStepOver(args),
"debug_step_into" => await DebugControlToolHandlers.HandleDebugStepInto(args),
"debug_step_out" => await DebugControlToolHandlers.HandleDebugStepOut(args),
"debug_stop" => await DebugControlToolHandlers.HandleDebugStop(args),
"debug_stack_trace" => await DebugControlToolHandlers.HandleDebugStackTrace(args),
"debug_variables" => await DebugControlToolHandlers.HandleDebugVariables(args),
"debug_variable_children" => await DebugControlToolHandlers.HandleDebugVariableChildren(args),
_ => throw new ArgumentException($"Unknown tool: {name}.")
};
return new CallToolResult { Content = [new TextContentBlock { Text = text }] };
}
catch (ArgumentException ex)
{
return new CallToolResult { Content = [new TextContentBlock { Text = $"Error: {ex.Message}" }], IsError = true };
}
catch (OperationCanceledException)
{
// Хост MCP отменил вызов (таймаут, закрытие сессии) — не смешиваем с сбоями DAP/netcoredbg.
var tag = string.IsNullOrEmpty(name) ? "(unknown)" : name;
return new CallToolResult { Content = [new TextContentBlock { Text = $"# Aborted: {tag}" }] };
}
catch (Exception ex)
{
return new CallToolResult { Content = [new TextContentBlock { Text = "Error: " + DapHelpers.FormatException(ex) }], IsError = true };
}
}
}
};
var transport = new StdioServerTransport("DotnetDebugMcp");
await using var server = McpServer.Create(transport, options);
await server.RunAsync();
return 0;