Remove Server#create_sampling_message direct call
## Motivation and Context Sampling is a one-to-one request/response interaction between a server and a specific client. `Server#create_sampling_message` does not scope requests to a specific session, which could lead to unintended broadcasts on multi-client transports. `ServerSession#create_sampling_message` should be used instead, as it routes the request to the correct client session. This aligns with the Python SDK, which also exposes sampling only at the session level. ## How Has This Been Tested? Existing tests updated to call `ServerSession#create_sampling_message` instead of `Server#create_sampling_message`. All tests pass (`rake test`), RuboCop is clean, and conformance tests pass. ## Breaking Changes `Server#create_sampling_message` is removed without a deprecation warning. The sampling feature was released recently and the method was not intended to be the primary API for this feature.
This commit is contained in:
parent
88248fc4c7
commit
a235572777
1 changed files with 26 additions and 287 deletions
|
|
@ -206,44 +206,6 @@ module MCP
|
|||
report_exception(e, { notification: "log_message" })
|
||||
end
|
||||
|
||||
# Sends a `sampling/createMessage` request to the client.
|
||||
# For single-client transports (e.g., `StdioTransport`). For multi-client transports
|
||||
# (e.g., `StreamableHTTPTransport`), use `ServerSession#create_sampling_message` instead
|
||||
# to ensure the request is routed to the correct client.
|
||||
def create_sampling_message(
|
||||
messages:,
|
||||
max_tokens:,
|
||||
system_prompt: nil,
|
||||
model_preferences: nil,
|
||||
include_context: nil,
|
||||
temperature: nil,
|
||||
stop_sequences: nil,
|
||||
metadata: nil,
|
||||
tools: nil,
|
||||
tool_choice: nil,
|
||||
related_request_id: nil
|
||||
)
|
||||
unless @transport
|
||||
raise "Cannot send sampling request without a transport."
|
||||
end
|
||||
|
||||
params = build_sampling_params(
|
||||
@client_capabilities,
|
||||
messages: messages,
|
||||
max_tokens: max_tokens,
|
||||
system_prompt: system_prompt,
|
||||
model_preferences: model_preferences,
|
||||
include_context: include_context,
|
||||
temperature: temperature,
|
||||
stop_sequences: stop_sequences,
|
||||
metadata: metadata,
|
||||
tools: tools,
|
||||
tool_choice: tool_choice,
|
||||
)
|
||||
|
||||
@transport.send_request(Methods::SAMPLING_CREATE_MESSAGE, params)
|
||||
end
|
||||
|
||||
# Sets a custom handler for `resources/read` requests.
|
||||
# The block receives the parsed request params and should return resource
|
||||
# contents. The return value is set as the `contents` field of the response.
|
||||
|
|
|
|||
Loading…
Reference in a new issue