91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
|
# File 'lib/debug_mcp/tools/trigger_request.rb', line 91
def call(method:, url:, headers: {}, body: nil, cookies: nil, skip_csrf: nil,
timeout: nil, session_id: nil, event_limits: nil, include_debug_eval: false,
server_context:)
manager = server_context[:session_manager]
timeout_sec = timeout || DEFAULT_TIMEOUT
formatter_limits = resolve_event_limits(event_limits)
= ( || {}).dup
if body && !.any? { |k, _| k.to_s.downcase == "content-type" }
["Content-Type"] = detect_content_type(body)
end
if cookies && !cookies.empty?
cookie_str = cookies.map { |k, v| "#{k}=#{v}" }.join("; ")
existing = .find { |k, _| k.to_s.downcase == "cookie" }
if existing
[existing[0]] = "#{existing[1]}; #{cookie_str}"
else
["Cookie"] = cookie_str
end
end
request_id = SecureRandom.uuid
unless .any? { |k, _| k.to_s.downcase == "x-request-id" }
["X-Request-Id"] = request_id
end
csrf_disabled = false
client = nil
log_capture = nil
subscriber_ready = false
begin
client = manager.client(session_id)
begin
client.auto_repause!
rescue DebugMcp::Error
end
if client.paused
if method != "GET" && should_disable_csrf?(skip_csrf, client)
csrf_disabled = temporarily_disable_csrf(client)
end
subscriber_ready = NotificationsSubscriber.install(client)
log_capture = start_log_capture(client)
end
rescue DebugMcp::SessionError
client = nil
end
begin
response = if client&.connected?
handle_with_debug_session(client, method, url, , body, timeout_sec)
else
handle_without_session(method, url, , body, timeout_sec)
end
response = append_captured_logs(response, log_capture)
append_notifications_events(response, client, request_id, subscriber_ready,
limits: formatter_limits,
include_debug_eval: include_debug_eval)
ensure
if csrf_disabled && client&.connected? && client.paused
restore_csrf(client)
end
end
rescue StandardError => e
MCP::Tool::Response.new([{ type: "text", text: "Error: #{e.class}: #{e.message}" }])
end
|