Module sampling

Module sampling 

Source
Expand description

MCP-Compliant Client-Side Sampling Support

This module provides the correct MCP architecture for handling sampling requests. The client’s role is to:

  1. Receive sampling/createMessage requests from servers
  2. Present them to users for approval (human-in-the-loop)
  3. Delegate to external LLM services (which can be MCP servers themselves)
  4. Return standardized results

§Perfect MCP Compliance

Unlike embedding LLM APIs directly (anti-pattern), this implementation:

  • Delegates to external services
  • Maintains protocol boundaries
  • Enables composition and flexibility
  • Provides maximum developer experience through simplicity

Structs§

AutoApprovingUserHandler
Default user handler that automatically approves (for development)
DelegatingSamplingHandler
Default implementation that delegates to external MCP servers
ServerInfo
Server information for model selection

Traits§

LLMServerClient
Interface for connecting to LLM MCP servers
SamplingHandler
MCP-compliant sampling handler trait
UserInteractionHandler
Interface for user interaction (human-in-the-loop)