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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
|
# File 'lib/debug_mcp/tools/rails_model.rb', line 36
def call(model_name: nil, session_id: nil, server_context:)
client = server_context[:session_manager].client(session_id)
client.auto_repause!
RailsHelper.require_rails!(client)
return list_models(client) unless model_name
verify_result = verify_ar_model(client, model_name)
return verify_result if verify_result.is_a?(MCP::Tool::Response)
parts = []
table_name = eval_expr(client, "#{model_name}.table_name")
parts << "=== #{model_name} (table: #{table_name || "unknown"}) ==="
parts << build_columns_section(client, model_name)
section = build_associations_section(client, model_name)
parts << section if section
section = build_validations_section(client, model_name)
parts << section if section
section = build_enums_section(client, model_name)
parts << section if section
section = build_scopes_section(client, model_name)
parts << section if section
section = build_callbacks_section(client, model_name)
parts << section if section
text = parts.compact.join("\n\n")
if text.include?("unable to retrieve") || text.include?("Error:")
text += "\n\n#{RailsHelper::TRAP_CONTEXT_HINT}" if RailsHelper.trap_context?(client)
end
MCP::Tool::Response.new([{ type: "text", text: text }])
rescue DebugMcp::Error => e
text = "Error: #{e.message}"
text += "\n\n#{RailsHelper::TRAP_CONTEXT_HINT}" if begin
RailsHelper.trap_context?(client)
rescue StandardError
false
end
MCP::Tool::Response.new([{ type: "text", text: text }])
end
|