LLDB mainline
lldb_protocol::mcp::Client Class Reference

An MCP client: the counterpart to Server. More...

#include <Client.h>

Public Types

template<typename T>
using Reply = lldb_private::transport::Reply<T>

Public Member Functions

 Client (std::unique_ptr< MCPTransport > transport, LogCallback log_callback={})
 ~Client ()=default
 Client (const Client &)=delete
Clientoperator= (const Client &)=delete
llvm::Error Run ()
 Registers the client with the transport's MainLoop.
void SetDisconnectHandler (llvm::unique_function< void()> handler)
 Sets a handler invoked when the transport disconnects (EOF).
void SetErrorHandler (llvm::unique_function< void(llvm::Error)> handler)
 Sets a handler invoked on a transport-level error.
void NotifyInitialized ()
 MCP notifications.
void CancelPendingRequests (llvm::StringRef reason)
 Fails every request still awaiting a response, invoking its reply with an error.
void Initialize (const InitializeParams &params, Reply< InitializeResult > reply)
 Outgoing MCP requests to the server.
void ToolsList (Reply< ListToolsResult > reply)
void ToolsCall (const CallToolParams &params, Reply< CallToolResult > reply)
void ResourcesList (Reply< ListResourcesResult > reply)
void ResourcesRead (const ReadResourceParams &params, Reply< ReadResourceResult > reply)

Private Member Functions

void Log (llvm::StringRef message)
void HandleDisconnect ()
 Trampolines registered with the binder, which forward to the move-only handlers below.
void HandleError (llvm::Error error)

Private Attributes

std::unique_ptr< MCPTransportm_transport
MCPBinderUP m_binder
LogCallback m_log_callback
llvm::unique_function< void()> m_disconnect_handler
llvm::unique_function< void(llvm::Error)> m_error_handler
lldb_private::transport::OutgoingRequest< InitializeResult, InitializeParamsm_initialize
lldb_private::transport::OutgoingRequest< ListToolsResult, void > m_tools_list
lldb_private::transport::OutgoingRequest< CallToolResult, CallToolParamsm_tools_call
lldb_private::transport::OutgoingRequest< ListResourcesResult, void > m_resources_list
lldb_private::transport::OutgoingRequest< ReadResourceResult, ReadResourceParamsm_resources_read
lldb_private::transport::OutgoingEvent< void > m_notify_initialized

Detailed Description

An MCP client: the counterpart to Server.

It speaks the MCP protocol to a remote server over a transport and exposes the protocol's requests as typed, asynchronous calls. Each request completes by invoking its Reply on the transport's MainLoop.

Definition at line 25 of file Client.h.

Member Typedef Documentation

◆ Reply

Definition at line 27 of file Client.h.

Constructor & Destructor Documentation

◆ Client() [1/2]

Client::Client ( std::unique_ptr< MCPTransport > transport,
LogCallback log_callback = {} )

◆ ~Client()

lldb_protocol::mcp::Client::~Client ( )
default

◆ Client() [2/2]

lldb_protocol::mcp::Client::Client ( const Client & )
delete

References Client().

Member Function Documentation

◆ CancelPendingRequests()

void Client::CancelPendingRequests ( llvm::StringRef reason)

Fails every request still awaiting a response, invoking its reply with an error.

Use before teardown so abandoned replies are satisfied rather than destroyed unanswered.

Definition at line 84 of file Client.cpp.

References m_binder.

◆ HandleDisconnect()

void Client::HandleDisconnect ( )
private

Trampolines registered with the binder, which forward to the move-only handlers below.

The binder requires copyable callables, so the handlers cannot be registered with it directly.

Definition at line 47 of file Client.cpp.

References m_disconnect_handler.

Referenced by Run().

◆ HandleError()

void Client::HandleError ( llvm::Error error)
private

Definition at line 52 of file Client.cpp.

References error(), and m_error_handler.

Referenced by Run().

◆ Initialize()

void Client::Initialize ( const InitializeParams & params,
Reply< InitializeResult > reply )

Outgoing MCP requests to the server.

Each sends its request and invokes its Reply asynchronously when the response arrives.

Definition at line 59 of file Client.cpp.

References m_initialize.

◆ Log()

void Client::Log ( llvm::StringRef message)
private

Definition at line 88 of file Client.cpp.

