Skip to content

Conversation

@LucaButBoring
Copy link
Contributor

@LucaButBoring LucaButBoring commented May 12, 2025

This change rewrites the sampling documentation to explain how sampling works in terms of tool calls and demonstrate how to actually implement sampling workflows via the SDK, rather than simply explaining the message format (which the specification is already capable of addressing). Most of the existing information has been reorganized into reference-level material. I also added a mention of the supported audio message type, which wasn't documented before.

This is related to #503. The intent of this change is to document the existing behavior of sampling prior to proposing any specification changes.

I suggest reading this in split diff view rather than the unified view 😔

Motivation and Context

In contrast to the current tools documentation, the sampling documentation is currently structured like an API reference, and has little to no information on how to actually leverage sampling for useful tasks. This PR rewrites the documentation to better convey sampling to developers unfamiliar with the protocol.

How Has This Been Tested?

Documentation tested with npm run serve:docs. The main implementation sample has been manually tested.

Breaking Changes

N/A

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update

Checklist

  • I have read the MCP Documentation
  • My code follows the repository's style guidelines
  • New and existing tests pass locally
  • I have added appropriate error handling
  • I have added or updated documentation as needed

Additional context

I tried to cut down the error-handling/limitations/best-practices/security sections to consolidate them and limit them to specific and non-generic statements, but I'm not convinced they're well-written even after these revisions. Open to suggestions on how to handle these.

Comment on lines 57 to 83
const result = await extra.sendRequest(
{
method: "sampling/createMessage",
params: {
messages: [
{
role: "user",
content: {
type: "text",
text: `Add ${a} and ${b}. Respond with only the sum of the two numbers.`,
},
},
],
maxTokens: 1000,
systemPrompt: "You are very good at math.",
includeContext: "thisServer",
},
},
CreateMessageResultSchema
);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Out of scope for this PR, but we really need a friendlier API. 😆

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, honestly even the name of the feature ("sampling") doesn't really convey what this is used for, let alone the API itself 😔

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed! If we could unify sampling and elicitation, I would propose the term "solicitation".

Quoth Gemini 2.5 Pro on "elicit" vs "solicit":

  • To solicit a response is to request it.
  • To elicit a response is to get it (often without a direct request for that specific response).

In essence, "solicit" is about the asking, while "elicit" is about the succeeding in drawing something out.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have to disagree that using two very similar sounding words instead will clarify things. :)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Haha, well the idea is that if we could unify sampling and elicitation into a single mechanism, then we could call that "solicitation". In other words, no "elicitation" (nor "sampling"), just "solicitation".

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jonathanhefner thanks, I totally misread the comment.

3. Client samples from an LLM
4. Client reviews the completion
5. Client returns the result to the server
Sampling enables agentic patterns such as:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From other discussions it seems like this was partly intended to allow a host/client to 'Bring Your Own LLM' if it supports this capability, taking the responsibility away from the Server. This can be useful for simple use cases as well as complex ones.

If I'm a developer reading this guide for the first time, emphasizing complexity right off the bat makes me feel like I'm good to keep ignoring Sampling if I'm not doing anything I consider complex or agentic. Since at the most basic level Sampling is just asking the host to provide a completion from an LLM, should this overview start with a simpler use case of 'my server needs a model' rather than emphasizing 'agentic patterns?'

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that's a good idea, I'll rewrite this section.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rewrote this section to align more with that framing - the new overview also touches on the explanation from @jerome3o-anthropic here.

@LucaButBoring LucaButBoring changed the title docs(sampling): rewrite sampling docs for practical usage docs(sampling): rewrite sampling docs for MCP server builders Jun 10, 2025
LucaButBoring and others added 3 commits August 13, 2025 11:49
This change rewrites the sampling documentation to explain how sampling in terms of
tool calls and demonstrate how to actually implement sampling workflows via the SDK.
Most of the existing information has been reorganized into reference-level material.

The intent of this change is to document the existing behavior of sampling prior to proposing any specification changes.
Co-authored-by: Jonathan Hefner <jonathan@hefner.pro>
@dsp-ant dsp-ant requested review from a team as code owners November 24, 2025 20:59
@dsp-ant
Copy link
Member

dsp-ant commented Nov 24, 2025

Given we haven't moved this forward in months, can we close it? I know it's a lot of hard work not making it and I am sorry for that.

I think adding more here is still valuable but likely as a tutorial or guide or so. @jonathanhefner maybe can take a look.

@dsp-ant dsp-ant closed this Nov 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants