feat(elicitation): add support URL elicitation. SEP-1036 (#605)
This commit is contained in:
parent
edd5b1d7e9
commit
187597bf7e
1 changed files with 1533 additions and 271 deletions
|
|
@ -17,6 +17,7 @@ use rmcp::{
|
|||
use serde::{Deserialize, Serialize};
|
||||
use tokio::sync::Mutex;
|
||||
use tracing_subscriber::{self, EnvFilter};
|
||||
use url::Url;
|
||||
|
||||
/// User information request
|
||||
#[derive(Debug, Serialize, Deserialize, JsonSchema)]
|
||||
|
|
@ -106,6 +107,48 @@ impl ElicitationServer {
|
|||
"User name reset. Next greeting will ask for name again.".to_string(),
|
||||
)]))
|
||||
}
|
||||
|
||||
#[tool(description = "Example of URL elicitation")]
|
||||
pub async fn secure_tool_call(
|
||||
&self,
|
||||
context: RequestContext<RoleServer>,
|
||||
) -> std::result::Result<CallToolResult, McpError> {
|
||||
let elicit_result = context
|
||||
.peer
|
||||
.elicit_url(
|
||||
"User must visit the following URL to complete tool call",
|
||||
Url::parse("https://example.com/complete_tool").expect("valid URL"),
|
||||
"elicit_123",
|
||||
)
|
||||
.await
|
||||
.map_err(|e| {
|
||||
ErrorData::new(
|
||||
ErrorCode::INTERNAL_ERROR,
|
||||
format!("Url elicitation has failed: {}", e),
|
||||
None,
|
||||
)
|
||||
})?;
|
||||
match elicit_result {
|
||||
ElicitationAction::Accept => {
|
||||
// Mock notifying completion
|
||||
let _ = context
|
||||
.peer
|
||||
.notify_url_elicitation_completed(ElicitationResponseNotificationParam {
|
||||
elicitation_id: "elicit_123".to_string(),
|
||||
})
|
||||
.await;
|
||||
Ok(CallToolResult::success(vec![Content::text(
|
||||
"Elicitation via URL successful".to_string(),
|
||||
)]))
|
||||
}
|
||||
ElicitationAction::Cancel => Ok(CallToolResult::success(vec![Content::text(
|
||||
"Elicitation via URL cancelled by user".to_string(),
|
||||
)])),
|
||||
ElicitationAction::Decline => Ok(CallToolResult::error(vec![Content::text(
|
||||
"Elicitation via URL declined by user".to_string(),
|
||||
)])),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[tool_handler]
|
||||
|
|
|
|||
Loading…
Reference in a new issue