Skip to content

Commit c2cedce

Browse files
committed
client: add prompts support
- Add prompts method to list available prompts - Add get_prompt method to retrieve prompt with arguments - Both methods support auto-initialization
1 parent e268738 commit c2cedce

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

lib/mcp/client.rb

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,37 @@ def read_resource(uri:)
151151
response.dig("result", "contents") || []
152152
end
153153

154+
# Lists available prompts from the server.
155+
#
156+
# @return [Array<Hash>] An array of available prompts.
157+
def prompts
158+
init unless @initialized
159+
160+
response = transport.send_request(request: {
161+
jsonrpc: JsonRpcHandler::Version::V2_0,
162+
id: request_id,
163+
method: "prompts/list",
164+
})
165+
166+
response.dig("result", "prompts") || []
167+
end
168+
169+
# Gets a prompt with the specified name and arguments.
170+
#
171+
# @param name [String] The name of the prompt to get.
172+
# @param arguments [Hash, nil] The arguments to pass to the prompt.
173+
# @return [Hash] The prompt result.
174+
def get_prompt(name:, arguments: nil)
175+
init unless @initialized
176+
177+
transport.send_request(request: {
178+
jsonrpc: JsonRpcHandler::Version::V2_0,
179+
id: request_id,
180+
method: "prompts/get",
181+
params: { name: name, arguments: arguments }.compact,
182+
})
183+
end
184+
154185
private
155186

156187
def request_id

0 commit comments

Comments
 (0)