diff --git a/pom.xml b/pom.xml index d636043..515289f 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ 4.0.0 com.microsoft.azure.functions azure-functions-java-library - 3.2.3 + 3.2.4 jar com.microsoft.maven diff --git a/src/main/java/com/microsoft/azure/functions/annotation/McpMetadata.java b/src/main/java/com/microsoft/azure/functions/annotation/McpMetadata.java new file mode 100644 index 0000000..af8b5b6 --- /dev/null +++ b/src/main/java/com/microsoft/azure/functions/annotation/McpMetadata.java @@ -0,0 +1,108 @@ +/** + * 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; + +/** + * Attaches arbitrary JSON metadata to an MCP trigger (tool or resource). + *

+ * This is a declarative annotation placed on the same parameter as the trigger + * annotation ({@link McpToolTrigger} or {@link McpResourceTrigger}). The metadata is surfaced + * in the MCP protocol's {@code _meta} field when clients call {@code tools/list} or + * {@code resources/list}. + *

+ *

+ * The {@code json} property must contain valid JSON. It can include any arbitrary key-value + * pairs such as author information, version numbers, UI hints, tags, or nested objects. + *

+ * + *

Example with a resource trigger:

+ *
+ * {@literal @}FunctionName("getReadme")
+ * public String getReadme(
+ *     {@literal @}McpResourceTrigger(
+ *         name = "context",
+ *         uri = "file://readme.md",
+ *         resourceName = "readme",
+ *         description = "Application readme file",
+ *         mimeType = "text/plain"
+ *     )
+ *     {@literal @}McpMetadata(
+ *         name = "context",
+ *         json = "{\"author\": \"John Doe\", \"version\": 1.0}"
+ *     ) String context,
+ *     final ExecutionContext executionContext
+ * ) {
+ *     return "# My Application";
+ * }
+ * 
+ * + *

Example with a tool trigger:

+ *
+ * {@literal @}FunctionName("getWeather")
+ * public String getWeather(
+ *     {@literal @}McpToolTrigger(
+ *         name = "context",
+ *         description = "Returns weather information"
+ *     )
+ *     {@literal @}McpMetadata(
+ *         name = "context",
+ *         json = "{\"version\": 1.0, \"author\": \"Jane Doe\"}"
+ *     ) String context
+ * ) {
+ *     return "Sunny, 72°F";
+ * }
+ * 
+ * + * @see McpToolTrigger + * @see McpResourceTrigger + * @since 3.2.4 + */ +@Target({ElementType.PARAMETER}) +@Retention(RetentionPolicy.RUNTIME) +public @interface McpMetadata { + + /** + * The binding parameter name. Should match the {@code name()} of the trigger + * annotation on the same parameter. + * + * @return The 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 ""; + + /** + * The metadata as a JSON string. + *

+ * Must contain valid JSON. The contents are surfaced in the MCP protocol's + * {@code _meta} field when clients discover available tools or resources. + *

+ * + *

Example:

+ *
+     * json = "{\"author\": \"John Doe\", \"version\": 1.0, \"tags\": [\"utility\", \"time\"]}"
+     * 
+ * + * @return The metadata JSON string + */ + String json(); +} diff --git a/src/main/java/com/microsoft/azure/functions/annotation/McpResourceTrigger.java b/src/main/java/com/microsoft/azure/functions/annotation/McpResourceTrigger.java new file mode 100644 index 0000000..9142f38 --- /dev/null +++ b/src/main/java/com/microsoft/azure/functions/annotation/McpResourceTrigger.java @@ -0,0 +1,108 @@ +/** + * 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 an MCP client requests to read a resource. + *

+ * This annotation enables Azure Functions to expose content (files, data, images) + * as MCP resources that can be discovered and consumed by MCP-compatible clients + * like AI assistants. The function returns the resource content as a string (text) + * or byte[] (binary). + *

+ * + *

Example (text resource):

+ *
+ * {@literal @}FunctionName("getReadme")
+ * public String getReadme(
+ *     {@literal @}McpResourceTrigger(
+ *         name = "context",
+ *         uri = "file://readme.md",
+ *         resourceName = "readme",
+ *         description = "Application readme file",
+ *         mimeType = "text/plain"
+ *     ) String context,
+ *     final ExecutionContext executionContext
+ * ) {
+ *     return "# My Application\nThis is the readme content.";
+ * }
+ * 
+ * + * @see McpToolTrigger + * @since 3.2.4 + */ +@Target({ElementType.PARAMETER}) +@Retention(RetentionPolicy.RUNTIME) +public @interface McpResourceTrigger { + + /** + * The binding name for the resource invocation context parameter. + * + * @return The 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 ""; + + /** + * The URI of the MCP resource (e.g., "file://readme.md"). + * + * @return The resource URI + */ + String uri(); + + /** + * The display name of the MCP resource. + * + * @return The resource name + */ + String resourceName(); + + /** + * The MIME type of the MCP resource (e.g., "text/plain", "image/png"). + * + * @return The MIME type, or empty string if not specified + */ + String mimeType() default ""; + + /** + * Human-readable description of this resource. + * + * @return Description of the resource + */ + String description() default ""; + + /** + * The optional size of the resource in bytes. A value of -1 indicates + * that the size is not specified. + * + * @return The resource size in bytes, or -1 if not specified + */ + long size() default -1; + + /** + * JSON-serialized metadata for the MCP resource. + * + * @return JSON metadata string, or empty string if not specified + */ + String metadata() default ""; +}