|
| 1 | +/** |
| 2 | + * Copyright (c) Microsoft Corporation. All rights reserved. |
| 3 | + * Licensed under the MIT License. See License.txt in the project root for |
| 4 | + * license information. |
| 5 | + */ |
| 6 | + |
| 7 | +package com.microsoft.azure.functions.annotation; |
| 8 | + |
| 9 | +import java.lang.annotation.ElementType; |
| 10 | +import java.lang.annotation.Retention; |
| 11 | +import java.lang.annotation.RetentionPolicy; |
| 12 | +import java.lang.annotation.Target; |
| 13 | + |
| 14 | +/** |
| 15 | + * Triggers an Azure Function when invoked by the Model Context Protocol (MCP) tool system. |
| 16 | + * <p> |
| 17 | + * This annotation enables Azure Functions to be called as tools from MCP-compatible clients |
| 18 | + * like AI assistants. The annotated parameter receives tool invocation arguments and context. |
| 19 | + * </p> |
| 20 | + * |
| 21 | + * <p>Example:</p> |
| 22 | + * <pre> |
| 23 | + * {@literal @}FunctionName("getFileContent") |
| 24 | + * public HttpResponseMessage getFile( |
| 25 | + * {@literal @}McpToolTrigger( |
| 26 | + * name = "request", |
| 27 | + * description = "Reads file content", |
| 28 | + * toolProperties = "[{\"propertyName\":\"filePath\",\"propertyType\":\"string\"," + |
| 29 | + * "\"description\":\"File path to read\"}]" |
| 30 | + * ) String toolRequest |
| 31 | + * ) { |
| 32 | + * // Parse and handle tool request |
| 33 | + * } |
| 34 | + * </pre> |
| 35 | + * |
| 36 | + * @see McpToolProperty |
| 37 | + * @since 3.2.0 |
| 38 | + */ |
| 39 | +@Target({ElementType.PARAMETER}) |
| 40 | +@Retention(RetentionPolicy.RUNTIME) |
| 41 | +public @interface McpToolTrigger { |
| 42 | + |
| 43 | + /** |
| 44 | + * The binding name for the tool invocation context parameter. |
| 45 | + * |
| 46 | + * @return The parameter binding name |
| 47 | + */ |
| 48 | + String name(); |
| 49 | + |
| 50 | + /** |
| 51 | + * Defines how Functions runtime should treat the parameter value. Possible values are: |
| 52 | + * <ul> |
| 53 | + * <li>"": get the value as a string, and try to deserialize to actual parameter type like POJO</li> |
| 54 | + * <li>string: always get the value as a string</li> |
| 55 | + * <li>binary: get the value as a binary data, and try to deserialize to actual parameter type byte[]</li> |
| 56 | + * </ul> |
| 57 | + * |
| 58 | + * @return The dataType which will be used by the Functions runtime. |
| 59 | + */ |
| 60 | + String dataType() default ""; |
| 61 | + |
| 62 | + /** |
| 63 | + * Human-readable description of what this tool does. |
| 64 | + * |
| 65 | + * @return Description of the tool's functionality |
| 66 | + */ |
| 67 | + String description(); |
| 68 | + |
| 69 | + /** |
| 70 | + * JSON array defining expected tool properties. |
| 71 | + * <p> |
| 72 | + * Each property should be a JSON object with: propertyName, propertyType, description. |
| 73 | + * Alternative: use {@link McpToolProperty} annotations on parameters. |
| 74 | + * </p> |
| 75 | + * |
| 76 | + * <p>Example:</p> |
| 77 | + * <pre> |
| 78 | + * [{"propertyName":"fileName","propertyType":"string","description":"File to read"}] |
| 79 | + * </pre> |
| 80 | + * |
| 81 | + * @return JSON array of property definitions, or empty string |
| 82 | + */ |
| 83 | + String toolProperties() default ""; |
| 84 | +} |
0 commit comments