LLDB mainline
ProtocolServerMCP.h
Go to the documentation of this file.
1//===- ProtocolServerMCP.h ------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef LLDB_PLUGINS_PROTOCOL_MCP_PROTOCOLSERVERMCP_H
10#define LLDB_PLUGINS_PROTOCOL_MCP_PROTOCOLSERVERMCP_H
11
13#include "lldb/Host/MainLoop.h"
14#include "lldb/Host/Socket.h"
17#include <map>
18#include <memory>
19#include <thread>
20#include <tuple>
21#include <vector>
22
24
27 using TransportUP = std::unique_ptr<lldb_protocol::mcp::MCPTransport>;
28 using ServerUP = std::unique_ptr<lldb_protocol::mcp::Server>;
29
30public:
32 virtual ~ProtocolServerMCP() override;
33
34 virtual llvm::Error Start(ProtocolServer::Connection connection) override;
35 virtual llvm::Error Stop() override;
36
37 static void Initialize();
38 static void Terminate();
39
40 static llvm::StringRef GetPluginNameStatic() { return "MCP"; }
41 static llvm::StringRef GetPluginDescriptionStatic();
42
44
45 llvm::StringRef GetPluginName() override { return GetPluginNameStatic(); }
46
47 Socket *GetSocket() const override { return m_listener.get(); }
48
49protected:
50 // This adds tools and resource providers that
51 // are specific to this server. Overridable by the unit tests.
52 virtual void Extend(lldb_protocol::mcp::Server &server) const;
53
54private:
55 void AcceptCallback(std::unique_ptr<Socket> socket);
56
57 bool m_running = false;
58
61 std::thread m_loop_thread;
62 std::mutex m_mutex;
63 size_t m_client_count = 0;
64
65 std::unique_ptr<Socket> m_listener;
66
67 std::vector<ReadHandleUP> m_listen_handlers;
69 std::tuple<ServerUP, ReadHandleUP, TransportUP>>
71};
72} // namespace lldb_private::mcp
73
74#endif
std::unique_ptr< ReadHandle > ReadHandleUP
std::unique_ptr< Socket > m_listener
virtual void Extend(lldb_protocol::mcp::Server &server) const
virtual llvm::Error Start(ProtocolServer::Connection connection) override
Socket * GetSocket() const override
std::unique_ptr< lldb_protocol::mcp::Server > ServerUP
std::unique_ptr< lldb_protocol::mcp::MCPTransport > TransportUP
static lldb::ProtocolServerUP CreateInstance()
virtual llvm::Error Stop() override
llvm::StringRef GetPluginName() override
void AcceptCallback(std::unique_ptr< Socket > socket)
static llvm::StringRef GetPluginNameStatic()
MainLoopBase::ReadHandleUP ReadHandleUP
lldb_protocol::mcp::ServerInfoHandle m_server_info_handle
std::map< lldb_protocol::mcp::MCPTransport *, std::tuple< ServerUP, ReadHandleUP, TransportUP > > m_instances
static llvm::StringRef GetPluginDescriptionStatic()
std::vector< ReadHandleUP > m_listen_handlers
A handle that tracks the server info on disk and cleans up the disk record once it is no longer refer...
Definition Server.h:110
MainLoopPosix MainLoop
Definition MainLoop.h:20
lldb_private::Transport< Request, Response, Notification > MCPTransport
Generic transport that uses the MCP protocol.
Definition Transport.h:21
std::unique_ptr< lldb_private::ProtocolServer > ProtocolServerUP