Skip to content

MCP Sampling #1569

@Gerr1ck

Description

@Gerr1ck

Question

Hello,

According to the Model Context Protocol (MCP) specification (Sampling), the MCP Server can forward prompts to the client for execution at a large language model (LLM) through a sampling mechanism.

I am trying to implement a use case where the MCP Server performs "sampling" and requests the MCP Client to execute a prompt and return the output without involving a User-In-The-Loop.

Essentially, I want the MCP Server to trigger prompt execution independently and receive the result from the client, and that the MCP Server can trigger prompt execution whenever the server needs it.

I have some questions to clarify this setup:

  1. Is it correct that the MCP Server can independently initiate a sampling message to the MCP Client, without the MCP Client first invoking a TOOL (or something else) on the MCP Server?

  2. If this is possible, could you please provide example code or guidance demonstrating how to implement this flow where the MCP Server triggers sampling and the client responds with the prompt output?

Thank you for your assistance.

Additional Context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions