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.McpProtocolVersion;
021import org.jspecify.annotations.NonNull;
022
023import java.lang.annotation.ElementType;
024import java.lang.annotation.Retention;
025import java.lang.annotation.RetentionPolicy;
026import java.lang.annotation.Target;
027
028/**
029 * Declares a class that contributes an endpoint to Soklet's dedicated MCP
030 * server.
031 * <p>
032 * Soklet's annotation processor derives the endpoint descriptor without
033 * initializing the annotated class. A running MCP server creates endpoint
034 * instances through its configured instance provider when invoking handlers.
035 * Named application modules must open or export the endpoint package to
036 * Soklet. Packages containing non-public record types used for typed arguments
037 * or results must be open to Soklet's module for runtime conversion.
038 *
039 * @author <a href="https://www.revetkn.com">Mark Allen</a>
040 */
041@Target(ElementType.TYPE)
042@Retention(RetentionPolicy.RUNTIME)
043public @interface McpServerEndpoint {
044        /**
045         * The exact MCP protocol revisions available at this endpoint. At least one
046         * revision must be specified; revisions are never inferred or upgraded.
047         *
048         * @return supported protocol revisions
049         */
050        @NonNull
051        McpProtocolVersion @NonNull [] protocolVersions();
052
053        /**
054         * Revisions on which this endpoint exposes the Tasks facility.
055         *
056         * @return task-enabled revisions, or an empty array when disabled
057         */
058        @NonNull
059        McpProtocolVersion @NonNull [] taskProtocolVersions() default {};
060
061        /**
062         * Exact served revisions on which this endpoint enables sessions. Only
063         * {@code 2025-06-18} and {@code 2025-11-25} are eligible; Soklet's
064         * {@code 2026-07-28} implementation does not use sessions. The server must
065         * configure {@link com.soklet.McpSessionConfig}. Once enabled, later requests
066         * require the initialized session ID rather than falling back to stateless
067         * operation. The selected revisions must be a subset of {@link #protocolVersions()}.
068         *
069         * @return session-enabled revisions, or an empty array when disabled
070         */
071        @NonNull
072        McpProtocolVersion @NonNull [] sessionProtocolVersions() default {};
073
074        /**
075         * Exact revisions on which this endpoint enables subscriptions. Modern
076         * {@code 2026-07-28} exposes {@code subscriptions/listen}; supported
077         * {@code 2025-06-18} and {@code 2025-11-25} use session GET delivery and must
078         * also appear in {@link #sessionProtocolVersions()}. Legacy delivery requires
079         * server HTTP admission and an effective event source/family set. URI updates
080         * require an explicit URI authorizer; legacy catalog-only delivery does not.
081         *
082         * @return subscription-enabled revisions, or an empty array when disabled
083         */
084        @NonNull
085        McpProtocolVersion @NonNull [] subscriptionProtocolVersions() default {};
086        /**
087         * The fixed, non-root URL path exposed by the dedicated MCP server. It must
088         * be a normalized ASCII raw URI path of at most 8192 bytes; non-ASCII
089         * characters must be percent-encoded. Trailing slashes, repeated slashes,
090         * whitespace and dot segments are rejected; the declared path is never
091         * rewritten.
092         *
093         * @return the endpoint URL path
094         */
095        @NonNull
096        String path();
097
098        /**
099         * The implementation name reported to MCP clients.
100         *
101         * @return the nonblank implementation name
102         */
103        @NonNull
104        String name();
105
106        /**
107         * The implementation version reported to MCP clients.
108         *
109         * @return the nonblank implementation version
110         */
111        @NonNull
112        String version();
113
114        /**
115         * The optional human-readable implementation title.
116         *
117         * @return the title, or an empty string if none is configured
118         */
119        @NonNull
120        String title() default "";
121
122        /**
123         * The optional human-readable implementation description.
124         *
125         * @return the description, or an empty string if none is configured
126         */
127        @NonNull
128        String description() default "";
129
130        /**
131         * The optional absolute website URL for the implementation.
132         *
133         * @return the website URL, or an empty string if none is configured
134         */
135        @NonNull
136        String websiteUrl() default "";
137
138        /**
139         * Optional instructions that help clients use this endpoint.
140         *
141         * @return endpoint instructions, or an empty string if none are configured
142         */
143        @NonNull
144        String instructions() default "";
145
146        /**
147         * Names a server-registered tool rate limiter for this endpoint.
148         * <p>
149         * An empty value inherits the server's tool rate limiter. A nonempty value
150         * must identify an entry in the server's rate-limiter registry.
151         *
152         * @return the rate-limiter name, or an empty string to inherit
153         */
154        @NonNull
155        String toolRateLimiterName() default "";
156
157        /**
158         * The default cache time to live for {@code resources/list} pages.
159         *
160         * @return nonnegative whole-millisecond time to live
161         */
162        long resourceListCacheTimeToLiveInMilliseconds() default 0;
163
164        /**
165         * The fixed cache scope for every {@code resources/list} page.
166         *
167         * @return resources-list cache scope
168         */
169        @NonNull
170        McpCacheScope resourceListCacheScope() default McpCacheScope.PRIVATE;
171
172        /**
173         * The default cache time to live for
174         * {@code resources/templates/list}.
175         *
176         * @return nonnegative whole-millisecond time to live
177         */
178        long resourceTemplateListCacheTimeToLiveInMilliseconds() default 0;
179
180        /**
181         * The fixed cache scope for {@code resources/templates/list}.
182         *
183         * @return resource-template-list cache scope
184         */
185        @NonNull
186        McpCacheScope resourceTemplateListCacheScope()
187                        default McpCacheScope.PRIVATE;
188}