Add define_custom_method to define custom methods
This commit is contained in:
parent
189d5fc5a5
commit
1ed313951a
1 changed files with 117 additions and 0 deletions
|
|
@ -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
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue