sequenceDiagram
participant Server
participant Client as Client/Host
actor User
participant LLM
Note over Server,Client: Initial request with tools
Server->>Client: sampling/createMessage<br/>(messages + tools)
Note over Client,User: Human-in-the-loop review
Client->>User: Present request for approval
User-->>Client: Approve/modify
Note over Client: Convert MCP messages and tool descriptions<br/>to LLM messages and tool descriptions
Client->>LLM: Send request with tools to LLM
LLM-->>Client: Response with tool_use<br/>(stopReason: "toolUse")
Client->>User: Present tool calls for review
User-->>Client: Approve tool calls
Note over Client: Convert LLM tool calls to MCP tool_use content blocks
Client-->>Server: Return tool_use response
Note over Server: Execute tool(s)
Server->>Server: Run get_weather("Paris")<br/>Run get_weather("London")
Note over Server,Client: Issue new sampling request with tool results
Server->>Client: sampling/createMessage<br/>(history + tool_results + tools)
Client->>User: Present continuation
User-->>Client: Approve
Note over Client: Convert MCP messages and tool results<br/>to LLM messages and tool results
Client->>LLM: Forward with tool results
LLM-->>Client: Final text response<br/>(stopReason: "endTurn")
Client->>User: Present response
User-->>Client: Approve
Note over Client: Convert LLM response to MCP content blocks
Client-->>Server: Return final response
Note over Server: Server processes result<br/>(may continue conversation...)
Last active
January 4, 2026 16:33
-
-
Save mikekistler/a636e41aef52f672465ce03415e77d0c to your computer and use it in GitHub Desktop.
Sampling with Tools
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment