Add define_custom_method to define custom methods

This commit is contained in:
Ates Goral 2025-07-14 19:04:12 -04:00
commit 1ed313951a

View file

@ -20,6 +20,15 @@ module MCP
end
end
class MethodAlreadyDefinedError < StandardError
attr_reader :method_name
def initialize(method_name)
super("Method #{method_name} already defined")
@method_name = method_name
end
end
include Instrumentation
attr_accessor :name, :version, :tools, :prompts, :resources, :server_context, :configuration, :capabilities, :transport
@ -89,6 +98,14 @@ module MCP
@prompts[prompt.name_value] = prompt
end
def define_custom_method(method_name:, &block)
if @handlers.key?(method_name)
raise MethodAlreadyDefinedError, method_name
end
@handlers[method_name] = block
end
def notify_tools_list_changed
return unless @transport