Sub topic 12
What clients offer servers: sampling, roots, and elicitation
This chapter assumes you know the host, client, and server roles, the JSON-RPC message format, and the initialization handshake. Most MCP traffic flows from client to server: the client lists tools and calls them. Three features run the other way. The server sends a request, and the client answers it. These are sampling, roots, and elicitation.
Why the direction matters
A server has no model, no file system view, and no user interface of its own. It lives behind the client. When it needs one of those things, it asks the client, and the host stays in control of each answer.
| Feature | The server asks the client to... | Method |
|---|---|---|
| Sampling | run an LLM completion | `sampling/createMessage` |
| Roots | tell it which locations it may work in | `roots/list` |
| Elicitation | ask the user for missing input | `elicitation/create` |
A server may only use a feature if the client declared it during initialization. The initialize example earlier declared "sampling": {} under capabilities. A client that supports all three declares them like this:
{"jsonrpc": "2.0", "id": 1, "method": "initialize", "params": {"protocolVersion": "2025-06-18", "capabilities": {"sampling": {}, "roots": {"listChanged": true}, "elicitation": {}}, "clientInfo": {"name": "example-client", "version": "1.0.0"}}}Sampling
Sampling lets a server get a model completion without holding its own API key. The server sends messages and preferences. The client forwards them to the host's model and returns the reply.
{"jsonrpc": "2.0", "id": 7, "method": "sampling/createMessage", "params": {"messages": [{"role": "user", "content": {"type": "text", "text": "Summarize this file in one sentence."}}], "maxTokens": 100}}The client replies with the generated message, the model name, and a stop reason. The server does not choose the model. It can only express preferences, such as cost or speed, and the client decides. The specification also expects the user to be able to review the request and the response before they are used.
Roots
A root is a URI, usually a file:// path, that marks a location the client is willing to expose. The server calls roots/list to find out where it should operate.
{"jsonrpc": "2.0", "id": 8, "result": {"roots": [{"uri": "file:///home/user/project", "name": "My Project"}]}}If the client declared listChanged: true, it sends a notifications/roots/list_changed notification when the list changes, and the server asks again. Roots are guidance about scope. They are not a sandbox, so a server that ignores them is not stopped by the protocol itself.
Elicitation
Elicitation lets a server pause and ask the user a question, for example which of two accounts to use. The request carries a message and a flat JSON schema describing the fields wanted.
{"jsonrpc": "2.0", "id": 9, "method": "elicitation/create", "params": {"message": "Which environment should I deploy to?", "requestedSchema": {"type": "object", "properties": {"environment": {"type": "string", "enum": ["staging", "production"]}}, "required": ["environment"]}}}The reply has an action of accept, decline, or cancel. Only accept includes content. The schema allows only simple fields (strings, numbers, booleans, enums), and servers must not use elicitation to request sensitive data such as passwords.
Common errors
- Calling a feature the client never declared. Check the negotiated capabilities first.
- Treating roots as access control. Enforce limits in the server and the operating system.
- Assuming the user always answers. Handle
declineandcancel. - Expecting a specific model from sampling. Write prompts that work with any model.
Exercise
A server wants to ask the user to confirm a deployment target halfway through a tool call. Which feature does it use, which method does it send, and what must be true of the client?
Show answer
It uses elicitation and sends elicitation/create. The client must have declared the elicitation capability during initialization. The server must handle decline and cancel replies as well as accept.