[Lldb-commits] [lldb] [lldb] Add Model Context Protocol (MCP) support to LLDB (PR #143628)
Pavel Labath via lldb-commits
lldb-commits at lists.llvm.org
Mon Jun 16 06:40:22 PDT 2025
================
@@ -0,0 +1,72 @@
+//===- Tool.cpp -----------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "Tool.h"
+#include "lldb/Interpreter/CommandInterpreter.h"
+#include "lldb/Interpreter/CommandReturnObject.h"
+
+using namespace lldb_private::mcp;
+using namespace llvm;
+
+Tool::Tool(std::string name, std::string description)
+ : m_name(std::move(name)), m_description(std::move(description)) {}
+
+protocol::ToolDefinition Tool::GetDefinition() const {
+ protocol::ToolDefinition definition;
+ definition.name = m_name;
+ definition.description.emplace(m_description);
+
+ if (std::optional<llvm::json::Value> input_schema = GetSchema())
+ definition.inputSchema = *input_schema;
+
+ if (m_annotations)
+ definition.annotations = m_annotations;
+
+ return definition;
+}
+
+LLDBCommandTool::LLDBCommandTool(std::string name, std::string description,
+ Debugger &debugger)
+ : Tool(std::move(name), std::move(description)), m_debugger(debugger) {}
+
+protocol::TextResult LLDBCommandTool::Call(const llvm::json::Value &args) {
+ std::string arguments;
+ if (const json::Object *args_obj = args.getAsObject()) {
+ if (const json::Value *s = args_obj->get("arguments")) {
+ arguments = s->getAsString().value_or("");
+ }
+ }
+
+ CommandReturnObject result(/*colors=*/false);
+ m_debugger.GetCommandInterpreter().HandleCommand(arguments.c_str(),
----------------
labath wrote:
I know a team which tries to do that, but I'm not sure they realize how easily workaroundable that is (`command alias print_help quit; print_help`). Given what I've read about AI, I'm fairly certain it could come up with this sequence if it sets its mind to it.
To make this reliable, I think we'd at least need to resolve all aliases down to core commands.
https://github.com/llvm/llvm-project/pull/143628
More information about the lldb-commits
mailing list