9#ifndef LLDB_PROTOCOL_MCP_SERVER_H
10#define LLDB_PROTOCOL_MCP_SERVER_H
17#include "llvm/ADT/StringMap.h"
18#include "llvm/Support/Error.h"
26 using LogCallback = std::function<void(llvm::StringRef message)>;
29 std::string client_name,
LogCallback log_callback = {})
30 : JSONRPCTransport(in, out),
m_client_name(std::move(client_name)),
34 void Log(llvm::StringRef message)
override {
55 Server(std::string name, std::string version,
56 std::unique_ptr<MCPTransport> transport_up,
62 void AddTool(std::unique_ptr<Tool> tool);
73 std::function<llvm::Expected<Response>(
const Request &)>;
79 llvm::Expected<std::optional<Message>>
HandleData(llvm::StringRef data);
95 void OnError(llvm::Error)
override;
107 llvm::StringMap<std::unique_ptr<Tool>>
m_tools;
A transport class for JSON RPC.
Implemented to handle incoming messages. (See Run() below).
virtual ~MCPTransport()=default
void Log(llvm::StringRef message) override
std::string m_client_name
MCPTransport(lldb::IOObjectSP in, lldb::IOObjectSP out, std::string client_name, LogCallback log_callback={})
std::function< void(llvm::StringRef message)> LogCallback
LogCallback m_log_callback
std::function< void(const Notification &)> NotificationHandler
llvm::Expected< Response > ToolsCallHandler(const Request &)
const std::string m_version
void AddTool(std::unique_ptr< Tool > tool)
void AddResourceProvider(std::unique_ptr< ResourceProvider > resource_provider)
lldb_private::MainLoop & m_loop
llvm::StringMap< std::unique_ptr< Tool > > m_tools
llvm::Expected< std::optional< Message > > HandleData(llvm::StringRef data)
std::vector< std::unique_ptr< ResourceProvider > > m_resource_providers
llvm::StringMap< NotificationHandler > m_notification_handlers
void AddRequestHandlers()
llvm::StringMap< RequestHandler > m_request_handlers
void OnError(llvm::Error) override
Called when an error occurs while reading from the transport.
llvm::Expected< Response > ResourcesListHandler(const Request &)
llvm::Expected< Response > ResourcesReadHandler(const Request &)
llvm::Expected< Response > Handle(const Request &request)
llvm::Expected< Response > ToolsListHandler(const Request &)
void AddRequestHandler(llvm::StringRef method, RequestHandler handler)
std::unique_ptr< MCPTransport > m_transport_up
std::function< llvm::Expected< Response >(const Request &)> RequestHandler
void Received(const Request &) override
void OnClosed() override
Called on EOF or client disconnect.
ServerCapabilities GetCapabilities()
void AddNotificationHandler(llvm::StringRef method, NotificationHandler handler)
llvm::Expected< Response > InitializeHandler(const Request &)
llvm::json::Value toJSON(const Request &)
bool fromJSON(const llvm::json::Value &, Request &, llvm::json::Path)
std::shared_ptr< lldb_private::IOObject > IOObjectSP
A notification which does not expect a response.
A request that expects a response.
A response to a request, either an error or a result.
Capabilities that a server may support.
Information about this instance of lldb's MCP server for lldb-mcp to use to coordinate connecting an ...
std::string connection_uri