-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathPromptExamples.java
More file actions
88 lines (77 loc) · 3.47 KB
/
PromptExamples.java
File metadata and controls
88 lines (77 loc) · 3.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
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.";
}
}