Skip to content

Conversation

@olaservo
Copy link
Member

Description

Adds support for SEP-1577 (Sampling With Tools) to the Everything server by introducing a new trigger-agentic-sampling tool that demonstrates the agentic sampling loop pattern.

This tool:

  • Sends a prompt to the client's LLM with tools available
  • Handles tool_use responses and executes tools locally
  • Loops until a final text response is received or max iterations reached
  • Only registers if the client supports sampling.tools capability

Server Details

  • Server: everything
  • Changes to: tools

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:

  1. Server sends sampling/createMessage with a tools array
  2. If the LLM returns stopReason: "toolUse", the server executes the tools
  3. Server sends tool results back and continues until final response

The Everything server is a reference implementation that demonstrates all MCP features, so it should include this capability.

How Has This Been Tested?

(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

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update

Checklist

  • I have read the MCP Protocol Documentation
  • My changes follows MCP security best practices
  • I have updated the server's README accordingly
  • I have tested this with an LLM client
  • My code follows the repository's style guidelines
  • New and existing tests pass locally
  • I have added appropriate error handling
  • I have documented all environment variables and configuration options

Additional context

References

Implementation Notes

The tool includes simple local implementations of echo and add tools for demonstration purposes. In a production scenario, tools could likely be reused via:

  • Internal server.server.callTool() calls
  • Connecting to other MCP servers as a client
  • Shared business logic functions

I thought about trying to re-use existing tools already defined in the everything server, but then decided to keep it self-contained instead.

olaservo and others added 2 commits December 28, 2025 21:29
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]>
Copy link
Member

@domdomegg domdomegg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

Copy link
Member

@cliffhall cliffhall left a 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.

Comment on lines +153 to +160
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");
Copy link
Member

@cliffhall cliffhall Jan 5, 2026

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}`);
Copy link
Member

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}`);
Copy link
Member

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(
Copy link
Member

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(
Copy link
Member

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(
Copy link
Member

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants