Module: TalkToYourApp::Transport::RailsMount
- Defined in:
- lib/talk_to_your_app/transport/rails_mount.rb
Overview
Builds the Rack application the host app mounts. It assembles an MCP::Server from the enabled plugins’ tools, wraps it in the SDK’s Streamable HTTP transport, and fronts the whole thing with the auth middleware. ‘config.stateless` selects the transport’s stateless mode, which holds no per-session state — required when the host app runs more than one worker or replica.
Class Method Summary collapse
- .build ⇒ Object
-
.collect_tools ⇒ Object
Compiles every enabled plugin’s tools into MCP::Tool subclasses, each audit-wrapped with its plugin name and (optional) per-plugin log level.
Class Method Details
.build ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/talk_to_your_app/transport/rails_mount.rb', line 17 def build config = TalkToYourApp.configuration server = MCP::Server.new( name: config.server_name, title: config.server_title, version: config.server_version, description: config.server_description, instructions: config.instructions, tools: collect_tools, ) transport = MCP::Server::Transports::StreamableHTTPTransport.new( server, stateless: config.stateless, enable_json_response: true, ) Auth::Middleware.new(transport) end |
.collect_tools ⇒ Object
Compiles every enabled plugin’s tools into MCP::Tool subclasses, each audit-wrapped with its plugin name and (optional) per-plugin log level.
37 38 39 40 41 42 43 44 45 |
# File 'lib/talk_to_your_app/transport/rails_mount.rb', line 37 def collect_tools TalkToYourApp.enabled_plugins.flat_map do |name, plugin_class, _opts| next [] unless plugin_class plugin_class.tools.map do |tool_class| tool_class.to_mcp_tool(plugin_name: name, log_level: plugin_class.log_level) end end end |