-
Notifications
You must be signed in to change notification settings - Fork 9.2k
feat(everything): add trigger-agentic-sampling tool #3163
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
feat(everything): add trigger-agentic-sampling tool #3163
Conversation
Adds a new tool that demonstrates sampling with tools capability (MCP 2025-11-25). The tool sends prompts to the LLM with tools available, handles tool_use responses in an agentic loop, and executes tools locally until a final response is received. 🦉 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <[email protected]>
Update features.md and structure.md to document the new trigger-agentic-sampling tool. Also adds missing documentation for trigger-elicitation-request. 🦉 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <[email protected]>
domdomegg
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice!
cliffhall
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can't test with the Inspector yet (saw your mention of an issue with the SDK on that), but review did turn up a few minor things.
| if (!clientSupportsSamplingWithTools) { | ||
| console.log( | ||
| "[trigger-agentic-sampling] Not registering - client does not support sampling.tools" | ||
| ); | ||
| return; | ||
| } | ||
|
|
||
| console.log("[trigger-agentic-sampling] Registering - client supports sampling.tools"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should not use console.log in tools. When running via STDIO, all output STDOUT must be constrained to JSON-RPC messages.
For this instance of it, I would suggest following the same pattern as the other conditionally registered tools, which is to simply make the server.registerTool call conditioned upon clientSupportsSamplingWithTools being true. The others don't log the fact that they weren't registered.
| // Agentic loop | ||
| while (iteration < maxIterations) { | ||
| iteration++; | ||
| console.log(`[trigger-agentic-sampling] Iteration ${iteration}/${maxIterations}`); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
More console.log that should be omitted or otherwise done with console.error
| // Send the sampling request to the client | ||
| const result = await extra.sendRequest(request, CreateMessageResultWithToolsSchema); | ||
|
|
||
| console.log(`[trigger-agentic-sampling] Got response with stopReason: ${result.stopReason}`); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
console.log that should be omitted or otherwise done with console.error
| ); | ||
|
|
||
| if (toolUseBlocks.length === 0) { | ||
| console.log( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
console.log that should be omitted or otherwise done with console.error
| // Execute each tool and collect results | ||
| const toolResults: ToolResultContent[] = []; | ||
| for (const toolUse of toolUseBlocks) { | ||
| console.log( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
console.log that should be omitted or otherwise done with console.error
| textBlock?.type === "text" | ||
| ? (textBlock as TextContent).text | ||
| : JSON.stringify(result.content); | ||
| console.log( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
console.log that should be omitted or otherwise done with console.error
Description
Adds support for SEP-1577 (Sampling With Tools) to the Everything server by introducing a new
trigger-agentic-samplingtool that demonstrates the agentic sampling loop pattern.This tool:
tool_useresponses and executes tools locallysampling.toolscapabilityServer Details
Motivation and Context
Issue: #3040
SEP-1577 adds tool calling support to the MCP sampling API, enabling servers to provide tools that the LLM can use during sampling requests. This creates an "agentic loop" where:
sampling/createMessagewith atoolsarraystopReason: "toolUse", the server executes the toolsThe Everything server is a reference implementation that demonstrates all MCP features, so it should include this capability.
How Has This Been Tested?
sampling.toolscapability checktrigger-sampling-request,trigger-elicitation-request)(We can wait to merge until I've had a chance to add a screengrab if that's preferred.)
Breaking Changes
No
Types of changes
Checklist
Additional context
References
Implementation Notes
The tool includes simple local implementations of
echoandaddtools for demonstration purposes. In a production scenario, tools could likely be reused via:server.server.callTool()callsI thought about trying to re-use existing tools already defined in the everything server, but then decided to keep it self-contained instead.