References m_log_callback.

◆ NotifyInitialized()

void Client::NotifyInitialized ( )

MCP notifications.

Definition at line 82 of file Client.cpp.

References m_notify_initialized.

◆ operator=()

Client & lldb_protocol::mcp::Client::operator= ( const Client & )
delete

References Client(), and error().

◆ ResourcesList()

void Client::ResourcesList ( Reply< ListResourcesResult > reply)

Definition at line 73 of file Client.cpp.

References m_resources_list.

◆ ResourcesRead()

void Client::ResourcesRead ( const ReadResourceParams & params,
Reply< ReadResourceResult > reply )

Definition at line 77 of file Client.cpp.

References m_resources_read.

◆ Run()

llvm::Error Client::Run ( )

Registers the client with the transport's MainLoop.

Must be called before issuing any request.

Definition at line 33 of file Client.cpp.

References HandleDisconnect(), HandleError(), m_binder, and m_transport.

◆ SetDisconnectHandler()

void Client::SetDisconnectHandler ( llvm::unique_function< void()> handler)

Sets a handler invoked when the transport disconnects (EOF).

Definition at line 39 of file Client.cpp.

References m_disconnect_handler.

◆ SetErrorHandler()

void Client::SetErrorHandler ( llvm::unique_function< void(llvm::Error)> handler)

Sets a handler invoked on a transport-level error.

Definition at line 43 of file Client.cpp.

References m_error_handler.

◆ ToolsCall()

void Client::ToolsCall ( const CallToolParams & params,
Reply< CallToolResult > reply )

Definition at line 68 of file Client.cpp.

References m_tools_call.

◆ ToolsList()

void Client::ToolsList ( Reply< ListToolsResult > reply)

Definition at line 64 of file Client.cpp.

References m_tools_list.

Member Data Documentation

◆ m_binder

MCPBinderUP lldb_protocol::mcp::Client::m_binder
private

Definition at line 77 of file Client.h.

Referenced by CancelPendingRequests(), Client(), and Run().

◆ m_disconnect_handler

llvm::unique_function<void()> lldb_protocol::mcp::Client::m_disconnect_handler
private

Definition at line 80 of file Client.h.

Referenced by HandleDisconnect(), and SetDisconnectHandler().

◆ m_error_handler

llvm::unique_function<void(llvm::Error)> lldb_protocol::mcp::Client::m_error_handler
private

Definition at line 81 of file Client.h.

Referenced by HandleError(), and SetErrorHandler().

◆ m_initialize

lldb_private::transport::OutgoingRequest<InitializeResult, InitializeParams> lldb_protocol::mcp::Client::m_initialize
private

Definition at line 84 of file Client.h.

Referenced by Client(), and Initialize().

◆ m_log_callback

LogCallback lldb_protocol::mcp::Client::m_log_callback
private

Definition at line 78 of file Client.h.

Referenced by Client(), and Log().

◆ m_notify_initialized

lldb_private::transport::OutgoingEvent<void> lldb_protocol::mcp::Client::m_notify_initialized
private

Definition at line 93 of file Client.h.

Referenced by Client(), and NotifyInitialized().

◆ m_resources_list

lldb_private::transport::OutgoingRequest<ListResourcesResult, void> lldb_protocol::mcp::Client::m_resources_list
private

Definition at line 89 of file Client.h.

Referenced by Client(), and ResourcesList().

◆ m_resources_read

lldb_private::transport::OutgoingRequest<ReadResourceResult, ReadResourceParams> lldb_protocol::mcp::Client::m_resources_read
private

Definition at line 92 of file Client.h.

Referenced by Client(), and ResourcesRead().

◆ m_tools_call

lldb_private::transport::OutgoingRequest<CallToolResult, CallToolParams> lldb_protocol::mcp::Client::m_tools_call
private

Definition at line 87 of file Client.h.

Referenced by Client(), and ToolsCall().

◆ m_tools_list

lldb_private::transport::OutgoingRequest<ListToolsResult, void> lldb_protocol::mcp::Client::m_tools_list
private

Definition at line 85 of file Client.h.

Referenced by Client(), and ToolsList().

◆ m_transport

std::unique_ptr<MCPTransport> lldb_protocol::mcp::Client::m_transport
private

Definition at line 76 of file Client.h.

Referenced by Client(), and Run().


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