Class: DebugMcp::Tools::Step

Inherits:
MCP::Tool
  • Object
show all
Defined in:
lib/debug_mcp/tools/step.rb

Class Method Summary collapse

Class Method Details

.call(session_id: nil, server_context:) ⇒ Object



30
31
32
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
# File 'lib/debug_mcp/tools/step.rb', line 30

def call(session_id: nil, server_context:)
  client = server_context[:session_manager].client(session_id)

  output = client.send_command("step")

  if output.strip.empty? && client.process_finished?
    text = DebugMcp::ExitMessageBuilder.build_exit_message(
      "Program exited during step.", 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)

  MCP::Tool::Response.new([{ type: "text", text: 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 step.", 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 step.", 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