Class: RosettAi::Mcp::Server
- Inherits:
-
Object
- Object
- RosettAi::Mcp::Server
- Defined in:
- lib/rosett_ai/mcp/server.rb
Overview
MCP server for Rosett-AI — exposes validation, compilation, and configuration management as MCP tools, resources, and prompts.
Supports stdio (default) and HTTP (Puma) transports with a 6-layer Rack middleware stack for security.
Requires the mcp gem (optional dependency, :mcp group).
Constant Summary collapse
- MCP_SPEC_VERSION =
Returns Supported MCP protocol specification version.
'2025-03-26'- DEFAULT_PORT =
Returns Default port number for the server.
8484- DEFAULT_HOST =
Returns Default hostname for the server.
'localhost'
Instance Attribute Summary collapse
-
#security_config ⇒ Object
readonly
Returns the value of attribute security_config.
Class Method Summary collapse
-
.available? ⇒ Boolean
True if the mcp gem is available.
Instance Method Summary collapse
-
#http_app ⇒ Proc
Build the Rack application for HTTP transport.
-
#initialize(config_path: nil, plugins: []) ⇒ Server
constructor
A new instance of Server.
-
#serve ⇒ void
Starts the MCP server on stdio transport.
-
#serve_http(**options) ⇒ void
Starts the MCP server on HTTP transport via Puma.
-
#tools ⇒ Array<Hash>
Returns the tool registry for listing available tools.
Constructor Details
#initialize(config_path: nil, plugins: []) ⇒ Server
Returns a new instance of Server.
31 32 33 34 35 |
# File 'lib/rosett_ai/mcp/server.rb', line 31 def initialize(config_path: nil, plugins: []) @config_path = config_path @plugin_names = plugins @security_config = load_security_config(config_path) end |
Instance Attribute Details
#security_config ⇒ Object (readonly)
Returns the value of attribute security_config.
27 28 29 |
# File 'lib/rosett_ai/mcp/server.rb', line 27 def security_config @security_config end |
Class Method Details
.available? ⇒ Boolean
Returns true if the mcp gem is available.
38 39 40 41 42 43 |
# File 'lib/rosett_ai/mcp/server.rb', line 38 def self.available? require 'mcp' true rescue LoadError false end |
Instance Method Details
#http_app ⇒ Proc
Build the Rack application for HTTP transport.
85 86 87 88 89 |
# File 'lib/rosett_ai/mcp/server.rb', line 85 def http_app ensure_mcp_available! ensure_http_available! build_rack_app end |
#serve ⇒ void
This method returns an undefined value.
Starts the MCP server on stdio transport.
49 50 51 52 53 54 |
# File 'lib/rosett_ai/mcp/server.rb', line 49 def serve ensure_mcp_available! server = build_server transport = ::MCP::Server::Transports::StdioTransport.new(server) transport.open end |
#serve_http(**options) ⇒ void
This method returns an undefined value.
Starts the MCP server on HTTP transport via Puma.
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/rosett_ai/mcp/server.rb', line 66 def serve_http(**) ensure_mcp_available! ensure_http_available! port = .fetch(:port, DEFAULT_PORT) host = .fetch(:host, DEFAULT_HOST) tls_cert = [:tls_cert] tls_key = [:tls_key] validate_host_binding(host, .fetch(:allow_remote, false)) rack_app = build_rack_app start_puma(rack_app, port: port, host: host, tls_cert: tls_cert, tls_key: tls_key) end |
#tools ⇒ Array<Hash>
Returns the tool registry for listing available tools.
94 95 96 97 98 99 100 101 102 |
# File 'lib/rosett_ai/mcp/server.rb', line 94 def tools Governance::TOOL_CLASSES.map do |klass| { name: klass::TOOL_NAME, description: klass::DESCRIPTION, annotations: klass::ANNOTATIONS } end end |