Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
288 changes: 227 additions & 61 deletions lldb/include/lldb/Protocol/MCP/Protocol.h

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion lldb/include/lldb/Protocol/MCP/Resource.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class ResourceProvider {
virtual ~ResourceProvider() = default;

virtual std::vector<lldb_protocol::mcp::Resource> GetResources() const = 0;
virtual llvm::Expected<lldb_protocol::mcp::ResourceResult>
virtual llvm::Expected<lldb_protocol::mcp::ReadResourceResult>
ReadResource(llvm::StringRef uri) const = 0;
};

Expand Down
2 changes: 1 addition & 1 deletion lldb/include/lldb/Protocol/MCP/Server.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class Server : public MCPTransport::MessageHandler {
llvm::Error Run();

protected:
Capabilities GetCapabilities();
ServerCapabilities GetCapabilities();

using RequestHandler =
std::function<llvm::Expected<Response>(const Request &)>;
Expand Down
3 changes: 2 additions & 1 deletion lldb/include/lldb/Protocol/MCP/Tool.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#define LLDB_PROTOCOL_MCP_TOOL_H

#include "lldb/Protocol/MCP/Protocol.h"
#include "llvm/Support/Error.h"
#include "llvm/Support/JSON.h"
#include <string>

Expand All @@ -20,7 +21,7 @@ class Tool {
Tool(std::string name, std::string description);
virtual ~Tool() = default;

virtual llvm::Expected<lldb_protocol::mcp::TextResult>
virtual llvm::Expected<lldb_protocol::mcp::CallToolResult>
Call(const lldb_protocol::mcp::ToolArguments &args) = 0;

virtual std::optional<llvm::json::Value> GetSchema() const {
Expand Down
15 changes: 7 additions & 8 deletions lldb/source/Plugins/Protocol/MCP/Resource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
#include "lldb/Core/Debugger.h"
#include "lldb/Core/Module.h"
#include "lldb/Protocol/MCP/MCPError.h"
#include "lldb/Target/Platform.h"

using namespace lldb_private;
using namespace lldb_private::mcp;
Expand Down Expand Up @@ -124,7 +123,7 @@ DebuggerResourceProvider::GetResources() const {
return resources;
}

llvm::Expected<lldb_protocol::mcp::ResourceResult>
llvm::Expected<lldb_protocol::mcp::ReadResourceResult>
DebuggerResourceProvider::ReadResource(llvm::StringRef uri) const {

auto [protocol, path] = uri.split("://");
Expand Down Expand Up @@ -161,7 +160,7 @@ DebuggerResourceProvider::ReadResource(llvm::StringRef uri) const {
return ReadDebuggerResource(uri, debugger_idx);
}

llvm::Expected<lldb_protocol::mcp::ResourceResult>
llvm::Expected<lldb_protocol::mcp::ReadResourceResult>
DebuggerResourceProvider::ReadDebuggerResource(llvm::StringRef uri,
lldb::user_id_t debugger_id) {
lldb::DebuggerSP debugger_sp = Debugger::FindDebuggerWithID(debugger_id);
Expand All @@ -173,17 +172,17 @@ DebuggerResourceProvider::ReadDebuggerResource(llvm::StringRef uri,
debugger_resource.name = debugger_sp->GetInstanceName();
debugger_resource.num_targets = debugger_sp->GetTargetList().GetNumTargets();

lldb_protocol::mcp::ResourceContents contents;
lldb_protocol::mcp::TextResourceContents contents;
contents.uri = uri;
contents.mimeType = kMimeTypeJSON;
contents.text = llvm::formatv("{0}", toJSON(debugger_resource));

lldb_protocol::mcp::ResourceResult result;
lldb_protocol::mcp::ReadResourceResult result;
result.contents.push_back(contents);
return result;
}

llvm::Expected<lldb_protocol::mcp::ResourceResult>
llvm::Expected<lldb_protocol::mcp::ReadResourceResult>
DebuggerResourceProvider::ReadTargetResource(llvm::StringRef uri,
lldb::user_id_t debugger_id,
size_t target_idx) {
Expand All @@ -209,12 +208,12 @@ DebuggerResourceProvider::ReadTargetResource(llvm::StringRef uri,
if (lldb::PlatformSP platform_sp = target_sp->GetPlatform())
target_resource.platform = platform_sp->GetName();

lldb_protocol::mcp::ResourceContents contents;
lldb_protocol::mcp::TextResourceContents contents;
contents.uri = uri;
contents.mimeType = kMimeTypeJSON;
contents.text = llvm::formatv("{0}", toJSON(target_resource));

lldb_protocol::mcp::ResourceResult result;
lldb_protocol::mcp::ReadResourceResult result;
result.contents.push_back(contents);
return result;
}
15 changes: 9 additions & 6 deletions lldb/source/Plugins/Protocol/MCP/Resource.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@

#include "lldb/Protocol/MCP/Protocol.h"
#include "lldb/Protocol/MCP/Resource.h"
#include "lldb/lldb-private.h"
#include "lldb/lldb-forward.h"
#include "lldb/lldb-types.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/Support/Error.h"
#include <cstddef>
#include <vector>

namespace lldb_private::mcp {
Expand All @@ -21,19 +25,18 @@ class DebuggerResourceProvider : public lldb_protocol::mcp::ResourceProvider {
using ResourceProvider::ResourceProvider;
virtual ~DebuggerResourceProvider() = default;

virtual std::vector<lldb_protocol::mcp::Resource>
GetResources() const override;
virtual llvm::Expected<lldb_protocol::mcp::ResourceResult>
std::vector<lldb_protocol::mcp::Resource> GetResources() const override;
llvm::Expected<lldb_protocol::mcp::ReadResourceResult>
ReadResource(llvm::StringRef uri) const override;

private:
static lldb_protocol::mcp::Resource GetDebuggerResource(Debugger &debugger);
static lldb_protocol::mcp::Resource GetTargetResource(size_t target_idx,
Target &target);

static llvm::Expected<lldb_protocol::mcp::ResourceResult>
static llvm::Expected<lldb_protocol::mcp::ReadResourceResult>
ReadDebuggerResource(llvm::StringRef uri, lldb::user_id_t debugger_id);
static llvm::Expected<lldb_protocol::mcp::ResourceResult>
static llvm::Expected<lldb_protocol::mcp::ReadResourceResult>
ReadTargetResource(llvm::StringRef uri, lldb::user_id_t debugger_id,
size_t target_idx);
};
Expand Down
12 changes: 6 additions & 6 deletions lldb/source/Plugins/Protocol/MCP/Tool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
//===----------------------------------------------------------------------===//

#include "Tool.h"
#include "lldb/Core/Module.h"
#include "lldb/Interpreter/CommandInterpreter.h"
#include "lldb/Interpreter/CommandReturnObject.h"
#include "lldb/Protocol/MCP/Protocol.h"

using namespace lldb_private;
using namespace lldb_protocol;
Expand All @@ -29,10 +29,10 @@ bool fromJSON(const llvm::json::Value &V, CommandToolArguments &A,
O.mapOptional("arguments", A.arguments);
}

/// Helper function to create a TextResult from a string output.
static lldb_protocol::mcp::TextResult createTextResult(std::string output,
bool is_error = false) {
lldb_protocol::mcp::TextResult text_result;
/// Helper function to create a CallToolResult from a string output.
static lldb_protocol::mcp::CallToolResult
createTextResult(std::string output, bool is_error = false) {
lldb_protocol::mcp::CallToolResult text_result;
text_result.content.emplace_back(
lldb_protocol::mcp::TextContent{{std::move(output)}});
text_result.isError = is_error;
Expand All @@ -41,7 +41,7 @@ static lldb_protocol::mcp::TextResult createTextResult(std::string output,

} // namespace

llvm::Expected<lldb_protocol::mcp::TextResult>
llvm::Expected<lldb_protocol::mcp::CallToolResult>
CommandTool::Call(const lldb_protocol::mcp::ToolArguments &args) {
if (!std::holds_alternative<json::Value>(args))
return createStringError("CommandTool requires arguments");
Expand Down
8 changes: 4 additions & 4 deletions lldb/source/Plugins/Protocol/MCP/Tool.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
#ifndef LLDB_PLUGINS_PROTOCOL_MCP_TOOL_H
#define LLDB_PLUGINS_PROTOCOL_MCP_TOOL_H

#include "lldb/Core/Debugger.h"
#include "lldb/Protocol/MCP/Protocol.h"
#include "lldb/Protocol/MCP/Tool.h"
#include "llvm/Support/Error.h"
#include "llvm/Support/JSON.h"
#include <string>
#include <optional>

namespace lldb_private::mcp {

Expand All @@ -22,10 +22,10 @@ class CommandTool : public lldb_protocol::mcp::Tool {
using lldb_protocol::mcp::Tool::Tool;
~CommandTool() = default;

virtual llvm::Expected<lldb_protocol::mcp::TextResult>
llvm::Expected<lldb_protocol::mcp::CallToolResult>
Call(const lldb_protocol::mcp::ToolArguments &args) override;

virtual std::optional<llvm::json::Value> GetSchema() const override;
std::optional<llvm::json::Value> GetSchema() const override;
};

} // namespace lldb_private::mcp
Expand Down
Loading
Loading