Elixir-native helpers for MCP sampling.
This module sits one level above FastestMCP.Context.sample/3. It keeps the
low-level sampling call available, but adds a friendlier surface for:
- prompt-oriented sampling requests
- message-list sampling requests
- normalization of the returned payload into a small response struct
- preparation of runtime tools for model-facing sampling calls
Example
response =
FastestMCP.Sampling.run!(ctx, "Summarize the active session in one sentence.")
FastestMCP.Sampling.text(response)If you want the model to see local tools during sampling, prepare them first:
tools = FastestMCP.Sampling.prepare_tools(server_name)
response = FastestMCP.Sampling.run!(ctx, prompt: "Use tools if needed", tools: tools)The module is small on purpose. It does not invent a second interaction model; it just makes the existing runtime sampling path easier to call from handlers.
Summary
Functions
Normalizes server tools or sampling tools into the sampling request format.
Normalizes raw sampling output into a response struct.
Runs the main entrypoint for this module.
Runs a sampling request and raises on failure.
Extracts or requests plain text for this interaction.
Types
@type run_opts() :: keyword()
Functions
Normalizes server tools or sampling tools into the sampling request format.
Normalizes raw sampling output into a response struct.
Runs the main entrypoint for this module.
Runs a sampling request and raises on failure.
Extracts or requests plain text for this interaction.