Class: ZeroMcp::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/zeromcp/config.rb

Constant Summary collapse

ICON_MIME =
{
  '.png'  => 'image/png',
  '.jpg'  => 'image/jpeg',
  '.jpeg' => 'image/jpeg',
  '.gif'  => 'image/gif',
  '.svg'  => 'image/svg+xml',
  '.ico'  => 'image/x-icon',
  '.webp' => 'image/webp'
}.freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ Config

Returns a new instance of Config.



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/zeromcp/config.rb', line 12

def initialize(opts = {})
  tools = opts[:tools_dir] || opts['tools'] || './tools'
  @tools_dir = tools.is_a?(Array) ? tools : [tools]

  resources = opts[:resources_dir] || opts['resources']
  @resources_dir = resources ? (resources.is_a?(Array) ? resources : [resources]) : []

  prompts = opts[:prompts_dir] || opts['prompts']
  @prompts_dir = prompts ? (prompts.is_a?(Array) ? prompts : [prompts]) : []

  @separator = opts[:separator] || opts['separator'] || '_'
  @logging = opts[:logging] || opts['logging'] || false
  @bypass_permissions = opts[:bypass_permissions] || opts['bypass_permissions'] || false
  @execute_timeout = opts[:execute_timeout] || opts['execute_timeout'] || 30 # seconds
  @credentials = opts[:credentials] || opts['credentials'] || {}
  @cache_credentials = opts.key?(:cache_credentials) ? opts[:cache_credentials] : (opts.key?('cache_credentials') ? opts['cache_credentials'] : true)
  @namespacing = opts[:namespacing] || opts['namespacing'] || {}
  @page_size = opts[:page_size] || opts['page_size'] || 0
  @icon = opts[:icon] || opts['icon']
end

Instance Attribute Details

#bypass_permissionsObject (readonly)

Returns the value of attribute bypass_permissions.



8
9
10
# File 'lib/zeromcp/config.rb', line 8

def bypass_permissions
  @bypass_permissions
end

#cache_credentialsObject (readonly)

Returns the value of attribute cache_credentials.



33
34
35
# File 'lib/zeromcp/config.rb', line 33

def cache_credentials
  @cache_credentials
end

#credentialsObject (readonly)

Returns the value of attribute credentials.



33
34
35
# File 'lib/zeromcp/config.rb', line 33

def credentials
  @credentials
end

#execute_timeoutObject (readonly)

Returns the value of attribute execute_timeout.



8
9
10
# File 'lib/zeromcp/config.rb', line 8

def execute_timeout
  @execute_timeout
end

#iconObject (readonly)

Returns the value of attribute icon.



8
9
10
# File 'lib/zeromcp/config.rb', line 8

def icon
  @icon
end

#loggingObject (readonly)

Returns the value of attribute logging.



8
9
10
# File 'lib/zeromcp/config.rb', line 8

def logging
  @logging
end

#namespacingObject (readonly)

Returns the value of attribute namespacing.



33
34
35
# File 'lib/zeromcp/config.rb', line 33

def namespacing
  @namespacing
end

#page_sizeObject (readonly)

Returns the value of attribute page_size.



8
9
10
# File 'lib/zeromcp/config.rb', line 8

def page_size
  @page_size
end

#prompts_dirObject (readonly)

Returns the value of attribute prompts_dir.



8
9
10
# File 'lib/zeromcp/config.rb', line 8

def prompts_dir
  @prompts_dir
end

#resources_dirObject (readonly)

Returns the value of attribute resources_dir.



8
9
10
# File 'lib/zeromcp/config.rb', line 8

def resources_dir
  @resources_dir
end

#separatorObject (readonly)

Returns the value of attribute separator.



8
9
10
# File 'lib/zeromcp/config.rb', line 8

def separator
  @separator
end

#tools_dirObject (readonly)

Returns the value of attribute tools_dir.



8
9
10
# File 'lib/zeromcp/config.rb', line 8

def tools_dir
  @tools_dir
end

Class Method Details

.load(path = nil) ⇒ Object



35
36
37
38
39
40
41
42
43
44
# File 'lib/zeromcp/config.rb', line 35

def self.load(path = nil)
  path ||= File.join(Dir.pwd, 'zeromcp.config.json')
  return new unless File.exist?(path)

  raw = File.read(path)
  data = JSON.parse(raw)
  new(data)
rescue JSON::ParserError
  new
end

.resolve_icon(icon) ⇒ Object

Resolve an icon config value to a data URI. Supports:

  • data: URIs (returned as-is)

  • Local file paths (read and base64 encode)

Returns nil on failure or if icon is not set.



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/zeromcp/config.rb', line 50

def self.resolve_icon(icon)
  return nil if icon.nil? || icon.empty?
  return icon if icon.start_with?('data:')

  # File path
  path = File.expand_path(icon)
  return nil unless File.exist?(path)

  ext = File.extname(path).downcase
  mime = ICON_MIME[ext] || 'image/png'
  data = File.binread(path)
  "data:#{mime};base64,#{Base64.strict_encode64(data)}"
rescue => e
  $stderr.puts "[zeromcp] Warning: failed to read icon file #{icon}: #{e.message}"
  nil
end