Class: Foobara::McpConnector::Commands::Initialize

Inherits:
Command
  • Object
show all
Defined in:
foobara-mcp-connector-1.0.1/src/commands/initialize.rb

Constant Summary

Constants included from TruncatedInspect

TruncatedInspect::MAX_LENGTH

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Command

install!

Methods included from TruncatedInspect

#inspect, truncating

Methods included from Concern

foobara_class_methods_module_for, foobara_concern?, included

Instance Attribute Details

#sessionObject

Returns the value of attribute session.



58
59
60
# File 'src/commands/initialize.rb', line 58

def session
  @session
end

#versionObject

Returns the value of attribute version.



58
59
60
# File 'src/commands/initialize.rb', line 58

def version
  @version
end

Instance Method Details

#build_resultObject

Just hard-coding a bunch of these values to a limited set of abilities for now



85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'src/commands/initialize.rb', line 85

def build_result
  {
    protocolVersion: version,
    capabilities: {
      # We only support tools for now and don't yet support updating lists of tools
      tools: { listChanged: false }
    },
    serverInfo: {
      name: command_connector.server_name,
      version: command_connector.server_version
    },
    instructions: command_connector.instructions
  }
end

#command_connectorObject



68
69
70
# File 'src/commands/initialize.rb', line 68

def command_connector
  request.command_connector
end

#create_sessionObject



60
61
62
# File 'src/commands/initialize.rb', line 60

def create_session
  self.session = Session.new(inputs.except(:request))
end

#determine_versionObject



72
73
74
75
76
77
78
79
80
81
82
# File 'src/commands/initialize.rb', line 72

def determine_version
  versions_to_choose_from = SUPPORTED_VERSIONS.select do |supported_version|
    supported_version <= protocolVersion
  end

  if versions_to_choose_from.empty?
    versions_to_choose_from = SUPPORTED_VERSIONS
  end

  self.version = versions_to_choose_from.max
end

#executeObject



50
51
52
53
54
55
56
# File 'src/commands/initialize.rb', line 50

def execute
  create_session
  notify_connector_of_session
  determine_version

  build_result
end

#notify_connector_of_sessionObject



64
65
66
# File 'src/commands/initialize.rb', line 64

def notify_connector_of_session
  command_connector.session_created(session)
end