#pragma once #include #include #include #include #include // httplib 与 Windows 头部的 min/max 宏冲突,按 file_server.h 的既有约定处理。 #undef min #undef max #include "httplib.h" #ifndef max #define max(a,b) (((a) > (b)) ? (a) : (b)) #endif #ifndef min #define min(a,b) (((a) < (b)) ? (a) : (b)) #endif #pragma comment(lib, "ws2_32.lib") class CMy2015RemoteDlg; // MCP (Model Context Protocol) 服务端:httplib 封装 + JSON-RPC 2.0 分发 + 静态 token 校验。 // 与 CWebService 平级、互不依赖;默认禁用,经「扩展 → MCP设置」开启后监听 // (默认 127.0.0.1:6544,仅本机回环)。见 docs/Mcp_Design.md。 class CMcpServer { public: static CMcpServer& Instance(); void SetParentDlg(CMy2015RemoteDlg* pDlg) { m_parent = pDlg; } void SetToken(const std::string& token) { m_token = token; } bool Start(const std::string& bind, int port); void Stop(); bool IsRunning() const { return m_running.load(); } private: CMcpServer(); ~CMcpServer(); CMcpServer(const CMcpServer&) = delete; CMcpServer& operator=(const CMcpServer&) = delete; // POST /mcp 处理器:token 校验 + JSON-RPC 分发。 void HandleMcp(const httplib::Request& req, httplib::Response& res); httplib::Server m_server; std::thread m_thread; std::atomic m_running{false}; std::string m_token; CMy2015RemoteDlg* m_parent = nullptr; }; // 全局访问器(仿 WebService(),见 WebService.h 末尾) inline CMcpServer& McpServer() { return CMcpServer::Instance(); } // 生成 32 hex(128-bit)随机 token;供运行时兜底与「MCP设置」对话框预填复用。 std::string GenerateRandomToken();