-
Notifications
You must be signed in to change notification settings - Fork 4
Add structured content and MCP prompt sample functions #17
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
base: main
Are you sure you want to change the base?
Changes from all commits
5487dae
c25cc61
1552ac3
8772ef5
6575ee8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,88 @@ | ||
| package com.function; | ||
|
|
||
| import com.microsoft.azure.functions.ExecutionContext; | ||
| import com.microsoft.azure.functions.annotation.FunctionName; | ||
| import com.microsoft.azure.functions.annotation.McpPromptArgument; | ||
| import com.microsoft.azure.functions.annotation.McpPromptTrigger; | ||
|
|
||
| /** | ||
| * Demonstrates MCP Prompt functions that expose prompt templates to MCP clients. | ||
| * Clients discover prompts via prompts/list and invoke them via prompts/get. | ||
| * | ||
| * Return a plain string (auto-wrapped into a single user message by the host) | ||
| * or a JSON-serialized GetPromptResult for multi-message / rich content responses. | ||
| */ | ||
| public class PromptExamples { | ||
|
|
||
| /** | ||
| * A code review prompt with multiple arguments (1 required, 1 optional). | ||
| * Uses McpPromptArgument annotations to define arguments in a strongly-typed way. | ||
| */ | ||
| @FunctionName("CodeReviewPrompt") | ||
| public String codeReviewPrompt( | ||
| @McpPromptTrigger( | ||
| name = "code_review", | ||
| description = "Generates a code review prompt for the given code snippet", | ||
| title = "Code Review") | ||
| String context, | ||
| @McpPromptArgument( | ||
| name = "code", | ||
| description = "The code to review", | ||
| isRequired = true) | ||
| String code, | ||
| @McpPromptArgument( | ||
| name = "language", | ||
| description = "The programming language") | ||
| String language, | ||
| final ExecutionContext executionContext) { | ||
|
|
||
| executionContext.getLogger().info("Generating code review prompt"); | ||
|
|
||
| String lang = (language != null && !language.isEmpty()) ? language : "unknown"; | ||
| String snippet = (code != null && !code.isEmpty()) ? code : "// no code provided"; | ||
|
|
||
| return "Please review the following " + lang + " code and suggest improvements:\n\n```" | ||
| + lang + "\n" + snippet + "\n```"; | ||
| } | ||
|
|
||
| /** | ||
| * A summarize prompt with a single required argument and plain string return. | ||
| * The host auto-wraps the returned string into a PromptMessage with role "user". | ||
| */ | ||
| @FunctionName("SummarizePrompt") | ||
| public String summarizePrompt( | ||
| @McpPromptTrigger( | ||
| name = "summarize", | ||
| description = "Summarizes the provided text", | ||
| title = "Summarize Text") | ||
| String context, | ||
| @McpPromptArgument( | ||
| name = "text", | ||
| description = "The text to summarize", | ||
| isRequired = true) | ||
| String text, | ||
| final ExecutionContext executionContext) { | ||
|
|
||
| executionContext.getLogger().info("Generating summarize prompt"); | ||
|
|
||
| String input = (text != null && !text.isEmpty()) ? text : "No text provided"; | ||
| return "Please provide a concise summary of the following text:\n\n" + input; | ||
| } | ||
|
|
||
| /** | ||
| * A prompt with no arguments. Tests the edge case of a prompt | ||
| * that takes no user input. | ||
| */ | ||
| @FunctionName("NoArgsPrompt") | ||
| public String noArgsPrompt( | ||
| @McpPromptTrigger( | ||
| name = "no_args_prompt", | ||
| description = "A prompt that requires no arguments", | ||
| title = "No Arguments Prompt") | ||
| String context, | ||
| final ExecutionContext executionContext) { | ||
|
|
||
| executionContext.getLogger().info("Generating no-args prompt"); | ||
| return "This prompt requires no arguments. Please provide general guidance."; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,159 @@ | ||||||||||
| package com.function; | ||||||||||
|
|
||||||||||
| import com.microsoft.azure.functions.ExecutionContext; | ||||||||||
| import com.microsoft.azure.functions.annotation.FunctionName; | ||||||||||
| import com.microsoft.azure.functions.annotation.McpToolProperty; | ||||||||||
| import com.microsoft.azure.functions.annotation.McpToolTrigger; | ||||||||||
| import com.microsoft.azure.functions.mcp.McpContent; | ||||||||||
| import com.microsoft.azure.functions.mcp.McpToolResult; | ||||||||||
|
||||||||||
| import com.microsoft.azure.functions.mcp.McpToolResult; |
Copilot
AI
Apr 21, 2026
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.
The class-level Javadoc refers to "ImageContentBlock" and "ContentBlock", but the actual return types used here are ImageContent and List<Content>. Updating the wording to match the concrete types will prevent confusion for readers trying to follow the examples.
| * <li>{@link #renderImage} — Single content block (ImageContentBlock)</li> | |
| * <li>{@link #getMultiContent} — Multiple content blocks (List of ContentBlock)</li> | |
| * <li>{@link #renderImage} — Single content block ({@code ImageContent})</li> | |
| * <li>{@link #getMultiContent} — Multiple content blocks ({@code List<Content>})</li> |
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.
FUNCTIONS_EXTENSIONBUNDLE_SOURCE_URIis set to the staging CDN. Committing this in the sample can cause local runs to fetch potentially unstable bundles and can break for users if the staging endpoint changes. Prefer omitting this setting or pointing to the production CDN, and if staging is required for a specific feature, document that requirement explicitly in the sample docs.