Skip to content

MCP Completion

A completion is meant to bring interactive experience to the user. The user enters a part of prompt argument or resource template argument, and the server offers autocompletion suggestions.

For example, a restaurant booking assistant may ask the user to enter the cuisine name. If the user enters ind, the MCP completion may respond with:

  • Indian
  • Indonesian
  • North Indian
  • South Indian

Code example

(ns hello-mcp-clj.completion
  (:require
   [clojure.string :as str]
   [plumcp.core.api.capability :as cap]
   [plumcp.core.api.entity-gen :as eg]))


(def cuisines
  (->> ["Indian"
        "North Indian"
        "South Indian"
        "Indonesian"
        "Italian"
        "Japanese"
        "Mexican"
        "Thai"]
       (mapv (fn [cuisine]
               [(str/lower-case cuisine) cuisine]))))


(def cuisine-completion
  "Cuisine completion implemented using naive sequential search for demo
   and learning purpose."
  (cap/make-completions-reference-item
   (eg/make-prompt-reference "cuisine-search")
   (fn [{:keys [ref cuisine]}]
     (let [user-cuisine (str/lower-case cuisine)
           matches (->> cuisines
                        (filterv (fn [[lower-cuisine _]]
                                   (str/includes? lower-cuisine
                                                  user-cuisine)))
                        (mapv second))]
       (eg/make-complete-result matches)))))

Other arguments may be autocompleted in a similar manner. For resource template argument reference, you need to use

(eg/make-resource-template-reference "res://template-name")