9#ifndef LLDB_PROTOCOL_MCP_SERVER_H
10#define LLDB_PROTOCOL_MCP_SERVER_H
17#include "llvm/ADT/SmallString.h"
18#include "llvm/ADT/StringMap.h"
19#include "llvm/ADT/StringRef.h"
20#include "llvm/Support/Error.h"
21#include "llvm/Support/FormatVariadic.h"
22#include "llvm/Support/JSON.h"
23#include "llvm/Support/Signals.h"
40 void AddTool(std::unique_ptr<Tool> tool);
56 llvm::Expected<ReadResourceResult>
59 template <
typename... Ts>
inline auto Logv(
const char *Fmt, Ts &&...Vals) {
60 Log(llvm::formatv(Fmt, std::forward<Ts>(Vals)...).str());
62 void Log(llvm::StringRef message) {
79 llvm::StringMap<std::unique_ptr<Tool>>
m_tools;
93 static llvm::Expected<std::vector<ServerInfo>>
Load();
std::unique_ptr< ReadHandle > ReadHandleUP
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 on disk, if one is tracked.
ServerInfoHandle(const ServerInfoHandle &)=delete
ServerIinfoHandle is not copyable.
ServerInfoHandle & operator=(ServerInfoHandle &&other) noexcept
ServerInfoHandle(llvm::StringRef filename="")
ServerInfoHandle & operator=(const ServerInfoHandle &)=delete
const std::string m_version
void AddTool(std::unique_ptr< Tool > tool)
void AddResourceProvider(std::unique_ptr< ResourceProvider > resource_provider)
llvm::StringMap< std::unique_ptr< Tool > > m_tools
MCPBinderUP Bind(MCPTransport &)
std::vector< std::unique_ptr< ResourceProvider > > m_resource_providers
llvm::Expected< ReadResourceResult > ResourcesReadHandler(const ReadResourceParams &)
LogCallback m_log_callback
Server(std::string name, std::string version, LogCallback log_callback={})
llvm::Expected< ListToolsResult > ToolsListHandler()
void Log(llvm::StringRef message)
llvm::Expected< InitializeResult > InitializeHandler(const InitializeParams &)
llvm::Expected< CallToolResult > ToolsCallHandler(const CallToolParams &)
llvm::Error Accept(lldb_private::MainLoop &, MCPTransportUP)
std::unique_ptr< lldb_protocol::mcp::MCPTransport > MCPTransportUP
lldb_private::MainLoop::ReadHandleUP ReadHandleUP
llvm::Expected< ListResourcesResult > ResourcesListHandler()
auto Logv(const char *Fmt, Ts &&...Vals)
std::map< MCPTransport *, Client > m_instances
ServerCapabilities GetCapabilities()
std::unique_ptr< MCPBinder > MCPBinderUP
lldb_private::transport::JSONTransport< ProtocolDescriptor > MCPTransport
Generic transport that uses the MCP protocol.
llvm::json::Value toJSON(const Request &)
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)
Sent from the client to the server, to read a specific resource URI.
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.