001/* 002 * Copyright 2022-2026 Revetware LLC. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 017package com.soklet; 018 019import org.jspecify.annotations.NonNull; 020import org.jspecify.annotations.Nullable; 021 022import javax.annotation.concurrent.Immutable; 023import java.util.List; 024 025import static java.util.Objects.requireNonNull; 026 027/** 028 * Immutable result for {@code resources/list}. 029 * 030 * @author <a href="https://www.revetkn.com">Mark Allen</a> 031 */ 032@Immutable 033public record McpListResourcesResult( 034 @NonNull List<@NonNull McpListedResource> resources, 035 @Nullable String nextCursor 036) { 037 public McpListResourcesResult { 038 requireNonNull(resources); 039 resources = List.copyOf(resources); 040 } 041 042 /** 043 * Creates a non-paginated {@code resources/list} result. 044 * 045 * @param resources the listed resources 046 * @return a result without a next cursor 047 */ 048 @NonNull 049 public static McpListResourcesResult fromResources(@NonNull List<@NonNull McpListedResource> resources) { 050 requireNonNull(resources); 051 return new McpListResourcesResult(resources, null); 052 } 053 054 /** 055 * Creates a paginated {@code resources/list} result. 056 * 057 * @param resources the listed resources for the current page 058 * @param nextCursor the cursor clients should use to request the next page 059 * @return a paginated list result 060 */ 061 @NonNull 062 public static McpListResourcesResult fromResourcesAndNextCursor(@NonNull List<@NonNull McpListedResource> resources, 063 @NonNull String nextCursor) { 064 requireNonNull(resources); 065 requireNonNull(nextCursor); 066 return new McpListResourcesResult(resources, nextCursor); 067 } 068}