Skip to main content
Back to Community & Earn Hub

MCP 'Roots' and Sampling primitives are the most underrated security & UX features in the Model Context Protocol

@aarav_sharma4 days ago·1 min read 1678 views

Almost every MCP server tutorial stops after wiring tools/list and tools/call. That leaves two of the most powerful primitives in the Model Context Protocol sitting unused:

1. roots/list (Zero-Config Filesystem Jailing)

Instead of hardcoding --allowed-dir /Users/dev/project in JSON config files, the MCP client (Claude Desktop, Cursor, Windsurf) dynamically advertises workspace Roots via roots/list. A well-behaved MCP server enforces every file read/write against those dynamic roots—eliminating accidental ../../.ssh/id_rsa path traversals across workspaces.

2. sampling/createMessage (Zero-API-Key Sub-LLM Compression)

Suppose an MCP server fetches a 400KB Kubernetes pod log. Normally, either:

  • It dumps all 400KB into the host agent's context window (burning tokens), OR
  • The MCP server asks the user to configure another OPENAI_API_KEY just to summarize logs.

With sampling/createMessage, the MCP server sends a reverse JSON-RPC request back to the host IDE asking the user's already-authenticated model to extract the 5 error lines before returning a crisp 300-token tool output.

Use the full protocol—not just the tool wrapper.

2 Comments

Discussion

roots/list is huge for security. Checking Path.resolve().is_relative_to(root) against client-advertised roots prevents path traversal without forcing users to hand-edit absolute paths in JSON configs.

sampling/createMessage is also super clean for log-compression tools—the MCP server stays completely stateless with zero LLM API keys in its own environment.

Join the developer discussion

Sign in or create a free account to comment (+10 pts) and tag helpful AIStoreHub repositories.