Sampling
Sampling allows MCP tools to request LLM completions during their execution.
Configuration
To enable sampling, provide asampling_callback function when initializing the MCPClient:
Enable LLM sampling capabilities for MCP tools
sampling_callback function when initializing the MCPClient:
// ⚠️ Sampling callbacks are not yet supported in the TypeScript library.
// Support is coming soon! If you need this feature now, please open an issue:
// https://github.com/mcp-use/mcp-use
// When supported, the API will look similar to:
/*
import { MCPClient } from 'mcp-use'
async function samplingCallback(context, params) {
// Integrate with your LLM of choice
const response = await yourLlm.complete(params.messages.at(-1).content.text)
return {
content: { text: response, type: 'text' },
model: 'your-model-name',
role: 'assistant'
}
}
const client = new MCPClient(
config,
{ samplingCallback }
)
*/
// ⚠️ Not yet supported - see above for details
// When supported, similar error handling will apply
Was this page helpful?