9#ifndef LLDB_PROTOCOL_MCP_TRANSPORT_H
10#define LLDB_PROTOCOL_MCP_TRANSPORT_H
16#include "llvm/ADT/FunctionExtras.h"
17#include "llvm/ADT/StringRef.h"
18#include "llvm/Support/Error.h"
31 std::optional<llvm::json::Value> params) {
35 std::optional<llvm::json::Value> params) {
40 llvm::handleAllErrors(
41 std::move(
error), [&](
const llvm::ErrorInfoBase &err) {
42 std::error_code cerr = err.convertToErrorCode();
44 cerr == llvm::inconvertibleErrorCode()
47 protocol_error.
message = err.message();
50 return Response{req.
id, std::move(protocol_error)};
53 std::optional<llvm::json::Value> result) {
64 std::get_if<lldb_protocol::mcp::Error>(&r.
result))
65 return llvm::make_error<lldb_protocol::mcp::MCPError>(
error->message,
67 return std::get<llvm::json::Value>(r.
result);
81using LogCallback = llvm::unique_function<void(llvm::StringRef message)>;
96 void Log(llvm::StringRef message)
override;
static llvm::raw_ostream & error(Stream &strm)
Binder collects a table of functions that handle calls.
A transport class for JSON RPC.
A transport is responsible for maintaining the connection to a client application,...
void Log(llvm::StringRef message) override
Transport(lldb::IOObjectSP in, lldb::IOObjectSP out, LogCallback log_callback={})
LogCallback m_log_callback
virtual ~Transport()=default
void operator=(const Transport &)=delete
Transport(const Transport &)=delete
Transport is not copyable.
std::unique_ptr< MCPBinder > MCPBinderUP
lldb_private::transport::Binder< ProtocolDescriptor > MCPBinder
@ eErrorCodeInternalError
Internal JSON-RPC error.
lldb_private::transport::JSONTransport< ProtocolDescriptor > 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...
std::shared_ptr< lldb_private::IOObject > IOObjectSP
std::string message
A short description of the error.
int64_t code
The error type that occurred.
A notification which does not expect a response.
std::optional< llvm::json::Value > params
The notification's params.
std::string method
The method to be invoked.
static llvm::Expected< llvm::json::Value > Extract(Response r)
static std::optional< llvm::json::Value > Extract(Request r)
static Response Make(Req req, llvm::Error error)
static Id KeyFor(Response r)
static std::string KeyFor(Notification n)
static Notification Make(llvm::StringRef method, std::optional< llvm::json::Value > params)
static std::optional< llvm::json::Value > Extract(Notification n)
static Response Make(Req req, std::optional< llvm::json::Value > result)
static Request Make(Id id, llvm::StringRef method, std::optional< llvm::json::Value > params)
static std::string KeyFor(Request r)
A request that expects a response.
std::optional< llvm::json::Value > params
The method's params.
std::string method
The method to be invoked.
A response to a request, either an error or a result.
std::variant< Error, llvm::json::Value > result
The result of the request, either an Error or the JSON value of the response.