feat: client-side support for SEP-1577 sampling with tools#1722
Merged
maxisbey merged 4 commits intomodelcontextprotocol:mainfrom Dec 9, 2025
Merged
Conversation
maxisbey
requested changes
Dec 9, 2025
src/mcp/client/session.py
Outdated
| write_stream: MemoryObjectSendStream[SessionMessage], | ||
| read_timeout_seconds: timedelta | None = None, | ||
| sampling_callback: SamplingFnT | None = None, | ||
| sampling_capabilities: types.SamplingCapability | None = None, |
Contributor
There was a problem hiding this comment.
thoughts on moving to the bottom of kwargs or keyword only to avoid breaking positional uses of the constructor? I'm probably leaning towards positional keyword only
Contributor
Author
There was a problem hiding this comment.
Good call! (assuming you meant leaning "keyword" only, and I agree - will update)
Contributor
There was a problem hiding this comment.
woops yea meant keyword only haha
maxisbey
approved these changes
Dec 9, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
SEP-1577 added tool calling support to sampling (via #1594). This PR adds the necessary client-side support:
toolsortoolChoiceare provided butclientCapabilities.sampling.toolsis missing. The SDK's types already support this, butClientSessionhad no way to advertise it—servers would always see the capability as missing and error. This adds asampling_capabilitiesparameter. If not provided, the previous logic applies: the presence of asampling_callbackenables basic sampling support without tools.CreateMessageResultWithTools(which supports array content). TheSamplingFnTcallback andClientResultTypedidn't include this type, so the client's response validation would reject it before it could be sent back to the server. This addsCreateMessageResultWithToolsto both.FWIW, with these changes we have full agentic sampling wired up in a branch of FastMCP, which is extremely exciting!