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);
     }
 }
 
  • Method Details

    • listPrompts

      List<Prompt> listPrompts()
      Returns the list of prompts provided by this provider.
      Returns:
      list of prompt definitions
    • getPrompt

      PromptProvider.PromptResult getPrompt(String name, Map<String,String> arguments)
      Gets a prompt with the given arguments filled in.
      Parameters:
      name - the prompt name
      arguments - the prompt arguments
      Returns:
      the prompt result containing messages
    • getCompletions

      default List<String> getCompletions(String promptName, String argumentName, String value)
      Returns auto-completion suggestions for a prompt argument. Used by the completion/complete protocol method.
      Parameters:
      promptName - the prompt name
      argumentName - the argument name to complete
      value - the partial value to complete
      Returns:
      list of completion suggestions (empty by default)