Skip to content
Open
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
2 changes: 1 addition & 1 deletion lib/mcp/server/pagination.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def cursor_from(request)
def paginate(items, cursor:, page_size:, request:, &block)
start_index = 0

if cursor
unless cursor.nil?
unless cursor.is_a?(String)
raise RequestHandlerError.new("Invalid cursor", request, error_type: :invalid_params)
end
Expand Down
7 changes: 7 additions & 0 deletions test/mcp/server/pagination_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,13 @@ class PaginationHost
assert_equal :invalid_params, error.error_type
end

test "paginate rejects a false cursor even without a page size" do
error = assert_raises(RequestHandlerError) do
@host.paginate(@items, cursor: false, page_size: nil, request: @request)
end
assert_equal :invalid_params, error.error_type
end

test "paginate raises RequestHandlerError for Integer cursor (spec requires string)" do
error = assert_raises(RequestHandlerError) do
@host.paginate(@items, cursor: 2, page_size: 2, request: @request)
Expand Down
10 changes: 10 additions & 0 deletions test/mcp/server_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5077,6 +5077,16 @@ def server_context
assert_equal(-32602, response[:error][:code])
end

test "#handle_json list methods reject a false cursor" do
server = Server.new(name: "test", tools: [@tool], prompts: [@prompt], page_size: 1)

["tools/list", "prompts/list"].each do |method|
request = { jsonrpc: "2.0", method: method, id: 1, params: { cursor: false } }
response = JSON.parse(server.handle_json(request.to_json))
assert_equal(-32602, response.dig("error", "code"), method)
end
end

test "#handle_json tools/list returns -32602 for numeric cursor (spec requires string)" do
server = Server.new(name: "test", tools: [@tool], page_size: 1)

Expand Down