Package com.tnsai.mcp.server
Interface PromptProvider
public interface PromptProvider
Interface for providing prompts to an MCP server.
Implement this interface to expose prompt templates to MCP clients.
Prompts can have arguments that are filled in when the prompt is requested.
Providers may also support auto-completion of argument values via
getCompletions(String, String, String).
Example implementation:
public class MyPromptProvider implements PromptProvider {
@Override
public List<Prompt> listPrompts() {
Prompt prompt = new Prompt();
prompt.setName("code_review");
prompt.setDescription("Reviews code for issues");
prompt.setArguments(List.of(
new Prompt.PromptArgument() {{
setName("code");
setDescription("The code to review");
setRequired(true);
}}
));
return List.of(prompt);
}
@Override
public PromptResult getPrompt(String name, Map<String, String> arguments) {
if ("code_review".equals(name)) {
String code = arguments.get("code");
return PromptResult.messages(List.of(
PromptMessage.user("Please review this code:\n" + code)
));
}
return PromptResult.error("Unknown prompt: " + name);
}
}
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic classA message in a prompt result.static classResult of a prompt request. -
Method Summary
Modifier and TypeMethodDescriptiongetCompletions(String promptName, String argumentName, String value) Returns auto-completion suggestions for a prompt argument.Gets a prompt with the given arguments filled in.Returns the list of prompts provided by this provider.
-
Method Details
-
listPrompts
Returns the list of prompts provided by this provider.- Returns:
- list of prompt definitions
-
getPrompt
Gets a prompt with the given arguments filled in.- Parameters:
name- the prompt namearguments- the prompt arguments- Returns:
- the prompt result containing messages
-
getCompletions
Returns auto-completion suggestions for a prompt argument. Used by the completion/complete protocol method.- Parameters:
promptName- the prompt nameargumentName- the argument name to completevalue- the partial value to complete- Returns:
- list of completion suggestions (empty by default)
-