-
Notifications
You must be signed in to change notification settings - Fork 45
Add McpResourceTrigger and McpMetadata annotations #231
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
ahmedmuhsin
wants to merge
4
commits into
Azure:dev
Choose a base branch
from
ahmedmuhsin:feature/mcp-resource-and-metadata
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+229
−1
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
4c13de7
Add McpResourceTrigger annotation and bump version to 3.2.4-beta
ahmedmuhsin 0deb2ff
Add McpMetadata annotation for attaching arbitrary JSON metadata to M…
ahmedmuhsin 1b39e2f
Remove -beta suffix from library version (3.2.4)
ahmedmuhsin f37b4c3
add title property
ahmedmuhsin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
108 changes: 108 additions & 0 deletions
108
src/main/java/com/microsoft/azure/functions/annotation/McpMetadata.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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). | ||
| * <p> | ||
| * This is a declarative annotation placed on the <b>same parameter</b> 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}. | ||
| * </p> | ||
| * <p> | ||
| * 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. | ||
| * </p> | ||
| * | ||
| * <p>Example with a resource trigger:</p> | ||
| * <pre> | ||
| * {@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"; | ||
| * } | ||
| * </pre> | ||
| * | ||
| * <p>Example with a tool trigger:</p> | ||
| * <pre> | ||
| * {@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"; | ||
| * } | ||
| * </pre> | ||
| * | ||
| * @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: | ||
| * <ul> | ||
| * <li>"": get the value as a string, and try to deserialize to actual parameter type like POJO</li> | ||
| * <li>string: always get the value as a string</li> | ||
| * <li>binary: get the value as a binary data, and try to deserialize to actual parameter type byte[]</li> | ||
| * </ul> | ||
| * | ||
| * @return The dataType which will be used by the Functions runtime. | ||
| */ | ||
| String dataType() default ""; | ||
|
|
||
| /** | ||
| * The metadata as a JSON string. | ||
| * <p> | ||
| * Must contain valid JSON. The contents are surfaced in the MCP protocol's | ||
| * {@code _meta} field when clients discover available tools or resources. | ||
| * </p> | ||
| * | ||
| * <p>Example:</p> | ||
| * <pre> | ||
| * json = "{\"author\": \"John Doe\", \"version\": 1.0, \"tags\": [\"utility\", \"time\"]}" | ||
| * </pre> | ||
| * | ||
| * @return The metadata JSON string | ||
| */ | ||
| String json(); | ||
| } |
120 changes: 120 additions & 0 deletions
120
src/main/java/com/microsoft/azure/functions/annotation/McpResourceTrigger.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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 an MCP client requests to read a resource. | ||
| * <p> | ||
| * 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). | ||
| * </p> | ||
| * | ||
| * <p>Example (text resource):</p> | ||
| * <pre> | ||
| * {@literal @}FunctionName("getReadme") | ||
| * public String getReadme( | ||
| * {@literal @}McpResourceTrigger( | ||
| * name = "context", | ||
| * uri = "file://readme.md", | ||
| * resourceName = "readme", | ||
| * title = "Application Readme", | ||
| * description = "Application readme file", | ||
| * mimeType = "text/plain" | ||
| * ) String context, | ||
| * final ExecutionContext executionContext | ||
| * ) { | ||
| * return "# My Application\nThis is the readme content."; | ||
| * } | ||
| * </pre> | ||
| * | ||
| * @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: | ||
| * <ul> | ||
| * <li>"": get the value as a string, and try to deserialize to actual parameter type like POJO</li> | ||
| * <li>string: always get the value as a string</li> | ||
| * <li>binary: get the value as a binary data, and try to deserialize to actual parameter type byte[]</li> | ||
| * </ul> | ||
| * | ||
| * @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(); | ||
|
|
||
| /** | ||
| * Optional human-readable title for display purposes. | ||
| * <p> | ||
| * Unlike {@code resourceName} which is a programmatic identifier, | ||
| * this is a friendly label for UI presentation. | ||
| * </p> | ||
| * | ||
| * @return The display title, or empty string if not specified | ||
| */ | ||
| String title() default ""; | ||
|
|
||
| /** | ||
| * 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 ""; | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the
titleproperty included?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm referencing this definition of the attribute from the extension which does not have
titlehttps://github.com/Azure/azure-functions-mcp-extension/blob/1ca16239e2f6db9ffc8da814312a9dac9da548ae/src/Microsoft.Azure.Functions.Worker.Extensions.Mcp/McpResourceTriggerAttribute.cs
I added the
titleproperty as a test and it gets ignored by the extension. The resources/list method only shows{ "resources": [{ "name": "Weather Widget", "uri": "ui://weather/index.html", "description": "Interactive weather display for MCP Apps", "mimeType": "text/html;profile=mcp-app", "_meta": {"ui": {"prefersBorder": true}} }] }However, when I pull the latest from main for the mcp extension I see that
titlewas added last weekAzure/azure-functions-mcp-extension@c084666
I'm not sure if there's an extension bundle release that includes that update, but I'll go ahead and add it assuming there will be one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done, thanks for catching it.