Module: VectorMCP::Server::Registry

Included in:
VectorMCP::Server
Defined in:
lib/vector_mcp/server/registry.rb

Overview

Handles registration of tools, resources, prompts, and roots

Instance Method Summary collapse

Instance Method Details

#register_image_prompt(name:, description:, image_argument: "image", additional_arguments: [], &block) ⇒ VectorMCP::Definitions::Prompt

Helper method to register a prompt that supports image arguments.

Parameters:

  • name (String)

    Unique name for the prompt.

  • description (String)

    Human-readable description.

  • image_argument (String) (defaults to: "image")

    Name of the image argument (default: "image").

  • additional_arguments (Array<Hash>) (defaults to: [])

    Additional prompt arguments.

  • block (Proc)

    The prompt handler block.

Returns:



195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
# File 'lib/vector_mcp/server/registry.rb', line 195

def register_image_prompt(name:, description:, image_argument: "image", additional_arguments: [], &block)
  prompt = VectorMCP::Definitions::Prompt.with_image_support(
    name: name,
    description: description,
    image_argument_name: image_argument,
    additional_arguments: additional_arguments,
    &block
  )

  register_prompt(
    name: prompt.name,
    description: prompt.description,
    arguments: prompt.arguments,
    &prompt.handler
  )
end

#register_image_resource(uri:, file_path:, name: nil, description: nil) ⇒ VectorMCP::Definitions::Resource

Helper method to register an image resource from a file path.

Parameters:

  • uri (String)

    Unique URI for the resource.

  • file_path (String)

    Path to the image file.

  • name (String, nil) (defaults to: nil)

    Human-readable name (auto-generated if nil).

  • description (String, nil) (defaults to: nil)

    Description (auto-generated if nil).

Returns:

Raises:

  • (ArgumentError)

    If the file doesn't exist or isn't a valid image.



109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
# File 'lib/vector_mcp/server/registry.rb', line 109

def register_image_resource(uri:, file_path:, name: nil, description: nil)
  resource = VectorMCP::Definitions::Resource.from_image_file(
    uri: uri,
    file_path: file_path,
    name: name,
    description: description
  )

  register_resource(
    uri: resource.uri,
    name: resource.name,
    description: resource.description,
    mime_type: resource.mime_type,
    &resource.handler
  )
end

#register_image_resource_from_data(uri:, image_data:, name:, description: nil, mime_type: nil) ⇒ VectorMCP::Definitions::Resource

Helper method to register an image resource from binary data.

Parameters:

  • uri (String)

    Unique URI for the resource.

  • image_data (String)

    Binary image data.

  • name (String)

    Human-readable name.

  • description (String, nil) (defaults to: nil)

    Description (auto-generated if nil).

  • mime_type (String, nil) (defaults to: nil)

    MIME type (auto-detected if nil).

Returns:

Raises:

  • (ArgumentError)

    If the data isn't valid image data.



135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
# File 'lib/vector_mcp/server/registry.rb', line 135

def register_image_resource_from_data(uri:, image_data:, name:, description: nil, mime_type: nil)
  resource = VectorMCP::Definitions::Resource.from_image_data(
    uri: uri,
    image_data: image_data,
    name: name,
    description: description,
    mime_type: mime_type
  )

  register_resource(
    uri: resource.uri,
    name: resource.name,
    description: resource.description,
    mime_type: resource.mime_type,
    &resource.handler
  )
end

#register_image_tool(name:, description:, image_parameter: "image", additional_parameters: {}, required_parameters: [], &block) ⇒ VectorMCP::Definitions::Tool

Helper method to register a tool that accepts image inputs.

Parameters:

  • name (String)

    Unique name for the tool.

  • description (String)

    Human-readable description.

  • image_parameter (String) (defaults to: "image")

    Name of the image parameter (default: "image").

  • additional_parameters (Hash) (defaults to: {})

    Additional JSON Schema properties.

  • required_parameters (Array<String>) (defaults to: [])

    List of required parameter names.

  • block (Proc)

    The tool handler block.

Returns:



162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
# File 'lib/vector_mcp/server/registry.rb', line 162

def register_image_tool(name:, description:, image_parameter: "image", additional_parameters: {}, required_parameters: [], &block)
  # Build the input schema with image support
  image_property = {
    type: "string",
    description: "Base64 encoded image data or file path to image",
    contentEncoding: "base64",
    contentMediaType: "image/*"
  }

  properties = { image_parameter => image_property }.merge(additional_parameters)

  input_schema = {
    type: "object",
    properties: properties,
    required: required_parameters
  }

  register_tool(
    name: name,
    description: description,
    input_schema: input_schema,
    &block
  )
end

#register_prompt(name:, description:, arguments: []) {|Hash| ... } ⇒ self

