Class: RailsAiBridge::Server
- Inherits:
-
Object
- Object
- RailsAiBridge::Server
- Defined in:
- lib/rails_ai_bridge/server.rb
Overview
Configures and starts an MCP server using the official Ruby SDK. Registers all introspection tools and handles transport selection. Supports both stdio and HTTP transports with proper error handling.
Constant Summary collapse
- STDIO_TRANSPORT =
Transport type constants for type safety and consistency
:stdio- HTTP_TRANSPORT =
:http- STREAMABLE_HTTP_TRANSPORT =
:streamable_http- STDIO_STARTUP_MESSAGE =
Log message templates for consistent logging
'[rails-ai-bridge] MCP server started (stdio transport)'- HTTP_STARTUP_MESSAGE =
'[rails-ai-bridge] MCP server starting on %s:%s%s'- TOOLS_LIST_MESSAGE =
'[rails-ai-bridge] Tools: %s'- UNKNOWN_TRANSPORT_ERROR =
Error message template for unknown transport types
'Unknown transport: %s. Use :stdio, :http, or :streamable_http'- TOOLS =
Built-in MCP tools that are always available These tools provide Rails application introspection capabilities
[ Tools::GetSchema, Tools::GetRoutes, Tools::GetModelDetails, Tools::GetGems, Tools::SearchCode, Tools::GetConventions, Tools::GetControllers, Tools::GetConfig, Tools::GetTestInfo, Tools::GetView, Tools::GetStimulus ].freeze
Instance Attribute Summary collapse
-
#app ⇒ Object
readonly
Returns the value of attribute app.
-
#transport_type ⇒ Object
readonly
Returns the value of attribute transport_type.
Instance Method Summary collapse
-
#build ⇒ MCP::Server
Build and return the configured MCP::Server instance.
-
#initialize(app, transport: STDIO_TRANSPORT) ⇒ Server
constructor
Initialize a new MCP server instance.
-
#start ⇒ void
Start the MCP server with the configured transport.
-
#tool_classes ⇒ Array<Class>
Returns all available tool classes including additional configured tools.
Constructor Details
#initialize(app, transport: STDIO_TRANSPORT) ⇒ Server
Initialize a new MCP server instance.
44 45 46 47 |
# File 'lib/rails_ai_bridge/server.rb', line 44 def initialize(app, transport: STDIO_TRANSPORT) @app = app @transport_type = transport end |
Instance Attribute Details
#app ⇒ Object (readonly)
Returns the value of attribute app.
10 11 12 |
# File 'lib/rails_ai_bridge/server.rb', line 10 def app @app end |
#transport_type ⇒ Object (readonly)
Returns the value of attribute transport_type.
10 11 12 |
# File 'lib/rails_ai_bridge/server.rb', line 10 def transport_type @transport_type end |
Instance Method Details
#build ⇒ MCP::Server
Build and return the configured MCP::Server instance.
57 58 59 60 61 62 63 |
# File 'lib/rails_ai_bridge/server.rb', line 57 def build config = RailsAiBridge.configuration server = create_mcp_server(config) register_resources(server) server end |
#start ⇒ void
This method returns an undefined value.
Start the MCP server with the configured transport.
67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/rails_ai_bridge/server.rb', line 67 def start server = build case transport_type when STDIO_TRANSPORT start_stdio(server) when HTTP_TRANSPORT, STREAMABLE_HTTP_TRANSPORT start_http(server) else raise ConfigurationError, UNKNOWN_TRANSPORT_ERROR % transport_type end end |
#tool_classes ⇒ Array<Class>
Returns all available tool classes including additional configured tools.
51 52 53 |
# File 'lib/rails_ai_bridge/server.rb', line 51 def tool_classes TOOLS + RailsAiBridge.configuration.additional_tools end |