feat: client-side support for SEP-1577 sampling with tools #1722
+90
−3
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!