diff --git a/server/2015Remote/McpServer.cpp b/server/2015Remote/McpServer.cpp index 3000277..c38b251 100644 --- a/server/2015Remote/McpServer.cpp +++ b/server/2015Remote/McpServer.cpp @@ -117,6 +117,11 @@ std::string GetStringArg(const Json::Value& args, const char* key) { return JsonStrField(args, key); } +// 读取可选整数入参(JSON number 或数字字符串);缺失/非法返回 false(不写 out)。 +// 定义见文件后半段(随 P3 终端会话辅助一起),此处前置声明供早于定义的 exec_command / +// terminal_exec 等工具复用。 +static bool GetIntArg(const Json::Value& args, const char* key, int& out); + // ========== P2b 辅助 ========== // 解析 id 入参(必填、纯数字)为 uint64;非法返回 false。 @@ -2051,11 +2056,8 @@ std::string BuildExecCommand(const Json::Value& id, const Json::Value& args, CMy return BuildError(id, -32007, "Command not allowed by whitelist: " + command); int timeoutMs = kMcpToolTimeoutMs; - std::string t = GetStringArg(args, "timeout_ms"); - if (!t.empty() && IsDigits(t)) { - int v = atoi(t.c_str()); - if (v > 0 && v <= 600000) timeoutMs = v; - } + int v = 0; + if (GetIntArg(args, "timeout_ms", v) && v > 0 && v <= 600000) timeoutMs = v; std::string nonce = GenerateRandomToken().substr(0, 8); @@ -2426,11 +2428,8 @@ std::string BuildTerminalOpen(const Json::Value& id, const Json::Value& args, CM return errJson; int timeoutMs = kMcpToolTimeoutMs; - std::string t = GetStringArg(args, "timeout_ms"); - if (!t.empty() && IsDigits(t)) { - int v = atoi(t.c_str()); - if (v > 0 && v <= 600000) timeoutMs = v; - } + int v = 0; + if (GetIntArg(args, "timeout_ms", v) && v > 0 && v <= 600000) timeoutMs = v; std::string sessionId = GenerateRandomToken(); if (!mcp.BeginTermOpen(devId, sessionId)) @@ -2498,11 +2497,8 @@ std::string BuildTerminalExec(const Json::Value& id, const Json::Value& args, CM "Command contains & or | or a newline (breaks output capture); run chained/piped commands as separate terminal_exec calls"); int timeoutMs = kMcpToolTimeoutMs; - std::string t = GetStringArg(args, "timeout_ms"); - if (!t.empty() && IsDigits(t)) { - int v = atoi(t.c_str()); - if (v > 0 && v <= 600000) timeoutMs = v; - } + int v = 0; + if (GetIntArg(args, "timeout_ms", v) && v > 0 && v <= 600000) timeoutMs = v; std::string nonce = GenerateRandomToken().substr(0, 8); @@ -2751,11 +2747,8 @@ std::string BuildRemoteOpen(const Json::Value& id, const Json::Value& args, CMy2 return BuildError(id, -32003, "Device busy: a remote desktop session is already active for this host"); int timeoutMs = kMcpToolTimeoutMs; - std::string t = GetStringArg(args, "timeout_ms"); - if (!t.empty() && IsDigits(t)) { - int v = atoi(t.c_str()); - if (v > 0 && v <= 600000) timeoutMs = v; - } + int v = 0; + if (GetIntArg(args, "timeout_ms", v) && v > 0 && v <= 600000) timeoutMs = v; std::string sessionId = GenerateRandomToken(); if (!mcp.BeginScreenCtrlOpen(devId, sessionId)) @@ -3579,7 +3572,7 @@ static bool FindSentinel(const std::vector& buf, const std::string& nonce, while (true) { size_t p = s.rfind(marker, from); if (p == std::string::npos) return false; - bool lineStart = (p == 0) || (s[p - 1] == '\n'); + bool lineStart = (p == 0) || (s[p - 1] == '\n') || (s[p - 1] == '\r'); size_t digitPos = p + marker.size(); if (lineStart && digitPos < s.size() && (s[digitPos] == '0' || s[digitPos] == '1')) {