Skip to main content

Sampling & Roots — Advanced Features

← Back to Dashboard
1. Sampling & Roots2. Async Tasks (2025)3. Elicitation & HITL4. Structured Content & Tool Annotations5. Completions & Metadata

Sampling & Roots

📚 Advanced Features⏱ 10 min⭐ 100 XP⌨ Hands-on lab

Reversing the Flow (Sampling)

Normally, the Client asks the Server for data. Sampling (sampling/createMessage) reverses this: the Server asks the Client's LLM to generate text or invoke nested tools (tools and toolChoice added in 2025-11-25) on its behalf!

This enables agentic sub-workflows without servers holding their own LLM API keys. Because requesting LLM completions implies cost and untrusted prompt exposure, MCP mandates Human-in-the-Loop (HITL) approval via the Client UI.

Establishing Roots & Spec 2026-07-28 Lifecycle (SEP-2577)

Roots (roots/list) define the operational filesystem or URI boundaries of an MCP Server. Lifecycle Note: In the 2026-07-28 specification (SEP-2577), Roots, Sampling, and Logging entered a formal 12-month deprecation window so the core protocol remains stateless—new servers should accept allowed paths via explicit tool parameters/resource URIs, call LLM APIs directly when feasible, and emit telemetry via stderr or OpenTelemetry (while stateless Multi Round-Trip Requests / MRTR handle remaining interactive client round-trips).

// Legacy/Transitional Server: Requesting declared client roots (never log to stdout!)
const rootList = await server.server.listRoots();
console.error("Authorized roots:", rootList.roots); // e.g. [{ uri: "file:///usr/src/app" }]
💡 Key Insight: When Roots are active, the server strictly confines file operations to those URIs, and the Host UI lets users add or revoke workspace folders dynamically.
⌨ HANDS-ON LABAudit Client Filesystem Roots
⭐ +150 XP

Query the client's declared root directories to enforce filesystem sandboxing boundaries.

1Send roots/list method over stdio.
lab-sandbox — simulated environment
INFINITY LAB SANDBOX v2.6 — simulated shell
Type the command for the current objective. Helpers: "hint", "solution", "clear".
$
OBJECTIVE 1 / 1 — type "hint" if stuck
🧪 Knowledge Check
Press 1-4 to select1 of 3
What does MCP 'Sampling' refer to?
Measuring server RAM usage.
The Server asking the connected Client's LLM to generate completions.
Downloading subsets of databases.
Audio processing algorithms.