LLDB mainline
Public Types | Public Member Functions | Protected Types | Protected Member Functions | Private Attributes | List of all members
lldb_protocol::mcp::Server Class Reference

#include <Server.h>

Inheritance diagram for lldb_protocol::mcp::Server:
[legend]

Public Types

using NotificationHandler = std::function< void(const Notification &)>
 

Public Member Functions

 Server (std::string name, std::string version, std::unique_ptr< MCPTransport > transport_up, lldb_private::MainLoop &loop)
 
 ~Server ()=default
 
void AddTool (std::unique_ptr< Tool > tool)
 
void AddResourceProvider (std::unique_ptr< ResourceProvider > resource_provider)
 
void AddNotificationHandler (llvm::StringRef method, NotificationHandler handler)
 
llvm::Error Run ()
 
- Public Member Functions inherited from lldb_private::Transport< Req, Resp, Evt >::MessageHandler
virtual ~MessageHandler ()=default
 
virtual void Received (const Evt &)=0
 Called when an event is received.
 
virtual void Received (const Req &)=0
 Called when a request is received.
 
virtual void Received (const Resp &)=0
 Called when a response is received.
 
virtual void OnError (llvm::Error)=0
 Called when an error occurs while reading from the transport.
 
virtual void OnClosed ()=0
 Called on EOF or client disconnect.
 

Protected Types

using RequestHandler = std::function< llvm::Expected< Response >(const Request &)>
 

Protected Member Functions

ServerCapabilities GetCapabilities ()
 
void AddRequestHandlers ()
 
void AddRequestHandler (llvm::StringRef method, RequestHandler handler)
 
llvm::Expected< std::optional< Message > > HandleData (llvm::StringRef data)
 
llvm::Expected< ResponseHandle (const Request &request)
 
void Handle (const Notification &notification)
 
llvm::Expected< ResponseInitializeHandler (const Request &)
 
llvm::Expected< ResponseToolsListHandler (const Request &)
 
llvm::Expected< ResponseToolsCallHandler (const Request &)
 
llvm::Expected< ResponseResourcesListHandler (const Request &)
 
llvm::Expected< ResponseResourcesReadHandler (const Request &)
 
void Received (const Request &) override
 
void Received (const Response &) override
 
void Received (const Notification &) override
 
void OnError (llvm::Error) override
 Called when an error occurs while reading from the transport.
 
void OnClosed () override
 Called on EOF or client disconnect.
 
void TerminateLoop ()
 

Private Attributes

const std::string m_name
 
const std::string m_version
 
std::unique_ptr< MCPTransportm_transport_up
 
lldb_private::MainLoopm_loop
 
llvm::StringMap< std::unique_ptr< Tool > > m_tools
 
std::vector< std::unique_ptr< ResourceProvider > > m_resource_providers
 
llvm::StringMap< RequestHandlerm_request_handlers
 
llvm::StringMap< NotificationHandlerm_notification_handlers
 

Detailed Description

Definition at line 53 of file Server.h.

Member Typedef Documentation

◆ NotificationHandler

using lldb_protocol::mcp::Server::NotificationHandler = std::function<void(const Notification &)>

Definition at line 60 of file Server.h.

◆ RequestHandler

using lldb_protocol::mcp::Server::RequestHandler = std::function<llvm::Expected<Response>(const Request &)>
protected

Definition at line 72 of file Server.h.

Constructor & Destructor Documentation

◆ Server()

Server::Server ( std::string  name,
std::string  version,
std::unique_ptr< MCPTransport transport_up,
lldb_private::MainLoop loop 
)

Definition at line 29 of file Server.cpp.

References AddRequestHandlers().

◆ ~Server()

lldb_protocol::mcp::Server::~Server ( )
default

Member Function Documentation

◆ AddNotificationHandler()

void Server::AddNotificationHandler ( llvm::StringRef  method,
NotificationHandler  handler 
)

Definition at line 89 of file Server.cpp.

References m_notification_handlers.

Referenced by lldb_private::mcp::ProtocolServerMCP::Extend().

◆ AddRequestHandler()

void Server::AddRequestHandler ( llvm::StringRef  method,
RequestHandler  handler 
)
protected

Definition at line 85 of file Server.cpp.

References m_request_handlers.

Referenced by AddRequestHandlers().

◆ AddRequestHandlers()

void Server::AddRequestHandlers ( )
protected

◆ AddResourceProvider()

void Server::AddResourceProvider ( std::unique_ptr< ResourceProvider resource_provider)

Definition at line 78 of file Server.cpp.

