Implement SEP-1577: Sampling With Tools#628
Implement SEP-1577: Sampling With Tools#628DaleSeo wants to merge 2 commits intomodelcontextprotocol:mainfrom
Conversation
c2da172 to
f037e01
Compare
|
Hi @alexhancock, could you please take a look at this PR? Thanks! |
|
@DaleSeo Sorry it took me a bit. I'm glad to have support for this, but a little worried about the breaking change. Can you think of any alternatives that would keep compat, or make it a but lighter for updaters? Interested to discuss! |
95e640e to
73e60d7
Compare
|
Thanks for the feedback, @alexhancock! I've made a few updates to simplify the migration:
use std::convert::TryInto;
let content: Content = Content::text("hello");
let sampling_content: SamplingMessageContent = content.try_into()?;
// Before
SamplingMessage { role: Role::User, content: Content::text("hi") }
// After
SamplingMessage::user_text("hi")The type change is unavoidable to support tool use and result content types from SEP-1577, but I think the migration path is now reasonable. Most users can either use the new constructors or add Let me know if you have any other suggestions! |
Closes #552
Motivation and Context
This PR implements SEP-1577: Sampling With Tools, enabling MCP servers to run agentic loops using the client's LLM while maintaining user supervision.
Key additions:
ToolChoice/ToolChoiceMode- Control tool selection behaviorToolUseContent/ToolResultContent- Tool calling content typesSamplingContent<T>- Single or array content wrapperSamplingMessageContent- Unified content enum withToolUseandToolResultvariantsSamplingCapability- Structured capability withtoolsandcontextsub-capabilitiesReference implementations:
How Has This Been Tested?
Breaking Changes
The type signature of
SamplingMessage.contentchanged fromContenttoSamplingContent<SamplingMessageContent>.Migration Made Easy
Convenience constructors (recommended):
Converting existing
Contentvalues:Note:
TryFromis used becauseContent::ResourceandContent::ResourceLinkvariants are not supported in sampling messages.Wire Format Compatibility
ClientCapabilities.sampling- Empty{}JSON still deserializes toSamplingCapabilityTypes of changes
Checklist
Additional context