9#ifndef LLDB_PROTOCOL_MCP_SERVER_H
10#define LLDB_PROTOCOL_MCP_SERVER_H
18#include "llvm/ADT/SmallString.h"
19#include "llvm/ADT/StringMap.h"
20#include "llvm/ADT/StringRef.h"
21#include "llvm/Support/Error.h"
22#include "llvm/Support/JSON.h"
23#include "llvm/Support/Signals.h"
31class Server :
public MCPTransport::MessageHandler {
41 void AddTool(std::unique_ptr<Tool> tool);
50 std::function<llvm::Expected<Response>(
const Request &)>;
56 llvm::Expected<std::optional<Message>>
HandleData(llvm::StringRef data);
72 void OnError(llvm::Error)
override;
76 void Log(llvm::StringRef);
86 llvm::StringMap<std::unique_ptr<Tool>>
m_tools;
103 static llvm::Expected<std::vector<ServerInfo>>
Load();
A handle that tracks the server info on disk and cleans up the disk record once it is no longer refer...
llvm::SmallString< 128 > m_filename
void Remove()
Remove the file.
ServerInfoHandle(const ServerInfoHandle &)=delete
ServerIinfoHandle is not copyable.
ServerInfoHandle & operator=(ServerInfoHandle &&other) noexcept
ServerInfoHandle(llvm::StringRef filename="")
ServerInfoHandle & operator=(const ServerInfoHandle &)=delete
std::function< void(const Notification &)> NotificationHandler
llvm::Expected< Response > ToolsCallHandler(const Request &)
const std::string m_version
llvm::unique_function< void()> ClosedCallback
void AddTool(std::unique_ptr< Tool > tool)
void AddResourceProvider(std::unique_ptr< ResourceProvider > resource_provider)
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()
LogCallback m_log_callback
Server(std::string name, std::string version, MCPTransport &client, LogCallback log_callback={}, ClosedCallback closed_callback={})
llvm::StringMap< RequestHandler > m_request_handlers
ClosedCallback m_closed_callback
void OnError(llvm::Error) override
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 Log(llvm::StringRef)
void AddRequestHandler(llvm::StringRef method, RequestHandler handler)
std::function< llvm::Expected< Response >(const Request &)> RequestHandler
void Received(const Request &) override
ServerCapabilities GetCapabilities()
void AddNotificationHandler(llvm::StringRef method, NotificationHandler handler)
llvm::Expected< Response > InitializeHandler(const Request &)
llvm::json::Value toJSON(const Request &)
lldb_private::Transport< Request, Response, Notification > MCPTransport
Generic transport that uses the MCP protocol.
llvm::unique_function< void(llvm::StringRef message)> LogCallback
Generic logging callback, to allow the MCP server / client / transport layer to be independent of the...
bool fromJSON(const llvm::json::Value &, Request &, llvm::json::Path)
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 ...
static llvm::Expected< std::vector< ServerInfo > > Load()
Loads any server info saved in ~/.lldb.
std::string connection_uri
static llvm::Expected< ServerInfoHandle > Write(const ServerInfo &)
Writes the server info into a unique file in ~/.lldb.