diff --git a/pom.xml b/pom.xml index 515289f..8a0e26c 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ 4.0.0 com.microsoft.azure.functions azure-functions-java-library - 3.2.4 + 3.3.0 jar com.microsoft.maven diff --git a/src/main/java/com/microsoft/azure/functions/annotation/McpPromptArgument.java b/src/main/java/com/microsoft/azure/functions/annotation/McpPromptArgument.java new file mode 100644 index 0000000..8582ec4 --- /dev/null +++ b/src/main/java/com/microsoft/azure/functions/annotation/McpPromptArgument.java @@ -0,0 +1,76 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + */ + +package com.microsoft.azure.functions.annotation; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * Defines a strongly-typed input argument for an MCP prompt function parameter. + *

+ * Alternative to using JSON format in {@link McpPromptTrigger#promptArguments()}. + * Each annotated parameter receives a specific argument value from the prompt invocation. + * Unlike tool properties, prompt arguments are always strings — no type schema is needed. + *

+ *

+ * The {@code name()} value serves as both the binding parameter name and the argument name + * exposed in the MCP protocol (the Maven plugin patches it into {@code argumentName} in + * function.json). This follows the same convention as {@link McpToolProperty} where + * {@code name()} is patched into {@code propertyName}. + *

+ * + *

Example:

+ *
+ * {@literal @}FunctionName("codeReview")
+ * public String codeReview(
+ *     {@literal @}McpPromptTrigger(name = "code_review", description = "Code review prompt") String context,
+ *     {@literal @}McpPromptArgument(
+ *         name = "code",
+ *         description = "The code to review",
+ *         isRequired = true
+ *     ) String code,
+ *     {@literal @}McpPromptArgument(
+ *         name = "language",
+ *         description = "The programming language"
+ *     ) String language
+ * ) {
+ *     return "Please review the following " + language + " code:\n\n" + code;
+ * }
+ * 
+ * + * @see McpPromptTrigger + * @since 3.3.0 + */ +@Target({ElementType.PARAMETER}) +@Retention(RetentionPolicy.RUNTIME) +public @interface McpPromptArgument { + + /** + * The argument name used as both the binding parameter name and the MCP protocol + * argument identifier. The Maven plugin patches this into {@code argumentName} + * in function.json. + * + * @return The argument name + */ + String name(); + + /** + * Description of the argument's purpose and usage. + * + * @return Description of the argument + */ + String description() default ""; + + /** + * Whether this argument is required for prompt invocation. + * + * @return true if required, false if optional + */ + boolean isRequired() default false; +} diff --git a/src/main/java/com/microsoft/azure/functions/annotation/McpPromptTrigger.java b/src/main/java/com/microsoft/azure/functions/annotation/McpPromptTrigger.java new file mode 100644 index 0000000..311f216 --- /dev/null +++ b/src/main/java/com/microsoft/azure/functions/annotation/McpPromptTrigger.java @@ -0,0 +1,120 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + */ + +package com.microsoft.azure.functions.annotation; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * Triggers an Azure Function when invoked by the Model Context Protocol (MCP) prompt system. + *

+ * This annotation enables Azure Functions to expose prompt templates that MCP-compatible clients + * can discover via {@code prompts/list} and invoke via {@code prompts/get} with arguments. + * The function returns a plain string (auto-wrapped into a single user message) or a + * JSON-serialized {@code GetPromptResult} for multi-message or rich content responses. + *

+ * + *

Example:

+ *
+ * {@literal @}FunctionName("codeReview")
+ * public String codeReview(
+ *     {@literal @}McpPromptTrigger(
+ *         name = "code_review",
+ *         description = "Generates a code review prompt"
+ *     ) String context,
+ *     {@literal @}McpPromptArgument(
+ *         name = "code",
+ *         description = "The code to review",
+ *         isRequired = true
+ *     ) String code,
+ *     {@literal @}McpPromptArgument(
+ *         name = "language",
+ *         description = "The programming language"
+ *     ) String language
+ * ) {
+ *     return "Please review the following " + language + " code:\n\n" + code;
+ * }
+ * 
+ * + * @see McpPromptArgument + * @see McpMetadata + * @since 3.3.0 + */ +@Target({ElementType.PARAMETER}) +@Retention(RetentionPolicy.RUNTIME) +public @interface McpPromptTrigger { + + /** + * The variable name used in function.json and also the unique prompt name + * that MCP clients use to identify and invoke this prompt. + *

+ * This serves as both the binding parameter name and the prompt identifier. + * It must be unique across all prompts in the function app. + *

+ * + * @return The prompt name / parameter binding name + */ + String name(); + + /** + * Defines how Functions runtime should treat the parameter value. Possible values are: + * + * + * @return The dataType which will be used by the Functions runtime. + */ + String dataType() default ""; + + /** + * Human-readable description of what this prompt does. + * + * @return Description of the prompt's purpose + */ + String description() default ""; + + /** + * Optional human-readable title for display purposes. + * + * @return The display title, or empty string if not specified + */ + String title() default ""; + + /** + * JSON array defining expected prompt arguments. + *

+ * Each argument should be a JSON object with: name, description, required. + * Alternative: use {@link McpPromptArgument} annotations on parameters. + *

+ * + *

Example:

+ *
+     * [{"name":"code","description":"The code to review","required":true}]
+     * 
+ * + * @return JSON array of argument definitions, or empty string + */ + String promptArguments() default ""; + + /** + * JSON-serialized metadata for the MCP prompt. + * + * @return JSON metadata string, or empty string if not specified + */ + String metadata() default ""; + + /** + * JSON array of icons for the MCP prompt. + * + * @return JSON array of icon definitions, or empty string if not specified + */ + String icons() default ""; +}