← 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 reverses this: the Server can ask the Client's LLM to generate text or structure data on its behalf!

This allows self-contained agentic workflows inside your MCP server. Because requesting LLM completions implies cost, MCP mandates Human-in-the-Loop (HITL) approval via the Client UI.

Establishing Roots (Deprecated in MCP 1.5)

Roots define the operational boundaries of an MCP Server within a filesystem or structure. Note: As of MCP 1.5, Roots, Sampling, and Logging are deprecated from the core protocol to enable a Stateless Core. They are now handled directly by the Host application.

// On Server: Requesting current boundaries
const rootList = await server.requestRoots();
console.log(rootList.roots); // e.g. [{ uri: "file:///usr/src/app" }]
💡 Key Insight: The server reads these Roots and strictly respects them. The Host UI allows the user to dynamically add or remove folders from the Root list to manage security 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.