Merge pull request #163 from dak2/add-client-prompts-support

Add `prompts/list` and `prompts/get` support to client
This commit is contained in:
Koichi ITO 2025-10-19 02:24:36 +09:00 • committed by GitHub
commit ad87c8d805
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -58,6 +58,20 @@ module MCP
response.dig("result", "resources") || []
end
# Returns the list of prompts available from the server.
# Each call will make a new request – the result is not cached.
#
# @return [Array<Hash>] An array of available prompts.
def prompts
response = transport.send_request(request: {
jsonrpc: JsonRpcHandler::Version::V2_0,
id: request_id,
method: "prompts/list",
})
response.dig("result", "prompts") || []
end
# Calls a tool via the transport layer and returns the full response from the server.
#
# @param tool [MCP::Client::Tool] The tool to be called.
@ -96,6 +110,21 @@ module MCP
response.dig("result", "contents") || []
end
# Gets a prompt from the server by name and returns its details.
#
# @param name [String] The name of the prompt to get.
# @return [Hash] A hash containing the prompt details.
def get_prompt(name:)
response = transport.send_request(request: {
jsonrpc: JsonRpcHandler::Version::V2_0,
id: request_id,
method: "prompts/get",
params: { name: name },
})
response.fetch("result", {})
end
private
def request_id