feat(xmcp): add ergonomic sampling helper for tool handlers - #542
Open
FiammaMuscari wants to merge 3 commits into
Open
feat(xmcp): add ergonomic sampling helper for tool handlers#542FiammaMuscari wants to merge 3 commits into
FiammaMuscari wants to merge 3 commits into
Conversation
Contributor
|
@FiammaMuscari is attempting to deploy a commit to the xmcp Team on Vercel. A member of the Team first needs to authorize it. |
Contributor
|
Thanks for the PR @FiammaMuscari Looks promising overall. Before a thorough review, could you please add:
|
Contributor
Author
|
@0xKoller hii I added an documentation and examples in Reposting examples here Minimal import { z } from "zod";
export const schema = {
topic: z.string(),
};
export default async ({ topic }, extra) => {
const result = await extra.sample({
messages: [
{
role: "user",
content: {
type: "text",
text: `Write a concise summary about ${topic}.`,
},
},
],
maxTokens: 300,
});
return {
content: [
{
type: "text",
text:
result.content.type === "text"
? result.content.text
: "The client did not return text content.",
},
],
};
};Tool-enabled sampling flow using local xmcp tools: const result = await extra.sample({
messages: [
{
role: "user",
content: {
type: "text",
text: "Research the current status and give me a short answer.",
},
},
],
tools: ["search_docs", "fetch_page"],
toolChoice: { mode: "auto" },
maxTokens: 800,
maxSteps: 6,
});Verification:
Screenshots:
|
0xKoller
suggested changes
Apr 3, 2026
0xKoller
left a comment
Contributor
There was a problem hiding this comment.
Remember to also add this to the docs website, and provide the screenshots/vid with MCPJam
0xKoller
suggested changes
Apr 6, 2026
FiammaMuscari
force-pushed
the
feat/sampling-helper
branch
from
April 8, 2026 01:49
c37d655 to
ad5078c
Compare
Contributor
Author
valebearzotti
requested changes
Apr 15, 2026
Contributor
Author
UpdateAll review feedback has been addressed.
Status
Let me know if there's anything else you'd like me to adjust! |
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.







Summary
extra.sample()for tool handlersmodelPreferencestools,toolChoice)tool_use -> tool_result -> continueloopSampleResultScope
tools: "all"excludes the current toolTool[]definitionsVerification
pnpm.cmd --filter xmcp buildextra.sample()from a tool contexttool_use -> tool_result -> continueloopCloses #541
Resolves XMCP-168