Skip to content

MCP Prompts (Server)

Prompts are parameterized message templates meant to construct LLM prompts at the MCP-Client end. MCP clients lookup prompts from the MCP server and with user-consent, pass parameters and end up with the complete prompt to be sent to the LLM.

Why Prompts?

Imagine, you have an "AI assistant" app that responds to user input. You are not going to send the user input directly as a prompt to the LLM - you would rather extract the intent and other contextual metadata from the user input, then structure a prompt (based on a template) as per your use cases in order to fetch a response.

Prompts are useful to model such templates. You can create an entire library of prompts for various use cases in your MCP Server.

Here is a simple Chain of Verification (CoVe) prompt example.

(ns hello-mcp-clj.prompt
  (:require
   [plumcp.core.api.entity-gen :as eg]
   [plumcp.core.schema.schema-defs :as sd]))


(def cove-steps
  "Step 1. Provide your initial answer
Step 2. Generate 3 to 5 sub-questions that would test the main answer's facts
Step 3. Provide answers to each of those verification questions on their own
Step 4. Provide a revised answer to the original question based on those checks
")


;; Ref: https://arxiv.org/abs/2309.11495
;; YTV: https://www.youtube.com/watch?v=MKU-Aeg_lBk
(defn ^{:mcp-name "chain_of_verification"
        :mcp-type :prompt} cove
  "Generate a Chain of Verification (CoVe) prompt for a given query."
  [{:keys [^{:doc "User query"
             :type "string"} query]}]
  (eg/make-get-prompt-result
   [(eg/make-prompt-message
     sd/role-user
     (eg/make-text-content
      (str query
           "\n"
           cove-steps)))]))

Client call

See Prompts (Client) for the client call.

Prompt Var definition

As you can see in the highlighted code example above, var annotations convey the prompt metadata:

  • :mcp-name (optional) The MCP prompt name - same as function name if unspecified
  • :mcp-type :prompt indicates that this is an MCP prompt
  • The function docstring acts as the prompt description
  • An MCP primitive var is always an arity-1 function. The argument is a map of specified, annotated keyword args. In the example above - query is a prompt argument with specified :doc (description) and :type (JSON type) annotations.
  • The function is called when MCP get-prompt method is invoked. The function body is supposed to return a get-prompt result, which is done above by the plumcp.core.api.entity-gen/make-get-prompt-result function.

Prompts can range from simple, rudimentary to complex, few-shot instances, depending upon the use case. Prompts are important feature of MCP servers to build capable agentic AI applications.