Elicitation results are not checked against `requested_schema`, but the docs say they match it

Đang mở
#661 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

@atesgoral đang làm issue này rồi.

Từ ngày 6/11/2026.

  • #669 của @atesgoral — đang mở

Đánh giá

Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức phù hợp với người mới
35/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Đình trệ
Công nghệ
ruby

Hướng nghiên cứu

Start with lib/mcp/server_session.rb at create_form_elicitation, create_url_elicitation, and fulfill_input_request, then read docs/_server/elicitation.md for the documented contract. Check how the SDK represents validation errors and test these methods with the supplied invalid action and schema values. Done means invalid actions and invalid accepted content are rejected, with tests covering the stated cases.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

bug

docs/_server/elicitation.md says: "Per the MCP specification, the client validates the user's input against this schema before returning it, so the content of an accept response matches the requested shape." The server does not check this.

ServerSession#create_form_elicitation (server_session.rb:209-224), #create_url_elicitation (:231-246) and #fulfill_input_request (:253-255, used by the legacy input_required shim) return the client's result as received. action is not limited to accept, decline and cancel, and content is not checked against requested_schema (types, required, enum). A buggy or non-compliant client can return wrong types or values outside an enum, and handlers that follow the docs use them as-is.

Repro

Run from the repository root with bundle exec ruby -I lib repro.rb. The stub transport plays the client's reply.

require "mcp"

class ClientReply
  def initialize(reply)
    @reply = reply
  end

  def send_request(_method, _params = nil, **)
    @reply
  end

  def send_notification(*, **)
    true
  end
end

reply = { action: "accept", content: { replicas: "lots", environment: "unlisted" } }
server = MCP::Server.new(name: "example")
session = MCP::ServerSession.new(server: server, transport: ClientReply.new(reply), session_id: "A")
session.store_client_info(client: { name: "client", version: "1" }, capabilities: { elicitation: {} })

result = session.create_form_elicitation(
  message: "Deploy settings",
  requested_schema: {
    type: "object",
    properties: {
      replicas: { type: "integer" },
      environment: { type: "string", enum: ["staging", "production"] },
    },
    required: ["replicas", "environment"],
  },
  related_request_id: 1,
)

p result

Expected: an error (or at least not an accept result), because replicas is not an integer and environment is not in the enum.

Actual: {action: "accept", content: {replicas: "lots", environment: "unlisted"}}

The same happens with an unknown action such as {action: "approve-everything"}.

Suggested fix

Check action and, for accept, check content against the flat requested_schema before returning it from these methods, and raise a validation error on a mismatch. The elicitation schema subset is small (flat object, primitive types, enum, required). If validation is out of scope, change the docs to say that handlers must validate content themselves.

Ngôn ngữ chính
Ruby
Star
940
Fork
143
Merge trung bình
1 ngày 5 giờ
Pull request đã merge (30 ngày)
48

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của modelcontextprotocol/ruby-sdk

Tất cả issue của modelcontextprotocol/ruby-sdk

Issue tương tự

Thêm issue về Ruby

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.