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 =
'2025-03-26'- DEFAULT_PORT =
8484- DEFAULT_HOST =
'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
Starts the MCP server on stdio transport.
-
#serve_http(**options)
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.
27 28 29 30 31 |
# File 'lib/rosett_ai/mcp/server.rb', line 27 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.
23 24 25 |
# File 'lib/rosett_ai/mcp/server.rb', line 23 def security_config @security_config end |
Class Method Details
.available? ⇒ Boolean
Returns true if the mcp gem is available.
34 35 36 37 38 39 |
# File 'lib/rosett_ai/mcp/server.rb', line 34 def self.available? require 'mcp' true rescue LoadError false end |
Instance Method Details
#http_app ⇒ Proc
Build the Rack application for HTTP transport.
81 82 83 84 85 |
# File 'lib/rosett_ai/mcp/server.rb', line 81 def http_app ensure_mcp_available! ensure_http_available! build_rack_app end |
#serve
This method returns an undefined value.
Starts the MCP server on stdio transport.
45 46 47 48 49 50 |
# File 'lib/rosett_ai/mcp/server.rb', line 45 def serve ensure_mcp_available! server = build_server transport = ::MCP::Server::Transports::StdioTransport.new(server) transport.open end |
#serve_http(**options)
This method returns an undefined value.
Starts the MCP server on HTTP transport via Puma.
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/rosett_ai/mcp/server.rb', line 62 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.
90 91 92 93 94 95 96 97 98 |
# File 'lib/rosett_ai/mcp/server.rb', line 90 def tools Governance::TOOL_CLASSES.map do |klass| { name: klass::TOOL_NAME, description: klass::DESCRIPTION, annotations: klass::ANNOTATIONS } end end |