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.annotation; 018 019import com.soklet.McpCacheScope; 020import com.soklet.McpRequestStateMode; 021import com.soklet.McpProtocolVersion; 022import org.jspecify.annotations.NonNull; 023 024import java.lang.annotation.ElementType; 025import java.lang.annotation.Retention; 026import java.lang.annotation.RetentionPolicy; 027import java.lang.annotation.Target; 028 029/** 030 * Declares an exact-URI or URI-template MCP resource-read handler. 031 * <p> 032 * A URI containing RFC 6570 Level 1 variables is a template registration; 033 * each variable is bound to exactly one {@link McpResourceUriParameter} 034 * method parameter. An exact URI contributes a descriptor to the static 035 * {@code resources/list} fallback. A URI template is advertised separately by 036 * {@code resources/templates/list}. 037 * <p> 038 * Level 1 simple variables cannot consume a raw slash: {@code file:///{path}} 039 * matches {@code file:///src%2Fmain.rs}, yielding {@code src/main.rs}, but not 040 * {@code file:///src/main.rs}. Reserved expansion ({@code {+path}}), explode 041 * and prefix modifiers are unsupported. Captured values are UTF-8 042 * percent-decoded exactly once. 043 * 044 * @author <a href="https://www.revetkn.com">Mark Allen</a> 045 */ 046@Target(ElementType.METHOD) 047@Retention(RetentionPolicy.RUNTIME) 048public @interface McpResource { 049 /** @return the required exact MCP revisions on which this resource is available */ 050 @NonNull 051 McpProtocolVersion @NonNull [] protocolVersions(); 052 /** 053 * The absolute resource URI or RFC 6570 Level 1 URI template. 054 * 055 * @return resource URI or URI template 056 */ 057 @NonNull 058 String uri(); 059 060 /** 061 * The resource name published to MCP clients. 062 * 063 * @return nonblank resource name 064 */ 065 @NonNull 066 String name(); 067 068 /** 069 * The optional human-readable resource title. 070 * 071 * @return title, or an empty string if none is configured 072 */ 073 @NonNull 074 String title() default ""; 075 076 /** 077 * The optional human-readable resource description. 078 * 079 * @return description, or an empty string if none is configured 080 */ 081 @NonNull 082 String description() default ""; 083 084 /** 085 * The optional resource MIME type. 086 * 087 * @return MIME type, or an empty string if none is configured 088 */ 089 @NonNull 090 String mimeType() default ""; 091 092 /** 093 * The raw size of an exact resource in bytes. 094 * <p> 095 * URI templates cannot declare a size because their concrete resources may 096 * differ. The default {@code -1} means that no size is published. 097 * 098 * @return nonnegative exact-resource size, or {@code -1} when absent 099 */ 100 long sizeInBytes() default -1; 101 102 /** 103 * The default cache time to live for reads through this registration. 104 * 105 * @return nonnegative whole-millisecond time to live 106 */ 107 long cacheTimeToLiveInMilliseconds() default 0; 108 109 /** 110 * The fixed cache scope for reads through this registration. 111 * 112 * @return cache scope 113 */ 114 @NonNull 115 McpCacheScope cacheScope() default McpCacheScope.PRIVATE; 116 117 /** 118 * Client requests this resource-read operation may emit during 119 * multi-round-trip handling. 120 * 121 * <p>A nonempty declaration requires the method to return 122 * {@code McpOperationResult} or a subtype. 123 * 124 * @return input-request declarations 125 */ 126 @NonNull 127 McpMayRequestInput @NonNull [] mayRequestInput() default {}; 128 129 /** 130 * The request-state contract for this resource-read operation. 131 * 132 * <p>A mode other than {@link McpRequestStateMode#NONE} requires the method 133 * to return {@code McpOperationResult} or a subtype. 134 * 135 * @return request-state mode 136 */ 137 @NonNull 138 McpRequestStateMode requestStateMode() default McpRequestStateMode.NONE; 139}