1414using namespace lldb_private ::mcp;
1515using namespace llvm ;
1616
17+ namespace {
1718struct CommandToolArguments {
1819 uint64_t debugger_id;
1920 std::string arguments;
@@ -26,6 +27,8 @@ bool fromJSON(const llvm::json::Value &V, CommandToolArguments &A,
2627 O.mapOptional (" arguments" , A.arguments );
2728}
2829
30+ } // namespace
31+
2932Tool::Tool (std::string name, std::string description)
3033 : m_name(std::move(name)), m_description(std::move(description)) {}
3134
@@ -41,14 +44,14 @@ protocol::ToolDefinition Tool::GetDefinition() const {
4144}
4245
4346llvm::Expected<protocol::TextResult>
44- CommandTool::Call (const llvm::json::Value * args) {
45- if (!args)
46- return createStringError (" no tool arguments" );
47+ CommandTool::Call (const protocol::ToolArguments & args) {
48+ if (!std::holds_alternative<json::Value>( args) )
49+ return createStringError (" CommandTool requires arguments" );
4750
48- llvm:: json::Path::Root root;
51+ json::Path::Root root;
4952
5053 CommandToolArguments arguments;
51- if (!fromJSON (* args, arguments, root))
54+ if (!fromJSON (std::get<json::Value>( args) , arguments, root))
5255 return root.getError ();
5356
5457 lldb::DebuggerSP debugger_sp =
@@ -93,9 +96,22 @@ std::optional<llvm::json::Value> CommandTool::GetSchema() const {
9396}
9497
9598llvm::Expected<protocol::TextResult>
96- DebuggerListTool::Call (const llvm::json::Value *args) {
99+ DebuggerListTool::Call (const protocol::ToolArguments &args) {
100+ if (!std::holds_alternative<std::monostate>(args))
101+ return createStringError (" DebuggerListTool takes no arguments" );
102+
97103 llvm::json::Path::Root root;
98104
105+ // Return a nested Markdown list with debuggers and target.
106+ // Example output:
107+ //
108+ // - debugger 0
109+ // - target 0 /path/to/foo
110+ // - target 1
111+ // - debugger 1
112+ // - target 0 /path/to/bar
113+ //
114+ // FIXME: Use Structured Content when we adopt protocol version 2025-06-18.
99115 std::string output;
100116 llvm::raw_string_ostream os (output);
101117
@@ -114,8 +130,10 @@ DebuggerListTool::Call(const llvm::json::Value *args) {
114130 if (!target_sp)
115131 continue ;
116132 os << " - target " << j;
133+ // Append the module path if we have one.
117134 if (Module *exe_module = target_sp->GetExecutableModulePointer ())
118135 os << " " << exe_module->GetFileSpec ().GetPath ();
136+ os << ' \n ' ;
119137 }
120138 }
121139
0 commit comments