MCP Sampling

A server asking the client to run a model on its behalf. Sampling inverts the usual direction — the server sends the request, your model and your budget answer it — so the messages are shown verbatim before the buttons.

src/components/ui/mcp-sampling.tsx

About

From the component's own source, where it was written.

A server asking the client to run a model on its behalf.

MCP sampling inverts the usual direction: the server sends a request, and the *client's* model and the *client's* budget answer it. That inversion is the whole risk. A server you installed for its file search can ask for a completion, and unless the client shows the request, nobody sees the prompt that was sent or the tokens that were spent.

So the messages are shown verbatim, before the buttons, in the order the server proposed them — the same rule as ToolApproval, for the same reason. maxTokens is displayed because it is what the request will cost, and a request that omits it is flagged rather than defaulted quietly.

Approve is not the primary action by default. This is a server spending your budget on its own initiative; the emphasis belongs on reading it first.

Install

npx astralyx-ui add mcp-sampling

Usage

import { McpSampling } from '@/components/ui/mcp-sampling'

<McpSampling server="git" messages={request.messages} maxTokens={512} onApprove={run} onDeny={deny} />

Composer

Change the props and the source below follows.

git wants to use your model.

Generating a changelog line for the last commit.

≤ 512 tokenshaiku

Messages the server wants sent

  • system

    Summarise the diff for a changelog entry. One sentence, past tense.

  • user

    --- a/src/auth.ts +++ b/src/auth.ts @@ - const TTL = 3600 + const TTL = 900

Props
tsx
<McpSampling
  server="git"
  messages={request.messages}
  maxTokens={512}
  onApprove={run}
  onDeny={deny}
/>

Examples

A server asking for a completion

API

Generated from the source, so it cannot fall behind the code. One table per exported component, then hooks, functions and types.

McpSampling

A server asking the client to run a model on its behalf.

Extends Omit<ComponentProps<'div'>, 'onSelect'>.

PropTypeDefaultDescription
serverstringrequiredThe server making the request.
messagesSamplingMessage[]requiredShown verbatim, in the server’s order, above the buttons. A server you installed for file search can ask for a completion; unless the client shows it, nobody sees what was sent.
intentReactNode—The server's stated intent, when it sends one.
maxTokensnumber—What the request will cost. Absent is flagged as unbounded rather than defaulted quietly.
modelHintstring—Model preference hints from the request.
onApprove() => void——
onDeny() => void——
busybooleanfalse—
approveLabelstring'Run it'—
denyLabelstring'Deny'—
messagesLabelstring'Messages the server wants sent'—
unboundedLabelstring'No token ceiling requested'—

Types

SamplingMessage

FieldTypeDescription
role'user' | 'assistant' | 'system'—
contentstring—

Behaviour

TopicDetailDescription
approve stylingsecondary, not primaryThis is a server spending your budget on its own initiative. The emphasis belongs on reading it first.