Class: RailsActiveMcp::Sdk::Server
- Inherits:
-
Object
- Object
- RailsActiveMcp::Sdk::Server
- Defined in:
- lib/rails_active_mcp/sdk/server.rb
Instance Attribute Summary collapse
-
#mcp_server ⇒ Object
readonly
Returns the value of attribute mcp_server.
Instance Method Summary collapse
-
#initialize ⇒ Server
constructor
A new instance of Server.
- #run_http(port: 3001) ⇒ Object
- #run_stdio ⇒ Object
Constructor Details
#initialize ⇒ Server
Returns a new instance of Server.
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/rails_active_mcp/sdk/server.rb', line 18 def initialize # Store original streams for restoration @original_stdout = $stdout @original_stderr = $stderr # Set up output redirection BEFORE any Rails interaction setup_output_redirection # Configure MCP first configure_mcp # Create the MCP server with our tools @mcp_server = MCP::Server.new( name: 'rails-active-mcp', version: RailsActiveMcp::VERSION, description: 'Secure Rails console access via Model Context Protocol (MCP) for AI agents', website_url: 'https://github.com/goodpie/rails-active-mcp', tools: discover_tools, server_context: server_context ) # Set up server handlers setup_server_handlers end |
Instance Attribute Details
#mcp_server ⇒ Object (readonly)
Returns the value of attribute mcp_server.
16 17 18 |
# File 'lib/rails_active_mcp/sdk/server.rb', line 16 def mcp_server @mcp_server end |
Instance Method Details
#run_http(port: 3001) ⇒ Object
59 60 61 62 63 |
# File 'lib/rails_active_mcp/sdk/server.rb', line 59 def run_http(port: 3001) # HTTP transport might not be available in the SDK yet # For now, fall back to a basic implementation or error raise NotImplementedError, 'HTTP transport not yet implemented with official MCP SDK' end |
#run_stdio ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/rails_active_mcp/sdk/server.rb', line 43 def run_stdio # Ensure output redirection is active for stdio mode ensure_output_redirection_for_stdio require 'mcp/server/transports/stdio_transport' transport = MCP::Server::Transports::StdioTransport.new(@mcp_server) transport.open rescue StandardError => e # Log to stderr (which is redirected to file) and re-raise warn "[#{Time.now}] [RAILS-MCP] FATAL: SDK Server crashed: #{e.}" warn "[#{Time.now}] [RAILS-MCP] FATAL: #{e.backtrace.join("\n")}" raise ensure restore_output_streams end |