|
9 | 9 | #ifndef LLDB_PROTOCOL_MCP_SERVER_H |
10 | 10 | #define LLDB_PROTOCOL_MCP_SERVER_H |
11 | 11 |
|
12 | | -#include "lldb/Host/JSONTransport.h" |
13 | 12 | #include "lldb/Host/MainLoop.h" |
14 | 13 | #include "lldb/Protocol/MCP/Protocol.h" |
15 | 14 | #include "lldb/Protocol/MCP/Resource.h" |
16 | 15 | #include "lldb/Protocol/MCP/Tool.h" |
| 16 | +#include "lldb/Protocol/MCP/Transport.h" |
17 | 17 | #include "llvm/ADT/StringMap.h" |
18 | 18 | #include "llvm/Support/Error.h" |
19 | | -#include <mutex> |
20 | 19 |
|
21 | 20 | namespace lldb_protocol::mcp { |
22 | 21 |
|
23 | | -class MCPTransport |
24 | | - : public lldb_private::JSONRPCTransport<Request, Response, Notification> { |
25 | | -public: |
26 | | - using LogCallback = std::function<void(llvm::StringRef message)>; |
27 | | - |
28 | | - MCPTransport(lldb::IOObjectSP in, lldb::IOObjectSP out, |
29 | | - std::string client_name, LogCallback log_callback = {}) |
30 | | - : JSONRPCTransport(in, out), m_client_name(std::move(client_name)), |
31 | | - m_log_callback(log_callback) {} |
32 | | - virtual ~MCPTransport() = default; |
33 | | - |
34 | | - void Log(llvm::StringRef message) override { |
35 | | - if (m_log_callback) |
36 | | - m_log_callback(llvm::formatv("{0}: {1}", m_client_name, message).str()); |
37 | | - } |
38 | | - |
39 | | -private: |
40 | | - std::string m_client_name; |
41 | | - LogCallback m_log_callback; |
42 | | -}; |
43 | | - |
44 | | -class Server : public MCPTransport::MessageHandler { |
| 22 | +class Server : public Transport::MessageHandler { |
45 | 23 | public: |
46 | 24 | Server(std::string name, std::string version, |
47 | | - std::unique_ptr<MCPTransport> transport_up, |
48 | | - lldb_private::MainLoop &loop); |
| 25 | + std::unique_ptr<Transport> transport_up, lldb_private::MainLoop &loop); |
49 | 26 | ~Server() = default; |
50 | 27 |
|
51 | 28 | using NotificationHandler = std::function<void(const Notification &)>; |
@@ -92,7 +69,7 @@ class Server : public MCPTransport::MessageHandler { |
92 | 69 | const std::string m_name; |
93 | 70 | const std::string m_version; |
94 | 71 |
|
95 | | - std::unique_ptr<MCPTransport> m_transport_up; |
| 72 | + std::unique_ptr<Transport> m_transport_up; |
96 | 73 | lldb_private::MainLoop &m_loop; |
97 | 74 |
|
98 | 75 | llvm::StringMap<std::unique_ptr<Tool>> m_tools; |
|
0 commit comments