-
Notifications
You must be signed in to change notification settings - Fork 45
Add McpPromptTrigger and McpPromptArgument annotations #235
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
Merged
ahmedmuhsin
merged 4 commits into
Azure:dev
from
ahmedmuhsin:feature/mcp-prompt-annotations
Apr 28, 2026
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
1e3d5c8
Add McpPromptTrigger and McpPromptArgument annotations
ahmedmuhsin b861a1e
Address review feedback: remove argumentName, fix Javadoc
ahmedmuhsin faec766
Bump version to 3.3.0 for new MCP prompt annotations
ahmedmuhsin ae0dde5
Remove inline JSON example from McpPromptTrigger Javadoc
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
76 changes: 76 additions & 0 deletions
76
src/main/java/com/microsoft/azure/functions/annotation/McpPromptArgument.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,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. | ||
| * <p> | ||
| * 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. | ||
| * </p> | ||
| * <p> | ||
| * 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}. | ||
| * </p> | ||
| * | ||
| * <p>Example:</p> | ||
| * <pre> | ||
| * {@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; | ||
| * } | ||
| * </pre> | ||
| * | ||
| * @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; | ||
| } |
120 changes: 120 additions & 0 deletions
120
src/main/java/com/microsoft/azure/functions/annotation/McpPromptTrigger.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 invoked by the Model Context Protocol (MCP) prompt system. | ||
| * <p> | ||
| * 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. | ||
| * </p> | ||
| * | ||
| * <p>Example:</p> | ||
| * <pre> | ||
| * {@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; | ||
| * } | ||
| * </pre> | ||
| * | ||
| * @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. | ||
| * <p> | ||
| * This serves as both the binding parameter name and the prompt identifier. | ||
| * It must be unique across all prompts in the function app. | ||
| * </p> | ||
| * | ||
| * @return The prompt name / 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 ""; | ||
|
|
||
| /** | ||
| * 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. | ||
| * <p> | ||
| * Each argument should be a JSON object with: name, description, required. | ||
| * Alternative: use {@link McpPromptArgument} annotations on parameters. | ||
| * </p> | ||
| * | ||
| * <p>Example:</p> | ||
| * <pre> | ||
| * [{"name":"code","description":"The code to review","required":true}] | ||
| * </pre> | ||
| * | ||
| * @return JSON array of argument definitions, or empty string | ||
| */ | ||
| String promptArguments() default ""; | ||
|
swapnil-nagar marked this conversation as resolved.
|
||
|
|
||
| /** | ||
| * 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 ""; | ||
| } | ||
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
namedifferent frompromptName?Per the spec from Lilian:
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.
name()serves as both the binding parameter name and the unique prompt identifier. The Maven plugin PR (#2554) patches it intopromptNamein function.json. This is the same convention asMcpToolTriggerwherename()is patched intotoolName. Added Javadoc clarifying this.