Commit 157d6af9 authored by shrabbit's avatar shrabbit
Browse files

♻️ refactor(InfiniteWait): 改用 JSON 序列化 Transport 数据并引入 Spectre.Console 优化等待窗口显示

parent 3355bc75
Loading
Loading
Loading
Loading
+10 −7
Original line number Diff line number Diff line
using System.ComponentModel;
using System.Diagnostics;
using System.Text.Json;
using McpBase.Shared;
using ModelContextProtocol.Server;

@@ -7,20 +8,22 @@ namespace McpBase.McpServer.Tools;

public class RequestTools
{
    [McpServerTool, Description("进行无限等待。由用户决定是否结束。返回从请求等待到同意继续之间的耗时(秒)。")]
    public async Task<string> InfiniteWait([Description("message")]string? msg)
    [McpServerTool, Description("Pause execution and wait indefinitely for human interaction. A separate window (McpBase.Request.exe) is launched showing the provided message to the user; the call blocks until the user closes that window. Use this when the agent needs human confirmation, review, or intervention before continuing. Returns the elapsed wait time in seconds (string, 3 decimal places). Note: the launched window is independent and does not share stdin/stdout with the MCP server.")]
    public async Task<string> InfiniteWait([Description("Message displayed to the user in the waiting window. Explain clearly what the agent is waiting for and what action the user should take to resume (e.g. 'Please review the proposed change and close this window when ready to continue').")] string? msg)
    {
        var sw = Stopwatch.StartNew();
        var self = Process.GetCurrentProcess().Id;

        var json = JsonSerializer.Serialize(new SendInfWaitTransport
        {
            Pid = self,
            Message = msg ?? string.Empty
        });
        var psi = new ProcessStartInfo(Path.Join(AppDomain.CurrentDomain.BaseDirectory, "McpBase.Request.exe"))
        {
            ArgumentList =
            {
                SendInfWaitTransport.GetTransportString(new SendInfWaitTransport
                {
                    Pid = self,
                    Message = msg ?? string.Empty
                })
                json
            },
            UseShellExecute = true
        };
+2 −1
Original line number Diff line number Diff line
using System.Text.Json;
using McpBase.Shared;
using Spectre.Console;

namespace McpBase.Request;

@@ -14,7 +15,7 @@ class Program

        HandleTid<SendInfWaitTransport>(tp!.Tid, args[0], 1, s =>
        {
            Console.WriteLine($"PID: {s.Pid} 正在进行无限等待。\n输入 'y' 或关闭控制台来结束等待。\n\n{s.Message}\n");
            AnsiConsole.MarkupLine($"PID: {s.Pid} 正在进行无限等待。\n输入 'y' 或关闭控制台来结束等待。\n\n{s.Message}\n");
            while (Console.ReadKey().Key != ConsoleKey.Y)
            {
            }
+4 −0
Original line number Diff line number Diff line
@@ -6,4 +6,8 @@
        <Nullable>enable</Nullable>
    </PropertyGroup>

    <ItemGroup>
      <PackageReference Include="Spectre.Console" Version="0.57.2" />
    </ItemGroup>

</Project>