Class: VectorMCP::Definitions::Root
- Inherits:
-
Struct
- Object
- Struct
- VectorMCP::Definitions::Root
- Defined in:
- lib/vector_mcp/definitions.rb
Overview
Represents an MCP root definition. Roots define filesystem boundaries where servers can operate.
Instance Attribute Summary collapse
-
#name ⇒ Object
Returns the value of attribute name.
-
#uri ⇒ Object
Returns the value of attribute uri.
Class Method Summary collapse
-
.from_path(path, name: nil) ⇒ Root
Class method to create a root from a local directory path.
Instance Method Summary collapse
-
#as_mcp_definition ⇒ Hash
Converts the root to its MCP definition hash.
-
#path ⇒ String
Returns the filesystem path for file:// URIs.
-
#validate! ⇒ Boolean
Validates that the root URI is properly formatted and secure.
Instance Attribute Details
#name ⇒ Object
Returns the value of attribute name
220 221 222 |
# File 'lib/vector_mcp/definitions.rb', line 220 def name @name end |
#uri ⇒ Object
Returns the value of attribute uri
220 221 222 |
# File 'lib/vector_mcp/definitions.rb', line 220 def uri @uri end |
Class Method Details
.from_path(path, name: nil) ⇒ Root
Class method to create a root from a local directory path.
264 265 266 267 268 269 270 271 272 273 274 275 276 277 |
# File 'lib/vector_mcp/definitions.rb', line 264 def self.from_path(path, name: nil) # Expand path to get absolute path and resolve any relative components = File.(path) # Create file:// URI uri = "file://#{}" # Generate name if not provided default_name = name || File.basename() root = new(uri, default_name) root.validate! # Ensure the root is valid root end |
Instance Method Details
#as_mcp_definition ⇒ Hash
Converts the root to its MCP definition hash.
223 224 225 226 227 228 |
# File 'lib/vector_mcp/definitions.rb', line 223 def as_mcp_definition { uri: uri.to_s, name: name }.compact end |
#path ⇒ String
Returns the filesystem path for file:// URIs.
282 283 284 285 286 287 |
# File 'lib/vector_mcp/definitions.rb', line 282 def path parsed_uri = URI(uri.to_s) raise ArgumentError, "Cannot get path for non-file URI: #{uri}" unless parsed_uri.scheme == "file" parsed_uri.path end |
#validate! ⇒ Boolean
Validates that the root URI is properly formatted and secure.
233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 |
# File 'lib/vector_mcp/definitions.rb', line 233 def validate! # Validate URI format parsed_uri = begin URI(uri.to_s) rescue URI::InvalidURIError raise ArgumentError, "Invalid URI format: #{uri}" end # Currently, only file:// scheme is supported per MCP spec raise ArgumentError, "Only file:// URIs are supported for roots, got: #{parsed_uri.scheme}://" unless parsed_uri.scheme == "file" # Validate path exists and is a directory path = parsed_uri.path raise ArgumentError, "Root directory does not exist: #{path}" unless File.exist?(path) raise ArgumentError, "Root path is not a directory: #{path}" unless File.directory?(path) # Security check: ensure we can read the directory raise ArgumentError, "Root directory is not readable: #{path}" unless File.readable?(path) # Validate against path traversal attempts in the URI itself raise ArgumentError, "Root path contains unsafe traversal patterns: #{path}" if path.include?("..") || path.include?("./") true end |