Feature: Add MCP tools for remote chat with the client user
Add chat_open, chat_send, chat_wait and chat_close to the MCP tool set, behind a new McpChat switch that defaults to off and is independent of the read-only switch. The tools reuse the existing client chat link: the main connection sends COMMAND_CHAT, the client opens a sub-connection with TOKEN_CONN_AUTH and TOKEN_CHAT_START, the server answers with COMMAND_NEXT_CHAT, and both directions then carry raw CP936 text. Sessions are per host and held in shared pointers under their own mutex, so a waiting chat_wait survives a close or a dropped sub-connection, and chat_send is serialised per session. Text is converted strictly between UTF-8 and CP936: invalid UTF-8, characters GBK cannot represent (emoji, accented letters) and messages over the client's 4000-byte buffer are rejected with -32602 instead of being mangled. A one-second settle delay after the sub-connection binds keeps the first message from reaching the client before its chat window exists. The routing hooks run before the host-management hooks in MessageHandle and clear the route in OfflineProc before the context leaves the list. A five-second tombstone absorbs a late TOKEN_CHAT_START after a timeout, so a failed chat_open does not pop the MFC chat dialog. Idle sessions are swept on every tool call, and audit entries record the session id and byte counts only, never message bodies. The settings dialog gains the chat checkbox and the translated labels for all three languages, and the strict UTF-8 to CP936 helpers move from McpMachine.cpp to McpInternal so both tool families can share them. Co-Authored-By: deepseek-flash
This commit is contained in:
1 parent
fff7c67af6
commit
c99a1c375e
17 files changed
+1519
-31
No files matched your search
@@ -0,0 +1,30 @@
|
||||
#pragma once
|
||||
|
||||
// MCP「远程交谈」工具族:chat_open / chat_send / chat_wait / chat_close。
|
||||
//
|
||||
// 复用 Windows 客户端既有的「远程交谈」链路(协议不变):
|
||||
// 主连接 [COMMAND_CHAT=161]
|
||||
// → 客户端子连接先 [TOKEN_CONN_AUTH=246],再 [TOKEN_CHAT_START=62]
|
||||
// → 服务端在子连接回 [COMMAND_NEXT_CHAT=0](客户端据此弹 IDD_CHAT)
|
||||
// → 双向文本 [CP936 字节][NUL];服务端 [COMMAND_CHAT_CLOSE=1] 结束。
|
||||
//
|
||||
// 会话状态由 CMcpServer 持有(McpServer.h),本文件只负责工具 schema、参数校验、
|
||||
// 编码转换与响应构造。协议、客户端怪癖与验证矩阵见 docs/Mcp_Chat_Design.md。
|
||||
|
||||
#include "jsoncpp/json.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
class CMy2015RemoteDlg;
|
||||
|
||||
namespace McpChat {
|
||||
|
||||
bool Handles(const std::string& toolName);
|
||||
|
||||
// 开关 close 时不追加任何工具(tools/list 与调用侧一致)。
|
||||
void AppendTools(Json::Value& tools);
|
||||
|
||||
std::string Call(const Json::Value& id, const std::string& toolName,
|
||||
const Json::Value& args, CMy2015RemoteDlg* parent);
|
||||
|
||||
} // namespace McpChat
|
||||
Reference in new issue
Block a user