Basic usage
Parameters
Sampling requests are expressed asCreateMessageRequestParams (field names match the MCP schema, e.g. maxTokens, systemPrompt).
| Parameter | Type | Description |
|---|---|---|
messages | list[SamplingMessage] | Prompt or conversation messages |
systemPrompt | str | None | Instructions for the LLM |
temperature | float | None | Randomness/creativity |
maxTokens | int | Maximum output tokens (required) |
model | str | None | Optional model hint |
stopSequences | list[str] | None | Stop strings |
includeContext | "none" | "thisServer" | "allServers" | None | Whether the client should include additional context |
modelPreferences | ModelPreferences | None | Model selection hints (client may ignore) |
metadata | dict[str, object] | None | Opaque metadata; Dedalus will add a requestId if missing |
Response
request_sampling(...) returns a CreateMessageResult. Most clients return TextContent:
Multi-turn conversations
Pass a list of messages for multi-turn context:Example: Code review
Error handling
Sampling requires the client to advertise the sampling capability. If the client doesn’t support sampling,request_sampling(...) raises McpError (typically METHOD_NOT_FOUND):