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 =

Returns Supported MCP protocol specification version.

Returns:

  • (String)

    Supported MCP protocol specification version.

'2025-03-26'
DEFAULT_PORT =

Returns Default port number for the server.

Returns:

  • (Integer)

    Default port number for the server.

8484
DEFAULT_HOST =

Returns Default hostname for the server.

Returns:

  • (String)

    Default hostname for the server.

'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



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

Returns:

  • (Boolean)

    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_appProc

Build the Rack application for HTTP transport.

Returns:

  • (Proc)

    Rack application



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

#servevoid

This method returns an undefined value.

Starts the MCP server on stdio transport.

Raises:



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.

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:



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(**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



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