References m_resource_providers.

Referenced by lldb_private::mcp::ProtocolServerMCP::Extend().

◆ AddTool()

void Server::AddTool ( std::unique_ptr< Tool tool)

Definition at line 72 of file Server.cpp.

References m_tools.

Referenced by lldb_private::mcp::ProtocolServerMCP::Extend().

◆ GetCapabilities()

ServerCapabilities Server::GetCapabilities ( )
protected

◆ Handle() [1/2]

void Server::Handle ( const Notification notification)
protected

Definition at line 64 of file Server.cpp.

References m_notification_handlers, and lldb_protocol::mcp::Notification::method.

◆ Handle() [2/2]

llvm::Expected< Response > Server::Handle ( const Request request)
protected

◆ HandleData()

llvm::Expected< std::optional< Message > > lldb_protocol::mcp::Server::HandleData ( llvm::StringRef  data)
protected

◆ InitializeHandler()

llvm::Expected< Response > Server::InitializeHandler ( const Request request)
protected

◆ OnClosed()

void Server::OnClosed ( )
overrideprotectedvirtual

Called on EOF or client disconnect.

Implements lldb_private::Transport< Req, Resp, Evt >::MessageHandler.

Definition at line 256 of file Server.cpp.

References m_transport_up, and TerminateLoop().

◆ OnError()

void Server::OnError ( llvm::Error  )
overrideprotectedvirtual

Called when an error occurs while reading from the transport.

NOTE: This does NOT indicate that a specific request failed, but that there was an error in the underlying transport.

Implements lldb_private::Transport< Req, Resp, Evt >::MessageHandler.

Definition at line 251 of file Server.cpp.

References error(), m_transport_up, and TerminateLoop().

◆ Received() [1/3]

void Server::Received ( const Notification notification)
overrideprotected

Definition at line 247 of file Server.cpp.

References Handle().

◆ Received() [2/3]

void Server::Received ( const Request request)
overrideprotected

◆ Received() [3/3]

void Server::Received ( const Response response)
overrideprotected

Definition at line 243 of file Server.cpp.

References m_transport_up.

◆ ResourcesListHandler()

llvm::Expected< Response > Server::ResourcesListHandler ( const Request request)
protected

◆ ResourcesReadHandler()

llvm::Expected< Response > Server::ResourcesReadHandler ( const Request request)
protected

◆ Run()

llvm::Error Server::Run ( )

◆ TerminateLoop()

void Server::TerminateLoop ( )
protected

◆ ToolsCallHandler()

llvm::Expected< Response > Server::ToolsCallHandler ( const Request request)
protected

◆ ToolsListHandler()

llvm::Expected< Response > Server::ToolsListHandler ( const Request request)
protected

Member Data Documentation

◆ m_loop

lldb_private::MainLoop& lldb_protocol::mcp::Server::m_loop
private

Definition at line 105 of file Server.h.

Referenced by Run(), and TerminateLoop().

◆ m_name

const std::string lldb_protocol::mcp::Server::m_name
private

Definition at line 101 of file Server.h.

Referenced by InitializeHandler().

◆ m_notification_handlers

llvm::StringMap<NotificationHandler> lldb_protocol::mcp::Server::m_notification_handlers
private

Definition at line 111 of file Server.h.

Referenced by AddNotificationHandler(), and Handle().

◆ m_request_handlers

llvm::StringMap<RequestHandler> lldb_protocol::mcp::Server::m_request_handlers
private

Definition at line 110 of file Server.h.

Referenced by AddRequestHandler(), and Handle().

◆ m_resource_providers

std::vector<std::unique_ptr<ResourceProvider> > lldb_protocol::mcp::Server::m_resource_providers
private

Definition at line 108 of file Server.h.

Referenced by AddResourceProvider(), ResourcesListHandler(), and ResourcesReadHandler().

◆ m_tools

llvm::StringMap<std::unique_ptr<Tool> > lldb_protocol::mcp::Server::m_tools
private

Definition at line 107 of file Server.h.

Referenced by AddTool(), ToolsCallHandler(), and ToolsListHandler().

◆ m_transport_up

std::unique_ptr<MCPTransport> lldb_protocol::mcp::Server::m_transport_up
private

Definition at line 104 of file Server.h.

Referenced by OnClosed(), OnError(), Received(), and Run().

◆ m_version

const std::string lldb_protocol::mcp::Server::m_version
private

Definition at line 102 of file Server.h.

Referenced by InitializeHandler().


The documentation for this class was generated from the following files: