Expand description
Sampling API for server-initiated LLM requests.
This module allows MCP servers to request LLM completions from clients that support the sampling capability. This enables agentic workflows where the server can leverage the client’s LLM for complex tasks.
§Example
ⓘ
use mcp_kit::server::sampling::{SamplingRequest, SamplingClient};
async fn agentic_tool(client: impl SamplingClient) -> Result<String, Error> {
let request = SamplingRequest::new()
.add_user_message("Analyze this data and suggest improvements")
.max_tokens(1000);
let response = client.create_message(request).await?;
Ok(response.content.text().unwrap_or_default())
}Structs§
- Channel
Sampling Client - Channel-based sampling client implementation.
- NoOp
Sampling Client - No-op sampling client for when client doesn’t support sampling.
- Sampling
Request Builder - Builder for creating sampling requests.
Traits§
- Sampling
Client - A client for making sampling requests to the MCP client.