Class: Relay::Models::MCP
- Inherits:
-
Sequel::Model
- Object
- Sequel::Model
- Relay::Models::MCP
- Includes:
- Relay::Model
- Defined in:
- app/models/mcp.rb
Defined Under Namespace
Modules: Preset
Constant Summary collapse
- SUMMARY_COLUMNS =
%i[ id user_id name description transport enabled created_at updated_at ].freeze
stdio collapse
-
#arguments ⇒ Array<String>
Returns the stdio command arguments.
-
#argv ⇒ Array<String>
Returns the stdio command argv.
-
#command ⇒ String
Returns the stdio executable name.
-
#cwd ⇒ String
Returns the stdio working directory.
-
#env ⇒ Hash
Returns the stdio environment variables.
HTTP collapse
-
#headers ⇒ Hash
Returns the MCP HTTP headers.
-
#url ⇒ String
Returns the MCP HTTP endpoint URL.
Class Method Summary collapse
- .dump_data(data) ⇒ Object
- .load_data(data) ⇒ Object
- .normalize_url(value) ⇒ Object
- .summary_dataset(dataset = self.dataset) ⇒ Object
Instance Method Summary collapse
-
#data ⇒ Hash
Returns the parsed MCP transport data.
-
#start ⇒ void
Starts the MCP client.
-
#stop ⇒ void
Stops the MCP client.
-
#tools ⇒ Array<Class<LLM::Tool>>
Returns the cached MCP tool classes.
Methods included from Relay::Model
Class Method Details
.dump_data(data) ⇒ Object
24 25 26 |
# File 'app/models/mcp.rb', line 24 def self.dump_data(data) JSON.generate(data) end |
.load_data(data) ⇒ Object
28 29 30 31 32 33 34 35 36 |
# File 'app/models/mcp.rb', line 28 def self.load_data(data) case data when String then JSON.parse(data) when Hash, Array then data else {} end rescue JSON::ParserError {} end |
.normalize_url(value) ⇒ Object
42 43 44 45 46 47 48 49 50 |
# File 'app/models/mcp.rb', line 42 def self.normalize_url(value) url = value.to_s.strip return "" if url.empty? uri = URI.parse(url) uri.path = "/" if uri.path.to_s.empty? uri.to_s rescue URI::InvalidURIError url end |
.summary_dataset(dataset = self.dataset) ⇒ Object
38 39 40 |
# File 'app/models/mcp.rb', line 38 def self.summary_dataset(dataset = self.dataset) dataset.select(*SUMMARY_COLUMNS) end |
Instance Method Details
#arguments ⇒ Array<String>
Returns the stdio command arguments
79 80 81 |
# File 'app/models/mcp.rb', line 79 def arguments argv.drop(1) end |
#argv ⇒ Array<String>
Returns the stdio command argv
65 66 67 |
# File 'app/models/mcp.rb', line 65 def argv transport == "stdio" ? data["argv"] || [] : [] end |
#command ⇒ String
Returns the stdio executable name
72 73 74 |
# File 'app/models/mcp.rb', line 72 def command argv.first.to_s end |
#cwd ⇒ String
Returns the stdio working directory
93 94 95 |
# File 'app/models/mcp.rb', line 93 def cwd transport == "stdio" ? data["cwd"].to_s : "" end |
#data ⇒ Hash
Returns the parsed MCP transport data
55 56 57 |
# File 'app/models/mcp.rb', line 55 def data self.class.load_data(self[:data]) end |
#env ⇒ Hash
Returns the stdio environment variables
86 87 88 |
# File 'app/models/mcp.rb', line 86 def env transport == "stdio" ? data["env"] || {} : {} end |
#headers ⇒ Hash
Returns the MCP HTTP headers
111 112 113 |
# File 'app/models/mcp.rb', line 111 def headers transport == "http" ? data["headers"] || {} : {} end |
#start ⇒ void
This method returns an undefined value.
Returns Starts the MCP client.
126 127 128 |
# File 'app/models/mcp.rb', line 126 def start mcp.start end |
#stop ⇒ void
This method returns an undefined value.
Returns Stops the MCP client.
133 134 135 |
# File 'app/models/mcp.rb', line 133 def stop mcp.stop end |
#tools ⇒ Array<Class<LLM::Tool>>
Returns the cached MCP tool classes
119 120 121 |
# File 'app/models/mcp.rb', line 119 def tools @tools ||= mcp.tools end |
#url ⇒ String
Returns the MCP HTTP endpoint URL
104 105 106 |
# File 'app/models/mcp.rb', line 104 def url self.class.normalize_url(transport == "http" ? data["url"] : nil) end |