Class: RosettAi::Mcp::Settings::TrustManager
- Inherits:
-
Object
- Object
- RosettAi::Mcp::Settings::TrustManager
- Defined in:
- lib/rosett_ai/mcp/settings/trust_manager.rb
Overview
Manages trust sources for MCP server installation.
Trust sources define which domains are approved for MCP server installation. Prevents untrusted servers from being silently added to configuration.
Constant Summary collapse
- CONFIG_DIR =
'.config/rosett-ai/mcp'- USER_TRUST_FILE =
'user_trust.yml'
Instance Method Summary collapse
-
#add_trust(domain, description: 'User-trusted domain')
Adds a user-trusted domain.
-
#initialize(config_dir: nil, defaults_path: nil) ⇒ TrustManager
constructor
A new instance of TrustManager.
-
#list ⇒ Array<Hash>
Lists all trusted sources (default + user-added).
-
#remove_trust(domain) ⇒ Boolean
Removes a user-trusted domain.
-
#trusted?(domain) ⇒ Boolean
Checks whether a domain is trusted.
-
#validate_uri(uri) ⇒ Hash
Validates whether a URI originates from a trusted source.
Constructor Details
#initialize(config_dir: nil, defaults_path: nil) ⇒ TrustManager
Returns a new instance of TrustManager.
23 24 25 26 |
# File 'lib/rosett_ai/mcp/settings/trust_manager.rb', line 23 def initialize(config_dir: nil, defaults_path: nil) @config_dir = config_dir || Pathname.new(Dir.home).join(CONFIG_DIR) @defaults_path = defaults_path || RosettAi.root.join('conf', 'mcp', 'trust.yml') end |
Instance Method Details
#add_trust(domain, description: 'User-trusted domain')
This method returns an undefined value.
Adds a user-trusted domain.
64 65 66 67 68 69 70 71 |
# File 'lib/rosett_ai/mcp/settings/trust_manager.rb', line 64 def add_trust(domain, description: 'User-trusted domain') sources = user_sources normalized = normalize_domain(domain) return if sources.any? { |s| normalize_domain(s[:domain]) == normalized } sources << { domain: normalized, type: 'user', description: description } write_user_sources(sources) end |
#list ⇒ Array<Hash>
Lists all trusted sources (default + user-added).
31 32 33 |
# File 'lib/rosett_ai/mcp/settings/trust_manager.rb', line 31 def list default_sources + user_sources end |
#remove_trust(domain) ⇒ Boolean
Removes a user-trusted domain.
77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/rosett_ai/mcp/settings/trust_manager.rb', line 77 def remove_trust(domain) # rubocop:disable Naming/PredicateMethod -- destructive action, not a predicate sources = user_sources normalized = normalize_domain(domain) original_size = sources.size sources.reject! { |s| normalize_domain(s[:domain]) == normalized } return false if sources.size == original_size write_user_sources(sources) true end |
#trusted?(domain) ⇒ Boolean
Checks whether a domain is trusted.
39 40 41 42 |
# File 'lib/rosett_ai/mcp/settings/trust_manager.rb', line 39 def trusted?(domain) normalized = normalize_domain(domain) list.any? { |source| normalize_domain(source[:domain]) == normalized } end |
#validate_uri(uri) ⇒ Hash
Validates whether a URI originates from a trusted source.
48 49 50 51 52 53 54 55 56 57 |
# File 'lib/rosett_ai/mcp/settings/trust_manager.rb', line 48 def validate_uri(uri) domain = extract_domain(uri) source = find_source(domain) if source { trusted: true, domain: domain, source_type: source[:type] } else { trusted: false, domain: domain, source_type: nil } end end |