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
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
|
# File 'lib/debug_mcp/tools/trigger_request.rb', line 73
def call(method:, url:, headers: {}, body: nil, cookies: nil, skip_csrf: nil,
timeout: nil, session_id: nil, server_context:)
manager = server_context[:session_manager]
timeout_sec = timeout || DEFAULT_TIMEOUT
= ( || {}).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
csrf_disabled = false
client = nil
log_capture = nil
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
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
append_captured_logs(response, log_capture)
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
|