Skip to main content
Glama

Exploring MCP’s Hidden Primitives: Prompts, Resources, Sampling & Roots

Written by on .

context-handling
AI-agent
anthropic
mcp

  1. 1. Prompts: Pre-Baked Interactions
    1. 2. Resources: Rich Context as Files
      1. 3. Sampling: Client-Controlled LLM Calls
        1. 4. Roots: Scoped File Access
          1. Practical Example: Thread Summarizer Agent
            1. Final Thoughts
              1. Acknowledgements
                1. References

                  If you're using MCP just for tool-calling, you're missing out. MCP also supports prompts, resources, sampling, and roots—primitives that enable richer, more interactive developer experiences1.

                  These lesser-known features are essential for building user-friendly, scalable systems that extend beyond simple tool invocations.

                  Image

                  1. Prompts: Pre-Baked Interactions

                  Prompts are like reusable command templates. Developers can expose prompts with autocomplete and dynamic payloads to guide user interactions.

                  mcp.prompt("summarizeThread", ["threadId"]) .autocomplete(async () => listThreads()) .generate(async ({ threadId }) => { const thread = await getThread(threadId); return `Summarize this thread:\n\n${thread.content}`; });

                  This pattern mirrors slash-command UX and encourages structured input from users. The result is a better overall experience and fewer malformed requests1.

                  2. Resources: Rich Context as Files

                  Resources let the server expose structured contextual information (logs, data schemas, etc.) that clients can treat like files:

                  @mcp.resource("db://mydb/schema") def db_schema() -> str: return introspect_schema()

                  These resources are read-only, versionable, and can be embedded, inspected, or searched. They’re ideal for applications requiring complex data access or auditing1.

                  3. Sampling: Client-Controlled LLM Calls

                  Instead of relying on the MCP server to run LLMs, you can defer sampling to the client side:

                  Image

                  const summary = await context.sampling({ model: "claude-3", prompt: `Summarize this text:\n${text}`, }); return summary;

                  This allows developers to offload compute, preserve privacy, and give users more control over costs and models. It’s particularly useful in multi-tenant settings1.

                  4. Roots: Scoped File Access

                  Roots define the safe boundaries within which tools or resources can operate:

                  const roots = await context.requestRoots(); // roots might include: "file:///home/user/project"

                  With roots, file access is opt-in and explicit—perfect for environments like IDE plugins or collaborative workspaces where data leakage is a concern1.

                  Practical Example: Thread Summarizer Agent

                  Imagine a summarizer for a forum:

                  1. Prompt: /summarizeThread with thread autocomplete.
                  2. Resource: Thread messages exposed as resources.
                  3. Sampling: Let the client summarize with their preferred model.
                  4. Tool: Use postMessage to publish the result.
                  5. Roots: Limit interactions to forum export files only.

                  This setup provides security, control, and UX benefits—all through core MCP primitives1.

                  Final Thoughts

                  These primitives reflect the protocol’s design goals: secure, flexible, and extensible interactions for agents. If you're building tools atop MCP, adopting these features early helps ensure better developer ergonomics and safer workflows.

                  Acknowledgements

                  This guide is based on David Soria Parra’s2 talk at the MCP Summit – “MCP201: The Protocol in Depth”1, where he explored how these primitives enhance agent interoperability and security.

                  References

                  Footnotes

                  1. MCP Summit – "MCP201: The Protocol in Depth with David Soria Parra" 2 3 4 5 6 7

                  2. David Soria Parra – LinkedIn

                  Written by Om-Shree-0709 (@Om-Shree-0709)