-
Notifications
You must be signed in to change notification settings - Fork 13.9k
Prepare executor MCP runtimes for replacement #29944
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,6 +8,8 @@ | |
| use std::collections::HashMap; | ||
| use std::sync::Arc; | ||
| use std::sync::Mutex as StdMutex; | ||
| use std::sync::atomic::AtomicU64; | ||
| use std::sync::atomic::Ordering; | ||
|
|
||
| use crate::mcp::McpPermissionPromptAutoApproveContext; | ||
| use crate::mcp::mcp_permission_prompt_is_auto_approved; | ||
|
|
@@ -48,13 +50,16 @@ pub trait ElicitationReviewer: Send + Sync { | |
|
|
||
| pub type ElicitationReviewerHandle = Arc<dyn ElicitationReviewer>; | ||
|
|
||
| static NEXT_ELICITATION_ROUTE_ID: AtomicU64 = AtomicU64::new(1); | ||
|
|
||
| #[derive(Clone)] | ||
| pub(crate) struct ElicitationRequestManager { | ||
| requests: Arc<Mutex<ResponderMap>>, | ||
| pub(crate) approval_policy: Arc<StdMutex<AskForApproval>>, | ||
| pub(crate) permission_profile: Arc<StdMutex<PermissionProfile>>, | ||
| auto_deny: Arc<StdMutex<bool>>, | ||
| reviewer: Option<ElicitationReviewerHandle>, | ||
| route_id: u64, | ||
| } | ||
|
|
||
| impl ElicitationRequestManager { | ||
|
|
@@ -69,6 +74,7 @@ impl ElicitationRequestManager { | |
| permission_profile: Arc::new(StdMutex::new(permission_profile)), | ||
| auto_deny: Arc::new(StdMutex::new(false)), | ||
| reviewer, | ||
| route_id: NEXT_ELICITATION_ROUTE_ID.fetch_add(1, Ordering::Relaxed), | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -110,6 +116,7 @@ impl ElicitationRequestManager { | |
| let permission_profile = self.permission_profile.clone(); | ||
| let auto_deny = self.auto_deny.clone(); | ||
| let reviewer = self.reviewer.clone(); | ||
| let route_id = self.route_id; | ||
| Box::new(move |id, elicitation| { | ||
| let elicitation_requests = elicitation_requests.clone(); | ||
| let tx_event = tx_event.clone(); | ||
|
|
@@ -214,17 +221,18 @@ impl ElicitationRequestManager { | |
| }, | ||
| }; | ||
| let (tx, rx) = oneshot::channel(); | ||
| let response_id = RequestId::String(Arc::from(format!("{route_id}:{id}"))); | ||
| { | ||
| let mut lock = elicitation_requests.lock().await; | ||
| lock.insert((server_name.clone(), id.clone()), tx); | ||
| lock.insert((server_name.clone(), response_id.clone()), tx); | ||
|
Comment on lines
+224
to
+227
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
When a refreshed/candidate manager emits an elicitation before Useful? React with 👍 / 👎. |
||
| } | ||
| let _ = tx_event | ||
| .send(Event { | ||
| id: "mcp_elicitation_request".to_string(), | ||
| msg: EventMsg::ElicitationRequest(ElicitationRequestEvent { | ||
| turn_id: None, | ||
| server_name, | ||
| id: match id.clone() { | ||
| id: match response_id { | ||
| rmcp::model::NumberOrString::String(value) => { | ||
| ProtocolRequestId::String(value.to_string()) | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If an MCP server has overlapping elicitations whose JSON-RPC IDs are
1and"1", this stringified routed ID makes both entries use the same key (<route>:1), so the second insert overwrites the first responder and one request can never be resolved. The previous typedRequestIdkey distinguished numeric and string IDs, so the route wrapper should encode the variant as well as the value.Useful? React with 👍 / 👎.