[Lldb-commits] [lldb] [lldb] Add Model Context Protocol (MCP) support to LLDB (PR #143628)
John Harrison via lldb-commits
lldb-commits at lists.llvm.org
Fri Jun 13 15:40:21 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(),
----------------
ashgti wrote:
Should we prevent some commands from being executed here?
For example, `quit`?
https://github.com/llvm/llvm-project/pull/143628
More information about the lldb-commits
mailing list