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.McpRequestStateMode; 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 an MCP tool handler method. 030 * <p> 031 * Soklet's annotation processor derives the input schema from parameters 032 * annotated with {@link McpToolArgument}. For an ordinary typed-completion 033 * method, it derives the output schema from the declared return type. A method 034 * returning {@link com.soklet.McpTaskCreatedResult} is statically task-only and 035 * derives its eventual output schema from the result's type argument; Soklet 036 * rejects a client without the Tasks capability before invoking it. Other 037 * methods returning {@link com.soklet.McpOperationResult} or a subtype use the 038 * dynamic advanced-result path and have no derived output schema. 039 * {@link McpToolProperty} customizes property metadata on ordinary typed input 040 * and output records. 041 * 042 * <p>A statically task-only method may accept one unannotated 043 * {@link com.soklet.McpTaskCreationContext} parameter directly. The same context remains 044 * available through {@link com.soklet.McpInvocationFeatures} for dynamic 045 * handlers. A task-control parameter must not be annotated with 046 * {@link McpToolArgument}. 047 * 048 * @author <a href="https://www.revetkn.com">Mark Allen</a> 049 */ 050@Target(ElementType.METHOD) 051@Retention(RetentionPolicy.RUNTIME) 052public @interface McpTool { 053 /** 054 * Exact MCP revisions on which this tool is available. At least one is 055 * required, and every revision must be exposed by the owning endpoint. 056 * 057 * @return supported protocol revisions 058 */ 059 @NonNull 060 McpProtocolVersion @NonNull [] protocolVersions(); 061 /** 062 * The tool name published to MCP clients. 063 * 064 * @return the nonblank tool name 065 */ 066 @NonNull 067 String name(); 068 069 /** 070 * The optional human-readable tool title. 071 * 072 * @return the title, or an empty string if none is configured 073 */ 074 @NonNull 075 String title() default ""; 076 077 /** 078 * The optional human-readable tool description. 079 * 080 * @return the description, or an empty string if none is configured 081 */ 082 @NonNull 083 String description() default ""; 084 085 /** 086 * Names a server-registered rate limiter for this tool. 087 * <p> 088 * An empty value inherits the endpoint or server tool rate limiter. A 089 * nonempty value must identify an entry in the server's rate-limiter 090 * registry. 091 * 092 * @return the rate-limiter name, or an empty string to inherit 093 */ 094 @NonNull 095 String rateLimiterName() default ""; 096 097 /** 098 * Whether Soklet mirrors structured tool output into a text content block. 099 * 100 * @return {@code true} to mirror structured content as text 101 */ 102 boolean structuredContentMirroredAsText() default true; 103 104 /** 105 * Client requests this tool may emit during multi-round-trip handling. 106 * 107 * <p>A nonempty declaration requires the method to return 108 * {@code McpOperationResult} or a subtype. 109 * 110 * @return input-request declarations 111 */ 112 @NonNull 113 McpMayRequestInput @NonNull [] mayRequestInput() default {}; 114 115 /** 116 * The request-state contract for this tool. 117 * 118 * <p>A mode other than {@link McpRequestStateMode#NONE} requires the method 119 * to return {@code McpOperationResult} or a subtype. 120 * 121 * @return request-state mode 122 */ 123 @NonNull 124 McpRequestStateMode requestStateMode() default McpRequestStateMode.NONE; 125}