Skip to content

[Feature]: Add support for sampling capability #541

Description

@0xKoller

Problem statement

MCP provides a standardized way for servers to request LLM sampling ("completions" or "generations") from language models via clients. This flow allows clients to maintain control over model access, selection, and permissions while enabling servers to leverage AI capabilities—with no server API keys necessary.

Currently, xmcp tool handlers have access to extra.sendRequest() which could technically be used to send a sampling/createMessage request, but there's no ergonomic helper for it. Developers would need to manually construct the full JSON-RPC payload, know the method name, and handle the response parsing themselves.

The xmcp client already declares the sampling capability during initialization (packages/xmcp/src/client/index.ts:28), but the server-side framework provides no abstraction for tool handlers to leverage it.

Proposed solution

The framework should:

  • Declare sampling server capability (with optional tools sub-capability) during initialization
  • Support all message content types: text, image, audio
  • Support modelPreferences (hints, cost/speed/intelligence priorities)
  • Support tools and toolChoice in sampling requests for agentic workflows
  • Handle the multi-turn tool loop pattern (tool_use → tool_result → continue)
  • Export the SampleResult type from xmcp

Package

xmcp (core framework)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions