Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions docs/_client/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,15 @@ This class supports:
Clients are initialized with a [transport layer](/client/transports/) instance that handles the low-level communication mechanics.
Authorization is handled by the transport layer; see [Authorization](/client/authorization/).

## Prompt Arguments

Pass template arguments by name when retrieving a prompt. This call supplies the `name` required by the `greeting` prompt.

```ruby
prompt = client.get_prompt(name: "greeting", arguments: { "name" => "Ari" })
prompt["messages"]
```

## Tool Objects

The client provides a wrapper class for tools returned by the server:
Expand Down
4 changes: 3 additions & 1 deletion lib/mcp/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -550,12 +550,14 @@ def read_resource(uri:, meta: nil, cancellation: nil, input_responses: nil, requ
# Gets a prompt from the server by name and returns its details.
#
# @param name [String] The name of the prompt to get.
# @param arguments [Hash{String => String}, nil] Values for the prompt template arguments.
# @param meta [Hash, nil] Additional `_meta` entries to send with the request,
# e.g. SEP-414 trace context (see {MCP::TraceContext}).
# @param cancellation [MCP::Cancellation, nil] Optional cancellation token.
# @return [Hash] A hash containing the prompt details.
def get_prompt(name:, meta: nil, cancellation: nil, input_responses: nil, request_state: nil)
def get_prompt(name:, arguments: nil, meta: nil, cancellation: nil, input_responses: nil, request_state: nil)
params = { name: name }
params[:arguments] = arguments unless arguments.nil?
params = params.merge(_meta: meta) if meta && !meta.empty?
params[:inputResponses] = input_responses if input_responses
params[:requestState] = request_state if request_state
Expand Down
7 changes: 5 additions & 2 deletions test/mcp/client_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -961,9 +961,12 @@ def test_get_prompt_drives_the_input_required_loop
client = Client.new(transport: transport)
client.on_elicitation { |_params| { action: "accept", content: {} } }

result = client.get_prompt(name: "my_prompt")
arguments = { "name" => "Ari" }
result = client.get_prompt(name: "my_prompt", arguments: arguments)

assert_equal({ "messages" => [] }, result)
assert_equal([arguments, arguments], sent_requests.map { |request| request.dig(:params, :arguments) })
assert_equal("accept", sent_requests[1].dig(:params, :inputResponses, "q", :action))
assert_equal("prompt-state", sent_requests[1].dig(:params, :requestState))
end

Expand Down Expand Up @@ -1176,7 +1179,7 @@ def test_get_prompt_sends_request_to_transport_and_returns_contents
transport.expects(:send_request).with do |args|
args.dig(:request, :method) == "prompts/get" &&
args.dig(:request, :jsonrpc) == "2.0" &&
args.dig(:request, :params, :name) == name
args.dig(:request, :params) == { name: name }
end.returns(mock_response).once

client = Client.new(transport: transport)
Expand Down