AI & MCP
Sampling in MCP: when the server asks for a generation
Sampling lets an MCP server ask the client to run a completion with the user's model. Here is the flow, and why a catalogue refuses it.
Key points
- Sampling is a server-to-client request: the server proposes messages, the client generates with the user's model.
- It needs the sampling capability declared by the client; without it the request has no useful answer.
- The EneUI server implements no sampling: sampling/createMessage returns -32601 method not found.
In MCP sampling is the primitive a server uses to ask the client for a completion with the user's model. The server sends sampling/createMessage with the messages; the client decides whether to generate, with which model, and what to show.
Who decides what
The server never sees the model: it proposes a list of messages and a token ceiling. The client checks the capability declared in the session, applies the user's consent, and returns the text or an error.
- Capability: the client announces
samplingininitialize; without it a server should not ask for anything. - Preferences:
modelPreferencesare hints about cost, speed and intelligence, not a constraint. - Consent: the client can show the messages, edit them, or refuse the completion.
Why the direction matters
A tool travels from the client to the server; sampling travels the other way, on the same session. The server must be able to send a request while the client stays listening: natural on stdio, and on Streamable HTTP it needs an open channel.
curl -s https://ui.eneawork.it/mcp \
-H "Content-Type: application/json" \
-d '{"jsonrpc":"2.0","id":1,"method":"sampling/createMessage","params":{"messages":[]}}'
The answer is {"code":-32601,"message":"method not found: sampling/createMessage"}. That is not a network fault: the method is absent from the dispatcher and the capability is undeclared, so a correct client should never try.
The client pays for it
Every completion spends the user's credit, not the server's. For a component catalogue that buys nothing: the tools already return records, URLs and ready-made commands with no model involved.
The risk sampling adds
The server writes the messages that reach the user's model. A hostile server can use that path to inject instructions or burn tokens; that is why the specification leaves consent and model choice to the client.
The EneUI catalogue
The server exposes read-only tables and dashboards; a sample record is 21st-shadcn data table, MIT licence and 114 stars declared upstream, read on 1 November 2026. Client configuration is at /agents.
The limitation
EneUI implements neither sampling nor its declaration: the initialize response lists tools only. A client calling the method gets -32601, and the protocol does not require sampling for compliance.
Where to continue
The protocol overview is in what MCP is; a tool schema is in designing an MCP tool; the hand-written dispatcher is in how to build an MCP server. The comparison with REST APIs is in MCP vs REST.
Frequently asked questions
Is sampling mandatory in MCP?
No. It is an optional capability: a server may not declare it and a client may not support it. The EneUI server declares neither the capability nor the method.
Who pays for the tokens spent by sampling?
The client's user. The server holds no key of its own: the completion runs on the client's model and credit, and the client can refuse.
Does sampling let a server read the conversation?
No, not the whole conversation. It gets back only the messages it sent and the completion the client returns, never the rest of the dialogue.
Are sampling and tools the same thing?
No. A tool is a server function the model calls; sampling is a completion the server requests from the client's model.
What does EneUI answer for sampling/createMessage?
-32601, method not found. The endpoint declares the tools capability only, so the method does not exist in its dispatcher.