Class: RosettAi::Mcp::Server

Inherits:
Object
  • Object
show all
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).

Author:

  • hugo

  • claude

Constant Summary collapse

MCP_SPEC_VERSION =
'2025-03-26'
DEFAULT_PORT =
8484
DEFAULT_HOST =
'localhost'

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config_path: nil, plugins: []) ⇒ Server

Returns a new instance of Server.

Parameters:

  • config_path (String, nil) (defaults to: nil)

    path to server config YAML

  • plugins (Array<String>) (defaults to: [])

    explicit plugin names to load



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_configObject (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.

Returns:

  • (Boolean)

    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_appProc

Build the Rack application for HTTP transport.

Returns:

  • (Proc)

    Rack application



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.

Raises:



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.

Parameters:

  • options (Hash)

    HTTP transport options

Options Hash (**options):

  • :port (Integer)

    HTTP port (default 8484)

  • :host (String)

    bind address (default localhost)

  • :tls_cert (String, nil)

    path to TLS certificate

  • :tls_key (String, nil)

    path to TLS private key

  • :allow_remote (Boolean)

    allow non-localhost binding

Raises:



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(**options)
  ensure_mcp_available!
  ensure_http_available!

  port = options.fetch(:port, DEFAULT_PORT)
  host = options.fetch(:host, DEFAULT_HOST)
  tls_cert = options[:tls_cert]
  tls_key = options[:tls_key]

  validate_host_binding(host, options.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

#toolsArray<Hash>

Returns the tool registry for listing available tools.

Returns:

  • (Array<Hash>)

    tool descriptors



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