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.rest.server.mcp; 018 019/** 020 * Revision-neutral resource payload, either inline text or a base64 blob. 021 * 022 * <p> 023 * Supersedes the wire-level {@code ResourceContents} dictionary and its two leaf types. Used both 024 * by {@link McpContentBlock#resource(McpResourceContents)} and by {@link McpResourceOutcome}. 025 */ 026public final class McpResourceContents { 027 028 /** Which payload variant is populated. */ 029 public enum Kind { 030 /** {@link McpResourceContents#text()} is populated. */ 031 TEXT, 032 /** {@link McpResourceContents#blob()} is populated. */ 033 BLOB 034 } 035 036 private final Kind kind; 037 private final String uri; 038 private final String mimeType; 039 private final String text; 040 private final String blob; 041 042 private McpResourceContents(Kind kind, String uri, String mimeType, String text, String blob) { 043 this.kind = kind; 044 this.uri = uri; 045 this.mimeType = mimeType; 046 this.text = text; 047 this.blob = blob; 048 } 049 050 /** 051 * Creates an inline-text resource payload. 052 * 053 * @param uri The resource URI. Can be <jk>null</jk>. 054 * @param mimeType The media type. Can be <jk>null</jk>. 055 * @param text The text payload. Can be <jk>null</jk>. 056 * @return A new payload. Never <jk>null</jk>. 057 */ 058 public static McpResourceContents text(String uri, String mimeType, String text) { 059 return new McpResourceContents(Kind.TEXT, uri, mimeType, text, null); 060 } 061 062 /** 063 * Creates a base64-blob resource payload. 064 * 065 * @param uri The resource URI. Can be <jk>null</jk>. 066 * @param mimeType The media type. Can be <jk>null</jk>. 067 * @param blob The base64-encoded payload. Can be <jk>null</jk>. 068 * @return A new payload. Never <jk>null</jk>. 069 */ 070 public static McpResourceContents blob(String uri, String mimeType, String blob) { 071 return new McpResourceContents(Kind.BLOB, uri, mimeType, null, blob); 072 } 073 074 /** 075 * Which variant this payload carries. 076 * 077 * @return The variant. Never <jk>null</jk>. 078 */ 079 public Kind kind() { 080 return kind; 081 } 082 083 /** 084 * The resource URI. 085 * 086 * @return The URI, or <jk>null</jk> if not set. 087 */ 088 public String uri() { 089 return uri; 090 } 091 092 /** 093 * The media type. 094 * 095 * @return The media type, or <jk>null</jk> if not set. 096 */ 097 public String mimeType() { 098 return mimeType; 099 } 100 101 /** 102 * The inline text payload. 103 * 104 * @return The text, or <jk>null</jk> for a {@link Kind#BLOB} payload. 105 */ 106 public String text() { 107 return text; 108 } 109 110 /** 111 * The base64-encoded payload. 112 * 113 * @return The blob, or <jk>null</jk> for a {@link Kind#TEXT} payload. 114 */ 115 public String blob() { 116 return blob; 117 } 118}