Rust: ergonomic SamplingHandler + typed MCP sampling request on sampling.requested
まだ誰も着手していません。
評価
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 初心者へのやさしさ
- 52/100
- issue の種類
- 機能追加
- 明瞭さ
- おおむね明確
- 活発さ
- 活発
- 技術スタック
- rust
調査の方向性
rust/src/generated/session_events.rs と rust/src/handler.rs から始め、SamplingRequestedData と既存の handler traits を比較します。次に、rust/src/session.rs の session-builder の配線と、rust/src/generated/rpc.rs の sampling RPCs を追跡します。型付きの sampling request と登録済みの SamplingHandler が連携して動作し、既存の low-level methods も引き続き利用できれば完了です。
索引モデルが issue の本文から書いたものです。
説明
Summary
The Rust binding exposes MCP sampling on the wire — the sampling.requested / sampling.completed events and the handle_pending_sampling (and execute_sampling / cancel_sampling_execution) methods — but there are two gaps for a consumer that wants to service MCP sampling requests itself (i.e. answer an MCP server's sampling/createMessage with its own model):
- The request content isn't on the typed event.
SamplingRequestedDatacarries only{ requestId, serverName, mcpRequestId }— not the MCPCreateMessageRequestparams (themessages,modelPreferences,systemPrompt,maxTokens, etc.) that a handler needs to actually produce a completion. So a consumer receives "a sampling request happened" but not what to sample. - There's no ergonomic handler. Every other consumer-serviced request has a first-class handler trait (
PermissionHandler,ElicitationHandler,McpAuthHandler,UserInputHandler, …) wired on the session builder. Sampling has none — a consumer must subscribe to the rawsampling.requestedevent and call the low-level, Experimentalhandle_pending_samplingby hand.
Current state (public Rust binding)
rust/src/generated/session_events.rs:
No sampling request params (messages / model preferences) are present.pub struct SamplingRequestedData { pub mcp_request_id: serde_json::Value, pub request_id: RequestId, pub server_name: String, } pub struct SamplingCompletedData { pub request_id: RequestId }rust/src/generated/rpc.rs:handle_pending_sampling(UIHandlePendingSamplingRequest) -> UIHandlePendingResult,execute_sampling(...),cancel_sampling_execution(...)— all marked Experimental.rust/src/handler.rs: ergonomic handler traits exist for permission, elicitation, MCP auth, user input, exit-plan-mode, auto-mode-switch — but not sampling.rust/src/session.rs: those handlers are wired on the builder (e.g.mcp_auth_handler); there is no sampling equivalent.
Why this is needed
This is a developer-experience / completeness improvement for consumers that want to fulfill MCP sampling requests with their own inference instead of the default behavior. Today such a consumer:
- can't get the request content from the typed event (has to reach past
SamplingRequestedData), and - has to hand-wire the raw event + Experimental RPC instead of implementing one trait.
It is not a capability blocker (the low-level RPCs exist), so this is a quality-of-life ask, not urgent.
Proposed change
- Expose the MCP sampling request params on
SamplingRequestedDataas a typed field (theCreateMessageRequestparams:messages,modelPreferences,systemPrompt,includeContext,maxTokens,temperature,stopSequences,metadata), so a handler can read what to sample directly from the event. - Add an ergonomic
SamplingHandlertrait inrust/src/handler.rsmirroringMcpAuthHandler:
Wire it on the session builder alongside the other handlers, and have the binding translate the trait's result into the existing#[async_trait] pub trait SamplingHandler: Send + Sync + 'static { async fn handle( &self, session_id: SessionId, request_id: RequestId, request: SamplingRequest, // typed CreateMessageRequest params ) -> SamplingResult; // completion, or None/err to reject }handle_pending_samplingcall (and reject/cancel when the handler declines), so consumers never touch the raw event or the Experimental RPC directly.
Acceptance criteria
- A consumer can register one
SamplingHandleron the session builder and receive the typed MCP sampling request (messages + model preferences), returning a completion or a rejection. - The sampling request params are available as typed data (not only reachable via the untyped/low-level path).
- The existing low-level
handle_pending_sampling/execute_samplingmethods continue to work for consumers that prefer them.
References
rust/src/handler.rs— existing handler-trait pattern (McpAuthHandleret al.) to mirror.rust/src/generated/session_events.rs—SamplingRequestedData/SamplingCompletedData.rust/src/generated/rpc.rs—handle_pending_sampling,execute_sampling,cancel_sampling_execution.- MCP spec —
sampling/createMessageand itsCreateMessageRequestparams.
- 主要言語
- Java
- スター
- 10.5k
- フォーク
- 1.5k
- 平均マージ
- 1日 12時間
- マージ済み PR(30日)
- 133
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
github/copilot-sdk のほかの issue
-
agentic-workflows
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
github/copilot-sdk#2709 · コメント 1 件 ·
-
難易度 1/5 1時間未満 初心者へのやさしさ 78/100
github/copilot-sdk#2673 ·
-
bug testing
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
github/copilot-sdk#2628 ·
-
agentic-workflows
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
github/copilot-sdk#2627 · コメント 1 件 ·
-
agentic-workflows
難易度 2/5 1〜3時間 初心者へのやさしさ 74/100
github/copilot-sdk#2493 ·
github/copilot-sdk の issue をすべて見る
似ている issue
-
bug
難易度 1/5 1時間未満 初心者へのやさしさ 90/100
apache/cloudstack#14222 ·
-
[BUG]茶杯方块在取茶时会引发崩溃 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 88/100
-
1.0.0-alpha2 Type/Improvement
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
wso2/dpdp-accelerator#272 ·
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 88/100
apache/rocketmq-dashboard#4860 · コメント 1 件 ·
-
agent-audit bug
難易度 2/5 1〜3時間 初心者へのやさしさ 88/100
Vault-Web/cloud-page#144 ·