001/* 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017package org.apache.juneau.bean.mcp.v20260728; 018 019import static org.apache.juneau.commons.utils.CollectionUtils.*; 020import static org.apache.juneau.commons.utils.Shorts.*; 021 022import java.util.*; 023 024import org.apache.juneau.commons.bean.*; 025import org.apache.juneau.marshall.*; 026 027/** 028 * Result payload for {@value McpMethods#SERVER_DISCOVER}. 029 * 030 * <p> 031 * Extends {@link CacheableResult} so discovery participates in the same SEP-2549 cache-hint machinery as the 032 * list/read results, and (transitively) {@link Result} so it inherits the required {@code resultType} 033 * discriminator plus {@code _meta}. Server identity belongs on the inherited {@code _meta} per the schema; there 034 * is no protocol version, session, or handshake state, and no top-level {@code serverInfo} member. Use the 035 * inherited {@link Result#getMeta()} server identity instead. 036 */ 037@Marshalled 038public class ServerDiscoverResult extends CacheableResult<ServerDiscoverResult> { 039 040 private List<String> supportedVersions; 041 private ServerCapabilities capabilities; 042 private String instructions; 043 044 /** 045 * Protocol versions this server supports, in preference order. 046 * 047 * @return The supported-versions list, or {@code null} if not set. 048 */ 049 public List<String> getSupportedVersions() { 050 return u(supportedVersions); 051 } 052 053 /** 054 * Sets the supported protocol versions. 055 * 056 * @param value The new value. Can be <jk>null</jk> to unset the property. 057 * @return This object (for method chaining). 058 */ 059 public ServerDiscoverResult setSupportedVersions(List<String> value) { 060 supportedVersions = value; 061 return this; 062 } 063 064 /** 065 * Sets the supported protocol versions. 066 * 067 * @param value The new value. Can be <jk>null</jk> to unset the property. 068 * @return This object (for method chaining). 069 */ 070 public ServerDiscoverResult setSupportedVersions(String...value) { 071 supportedVersions = list(value); 072 return this; 073 } 074 075 /** 076 * Appends to the supported protocol versions. 077 * 078 * @param value The values to append. 079 * @return This object (for method chaining). 080 */ 081 public ServerDiscoverResult addSupportedVersions(String...value) { 082 if (supportedVersions == null) 083 supportedVersions = list(); 084 Collections.addAll(supportedVersions, value); 085 return this; 086 } 087 088 /** 089 * Appends to the supported protocol versions. 090 * 091 * @param value The values to append. 092 * @return This object (for method chaining). 093 */ 094 public ServerDiscoverResult addSupportedVersions(Collection<String> value) { 095 if (supportedVersions == null) 096 supportedVersions = list(); 097 supportedVersions.addAll(value); 098 return this; 099 } 100 101 /** 102 * Server capability advertisement. 103 * 104 * @return The capabilities, or {@code null} if not set. 105 */ 106 public ServerCapabilities getCapabilities() { 107 return capabilities; 108 } 109 110 /** 111 * Sets the server capability advertisement. 112 * 113 * @param value The new value. Can be <jk>null</jk> to unset the property. 114 * @return This object (for method chaining). 115 */ 116 public ServerDiscoverResult setCapabilities(ServerCapabilities value) { 117 capabilities = value; 118 return this; 119 } 120 121 /** 122 * Optional free-form usage instructions for the client. 123 * 124 * @return The instructions, or {@code null} if not set. 125 */ 126 public String getInstructions() { 127 return instructions; 128 } 129 130 /** 131 * Sets the usage instructions. 132 * 133 * @param value The new value. Can be <jk>null</jk> to unset the property. 134 * @return This object (for method chaining). 135 */ 136 public ServerDiscoverResult setInstructions(String value) { 137 instructions = value; 138 return this; 139 } 140 141 /** 142 * Returns this result's server identity, if present. 143 * 144 * <p> 145 * Null-safe shortcut for {@code getMeta() == null ? null : getMeta().getServerInfo()}, so a caller does not 146 * have to null-check the intermediate {@link #getMeta()} just to reach the server's {@link Implementation}. 147 * 148 * @return The server identity, or {@code null} if {@link #getMeta()} is unset, or its 149 * {@link ResultMeta#getServerInfo()} is unset. 150 */ 151 // @BeanIgnore keeps this convenience getter from being (re)discovered as its own bean property, which 152 // would add a second, top-level "serverInfo" member to the server/discover wire format - identity 153 // belongs solely under the inherited _meta envelope (see the class javadoc). 154 @BeanIgnore 155 public Implementation getServerInfo() { 156 var m = getMeta(); 157 return m == null ? null : m.getServerInfo(); 158 } 159}