Registers a new prompt with the server.

Parameters:

  • name (String, Symbol)

    The unique name for the prompt.

  • description (String)

    A human-readable description of the prompt.

  • arguments (Array<Hash>) (defaults to: [])

    An array defining the prompt's arguments.

Yields:

  • (Hash)

    A block that generates the prompt.

Returns:

  • (self)

    The server instance, for chaining.

Raises:

  • (ArgumentError)

    if a prompt with the same name is already registered.



58
59
60
61
62
63
64
65
66
67
68
# File 'lib/vector_mcp/server/registry.rb', line 58

def register_prompt(name:, description:, arguments: [], &handler)
  name_s = name.to_s
  raise ArgumentError, "Prompt '#{name_s}' already registered" if @prompts[name_s]

  validate_prompt_arguments(arguments)
  @prompts[name_s] = VectorMCP::Definitions::Prompt.new(name_s, description, arguments, handler)
  @prompts_list_changed = true
  notify_prompts_list_changed
  logger.debug("Registered prompt: #{name_s}")
  self
end

#register_resource(uri:, name:, description:, mime_type: "text/plain") {|Hash| ... } ⇒ self

Registers a new resource with the server.

Parameters:

  • uri (String, URI)

    The unique URI for the resource.

  • name (String)

    A human-readable name for the resource.

  • description (String)

    A description of the resource.

  • mime_type (String) (defaults to: "text/plain")

    The MIME type of the resource's content (default: "text/plain").

Yields:

  • (Hash)

    A block that provides the resource's content.

Returns:

  • (self)

    The server instance, for chaining.

Raises:

  • (ArgumentError)

    if a resource with the same URI is already registered.



41
42
43
44
45
46
47
48
# File 'lib/vector_mcp/server/registry.rb', line 41

def register_resource(uri:, name:, description:, mime_type: "text/plain", &handler)
  uri_s = uri.to_s
  raise ArgumentError, "Resource '#{uri_s}' already registered" if @resources[uri_s]

  @resources[uri_s] = VectorMCP::Definitions::Resource.new(uri, name, description, mime_type, handler)
  logger.debug("Registered resource: #{uri_s}")
  self
end

#register_root(uri:, name:) ⇒ self

Registers a new root with the server.

Parameters:

  • uri (String, URI)

    The unique URI for the root (must be file:// scheme).

  • name (String)

    A human-readable name for the root.

Returns:

  • (self)

    The server instance, for chaining.

Raises:

  • (ArgumentError)

    if a root with the same URI is already registered.



76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/vector_mcp/server/registry.rb', line 76

def register_root(uri:, name:)
  uri_s = uri.to_s
  raise ArgumentError, "Root '#{uri_s}' already registered" if @roots[uri_s]

  root = VectorMCP::Definitions::Root.new(uri, name)
  root.validate! # This will raise ArgumentError if invalid

  @roots[uri_s] = root
  @roots_list_changed = true
  notify_roots_list_changed
  logger.debug("Registered root: #{uri_s} (#{name})")
  self
end

#register_root_from_path(path, name: nil) ⇒ self

Helper method to register a root from a local directory path.

Parameters:

  • path (String)

    Local filesystem path to the directory.

  • name (String, nil) (defaults to: nil)

    Human-readable name for the root.

Returns:

  • (self)

    The server instance, for chaining.

Raises:

  • (ArgumentError)

    if the path is invalid or not accessible.



96
97
98
99
# File 'lib/vector_mcp/server/registry.rb', line 96

def register_root_from_path(path, name: nil)
  root = VectorMCP::Definitions::Root.from_path(path, name: name)
  register_root(uri: root.uri, name: root.name)
end

#register_tool(name:, description:, input_schema:) {|Hash| ... } ⇒ self

Registers a new tool with the server.

Parameters:

  • name (String, Symbol)

    The unique name for the tool.

  • description (String)

    A human-readable description of the tool.

  • input_schema (Hash)

    A JSON Schema object that precisely describes the structure of the argument hash your tool expects.

Yields:

  • (Hash)

    A block implementing the tool logic.

Returns:

  • (self)

    Returns the server instance so you can chain registrations.

Raises:

  • (ArgumentError)

    If another tool with the same name is already registered.



20
21
22
23
24
25
26
27
28
29
30
# File 'lib/vector_mcp/server/registry.rb', line 20

def register_tool(name:, description:, input_schema:, &handler)
  name_s = name.to_s
  raise ArgumentError, "Tool '#{name_s}' already registered" if @tools[name_s]

  # Validate schema format during registration
  validate_schema_format!(input_schema) if input_schema

  @tools[name_s] = VectorMCP::Definitions::Tool.new(name_s, description, input_schema, handler)
  logger.debug("Registered tool: #{name_s}")
  self
end