Skip to content

MCP Sampling

Deprecation Notice

Sampling feature has been deprecated in the MCP spec 2026-07-28.

You are advised NOT to adopt this for new projects.

Sampling lets an MCP server ask the AI model used by the client a question or work out details toward any particular goal.

Example scenario

Imagine an insurance company is using an AI agent. They want to know if a certain car insurance claim needs deeper analysis. The AI agent connects to an MCP server that has access to company's claims.

The server retrieves customer's current and previous claims, accident details, repair estimate and policy information. However, the server cannot do any reasoning by itself.

This is when the server sends a Sampling request to the client asking for a claim investigation.

Apart from sending sampling request and receiving sampling response at the server end, the client needs to define a sampling handler. There may be just one sampling handler for the entire MCP client, so any branching or routing logic has to be worked out internally between the MCP server (sampling requester) and the client sampling handler.

Code example

(ns hello-mcp-clj.client.sampling
  (:require
   [plumcp.core.api.capability :as cap]
   [plumcp.core.api.entity-gen :as eg]
   [plumcp.core.api.mcp-runtime :as mr]
   [plumcp.core.schema.json-rpc :as jr]
   [plumcp.core.schema.schema-defs :as sd]))


(defn ^{:mcp-type :sampling
        :mcp-name "sampling-handler"} sampling-handler
  "Respond to sampling request from server"
  [{:as kwargs}]
  (let [;; fetch data, do computation etc
        model-name "..."
        message-text "..."]
    ;; any further
    (->> (eg/make-text-content message-text)
         (eg/make-create-message-result model-name sd/role-user)
         (jr/jsonrpc-success (mr/get-request-id kwargs)))))


(defn make-sampling-handler
  "Manual equivalent of creating a sampling handler as in the function
   `sampling-handler` above. There may be only one samplng handler per
   MCP client."
  []
  (cap/make-sampling-handler sampling-handler))

Sampling is supported at both var annotation level (var discovery) and manual definition as we note above.