@@ -27,6 +27,16 @@ bool fromJSON(const llvm::json::Value &V, CommandToolArguments &A,
2727 O.mapOptional (" arguments" , A.arguments );
2828}
2929
30+ // / Helper function to create a TextResult from a string output.
31+ static lldb_private::mcp::protocol::TextResult
32+ createTextResult (std::string output, bool is_error = false ) {
33+ lldb_private::mcp::protocol::TextResult text_result;
34+ text_result.content .emplace_back (
35+ lldb_private::mcp::protocol::TextContent{{std::move (output)}});
36+ text_result.isError = is_error;
37+ return text_result;
38+ }
39+
3040} // namespace
3141
3242Tool::Tool (std::string name, std::string description)
@@ -77,10 +87,7 @@ CommandTool::Call(const protocol::ToolArguments &args) {
7787 output += err_str;
7888 }
7989
80- mcp::protocol::TextResult text_result;
81- text_result.content .emplace_back (mcp::protocol::TextContent{{output}});
82- text_result.isError = !result.Succeeded ();
83- return text_result;
90+ return createTextResult (output, !result.Succeeded ());
8491}
8592
8693std::optional<llvm::json::Value> CommandTool::GetSchema () const {
@@ -126,7 +133,7 @@ DebuggerListTool::Call(const protocol::ToolArguments &args) {
126133 const TargetList &target_list = debugger_sp->GetTargetList ();
127134 const size_t num_targets = target_list.GetNumTargets ();
128135 for (size_t j = 0 ; j < num_targets; ++j) {
129- lldb::TargetSP target_sp = target_list.GetTargetAtIndex (i );
136+ lldb::TargetSP target_sp = target_list.GetTargetAtIndex (j );
130137 if (!target_sp)
131138 continue ;
132139 os << " - target " << j;
@@ -137,7 +144,5 @@ DebuggerListTool::Call(const protocol::ToolArguments &args) {
137144 }
138145 }
139146
140- mcp::protocol::TextResult text_result;
141- text_result.content .emplace_back (mcp::protocol::TextContent{{output}});
142- return text_result;
147+ return createTextResult (output);
143148}
0 commit comments