You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/concepts/sampling.mdx
+50-26Lines changed: 50 additions & 26 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,14 +5,18 @@ description: "Let your servers request completions from LLMs"
5
5
6
6
Sampling is a powerful MCP feature that allows servers to request LLM completions through the client, enabling sophisticated agentic behaviors while maintaining security and privacy.
7
7
8
+
<Info>
9
+
This feature of MCP is not yet supported in the Claude Desktop client.
10
+
</Info>
11
+
8
12
## How sampling works
9
13
10
14
The sampling flow follows these steps:
11
15
12
16
1. Server sends a `sampling/createMessage` request to the client
13
17
2. Client reviews the request and can modify it
14
18
3. Client samples from an LLM
15
-
4. Client reviews the completion
19
+
4. Client reviews the completion
16
20
5. Client returns the result to the server
17
21
18
22
This human-in-the-loop design ensures users maintain control over what the LLM sees and generates.
@@ -28,14 +32,24 @@ Sampling requests use a standardized message format:
28
32
role: "user"|"assistant",
29
33
content: {
30
34
type: "text"|"image",
35
+
31
36
// For text:
32
37
text?: string,
38
+
33
39
// For images:
34
-
data?: string, // base64 encoded
40
+
data?: string, // base64 encoded
35
41
mimeType?: string
36
42
}
37
43
}
38
44
],
45
+
modelPreferences?: {
46
+
hints?: [{
47
+
name?: string// Suggested model name/family
48
+
}],
49
+
costPriority?: number, // 0-1, importance of minimizing cost
50
+
speedPriority?: number, // 0-1, importance of low latency
51
+
intelligencePriority?: number// 0-1, importance of capabilities
52
+
},
39
53
systemPrompt?:string,
40
54
includeContext?:"none"|"thisServer"|"allServers",
41
55
temperature?:number,
@@ -51,11 +65,27 @@ Sampling requests use a standardized message format:
51
65
52
66
The `messages` array contains the conversation history to send to the LLM. Each message has:
53
67
54
-
-`role`: Either "user" or "assistant"
68
+
-`role`: Either "user" or "assistant"
55
69
-`content`: The message content, which can be:
56
70
- Text content with a `text` field
57
71
- Image content with `data` (base64) and `mimeType` fields
58
72
73
+
### Model preferences
74
+
75
+
The `modelPreferences` object allows servers to specify their model selection preferences:
76
+
77
+
-`hints`: Array of model name suggestions that clients can use to select an appropriate model:
78
+
-`name`: String that can match full or partial model names (e.g. "claude-3", "sonnet")
79
+
- Clients may map hints to equivalent models from different providers
80
+
- Multiple hints are evaluated in preference order
81
+
82
+
- Priority values (0-1 normalized):
83
+
-`costPriority`: Importance of minimizing costs
84
+
-`speedPriority`: Importance of low latency response
85
+
-`intelligencePriority`: Importance of advanced model capabilities
86
+
87
+
Clients make the final model selection based on these preferences and their available models.
88
+
59
89
### System prompt
60
90
61
91
An optional `systemPrompt` field allows servers to request a specific system prompt. The client may modify or ignore this.
@@ -85,8 +115,8 @@ The client returns a completion result:
0 commit comments