33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
# File 'lib/debug_mcp/tools/finish.rb', line 33
def call(session_id: nil, server_context:)
client = server_context[:session_manager].client(session_id)
output = client.send_command("finish", timeout: DebugClient::CONTINUE_TIMEOUT)
if output.strip.empty? && client.process_finished?
text = DebugMcp::ExitMessageBuilder.build_exit_message(
"Program exited during finish.", output, client,
)
return MCP::Tool::Response.new([{ type: "text", text: text }])
end
client.cleanup_one_shot_breakpoints(output)
output = DebugMcp::StopEventAnnotator.annotate_breakpoint_hit(output)
output = DebugMcp::StopEventAnnotator.enrich_stop_context(output, client)
location = parse_stop_location(output)
= if location
"Method/block returned. Now at: #{location}"
else
"Method/block returned (stopped at caller's frame)."
end
MCP::Tool::Response.new([{ type: "text", text: "#{}\n\n#{output}" }])
rescue DebugMcp::SessionError => e
text = if e.message.include?("session ended") || e.message.include?("finished execution")
DebugMcp::ExitMessageBuilder.build_exit_message("Program exited during finish.", e.final_output, client)
else
"Error: #{e.message}"
end
MCP::Tool::Response.new([{ type: "text", text: text }])
rescue DebugMcp::ConnectionError => e
text = if e.message.include?("Connection lost") || e.message.include?("connection closed")
DebugMcp::ExitMessageBuilder.build_exit_message("Program exited during finish.", e.final_output, client)
else
"Error: #{e.message}"
end
MCP::Tool::Response.new([{ type: "text", text: text }])
rescue DebugMcp::Error => e
MCP::Tool::Response.new([{ type: "text", text: "Error: #{e.message}" }])
end
|