Class: Clacky::Mcp::ConnectionManager

Inherits:
Object
  • Object
show all
Defined in:
lib/clacky/mcp/connection_manager.rb

Defined Under Namespace

Classes: Error

Instance Method Summary collapse

Constructor Details

#initialize(server_name:, home: Dir.home, working_dir: Dir.pwd, session_factory: nil) ⇒ ConnectionManager

Returns a new instance of ConnectionManager.



14
15
16
17
18
19
20
21
# File 'lib/clacky/mcp/connection_manager.rb', line 14

def initialize(server_name:, home: Dir.home, working_dir: Dir.pwd, session_factory: nil)
  @server_name = server_name.to_s
  @home = File.expand_path(home)
  @working_dir = working_dir && File.expand_path(working_dir)
  @session_factory = session_factory || lambda do |_config, store, manager|
    OAuth::Session.new(store: store, manager: manager)
  end
end

Instance Method Details

#loginObject



23
24
25
26
27
28
# File 'lib/clacky/mcp/connection_manager.rb', line 23

def 
  session.
  safe_status
rescue OAuth::AuthorizationManager::Error, OAuth::Session::Error, OAuth::CredentialStore::Error => e
  raise Error, e.message
end

#logoutObject



36
37
38
39
40
41
# File 'lib/clacky/mcp/connection_manager.rb', line 36

def logout
  session.logout
  { "server" => @server_name, "connected" => false }
rescue OAuth::Session::Error, OAuth::CredentialStore::Error => e
  raise Error, e.message
end

#statusObject



30
31
32
33
34
# File 'lib/clacky/mcp/connection_manager.rb', line 30

def status
  safe_status
rescue OAuth::CredentialStore::Error => e
  raise Error, e.message
end