26
27
28
29
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
|
# File 'app/controllers/solid_loop/mcp_sessions_controller.rb', line 26
def run_tool
tool_name = params[:tool_name]
arguments = params[:arguments]&.to_unsafe_h || {}
@tools = @mcp_session.mcp_tools.order(:name)
@tool = @mcp_session.mcp_tools.find_by!(name: tool_name)
@selected_tool = @tool
agent = @mcp_session.loop&.agent
start_time = Time.current
result_hash = @tool.call(agent: agent, arguments: arguments)
duration = Time.current - start_time
@result = result_hash[:result]
@is_error = !result_hash[:success]
@duration = result_hash[:duration] || duration
@log = result_hash[:log]
respond_to do |format|
format.turbo_stream do
content = render_to_string(
partial: "solid_loop/mcp_sessions/tool_output",
formats: [ :html ],
locals: { result: @result, is_error: @is_error, duration: @duration, log: @log }
)
render html: <<~HTML.html_safe, content_type: "text/vnd.turbo-stream.html"
<turbo-stream action="update" target="sl-inspector-output">
<template>#{content}</template>
</turbo-stream>
HTML
end
format.html { render :inspector }
end
end
|