33require_relative 'client/client'
44require_relative 'client/retry'
55require_relative 'client/streaming'
6+ require_relative 'client/sampling'
7+ require_relative 'client/roots'
68
79module MCP
810 # Creates a new client instance with optional block configuration
@@ -15,6 +17,8 @@ def self.Client(options = {})
1517 # Add additional capabilities
1618 client . extend ( Client ::Retry )
1719 client . extend ( Client ::Streaming )
20+ client . extend ( Client ::Sampling )
21+ client . extend ( Client ::Roots )
1822
1923 yield client if block_given?
2024 client
@@ -29,6 +33,10 @@ class Client
2933 def initialize ( options = { } )
3034 @client = MCP . Client ( options )
3135
36+ # Set up roots and sampling handlers if provided
37+ @client . set_roots ( options [ :roots ] ) if options [ :roots ]
38+ @client . set_sampling_handler ( options [ :sampling_handler ] ) if options [ :sampling_handler ]
39+
3240 yield self if block_given?
3341
3442 self
@@ -54,7 +62,7 @@ def connected?
5462 @client . connected?
5563 end
5664
57- # Get the list of available tools
65+ # List available tools on the server
5866 # @return [Array<Hash>] The list of available tools
5967 def list_tools
6068 @client . list_tools
@@ -87,6 +95,74 @@ def with_retry(options = {}, retriable_errors = [StandardError], retry_condition
8795 @client . with_retry ( options , retriable_errors , retry_condition , &block )
8896 end
8997
98+ # List available resources on the server
99+ # @return [Array<Hash>] The list of available resources
100+ def list_resources
101+ @client . list_resources
102+ end
103+
104+ # List available resource templates on the server
105+ # @return [Array<Hash>] The list of available resource templates
106+ def list_resource_templates
107+ @client . list_resource_templates
108+ end
109+
110+ # Read a resource from the server
111+ # @param uri [String] The URI of the resource to read
112+ # @param params [Hash] Optional parameters for template resources
113+ # @return [Array<Hash>] The resource content
114+ def read_resource ( uri , params = nil )
115+ @client . read_resource ( uri , params )
116+ end
117+
118+ # List available prompts on the server
119+ # @return [Array<Hash>] The list of available prompts
120+ def list_prompts
121+ @client . list_prompts
122+ end
123+
124+ # Get a prompt from the server
125+ # @param name [String] The name of the prompt to get
126+ # @param arguments [Hash] Optional arguments for the prompt
127+ # @return [Array<Hash>] The prompt messages
128+ def get_prompt ( name , arguments = { } )
129+ @client . get_prompt ( name , arguments )
130+ end
131+
132+ # List available roots on the server
133+ # @return [Array<Hash>] The list of available roots
134+ def list_roots
135+ @client . list_roots
136+ end
137+
138+ # Read a file from a root on the server
139+ # @param root [String] The name of the root to read from
140+ # @param path [String] The path to read
141+ # @return [String] The file content
142+ def read_root_file ( root , path )
143+ @client . read_root_file ( root , path )
144+ end
145+
146+ # Allow models to call their host model for text generation
147+ # @param prompt [String, Array<Hash>] The prompt to generate from
148+ # @param options [Hash] Generation options
149+ # @return [String] The generated text
150+ def sample ( prompt , options = { } )
151+ @client . sample ( prompt , options )
152+ end
153+
154+ # Set the roots list handler
155+ # @param roots [Array<Hash>] The roots to register
156+ def set_roots ( roots )
157+ @client . set_roots ( roots )
158+ end
159+
160+ # Set the sampling handler
161+ # @param handler [Proc] The handler function
162+ def set_sampling_handler ( handler )
163+ @client . set_sampling_handler ( handler )
164+ end
165+
90166 # Forward other methods to the client instance
91167 def method_missing ( method , *args , &block )
92168 if @client . respond_to? ( method )
0 commit comments