MCP: execute Tools through request-scoped SDK handlers
CI / UI Checks (pull_request) Successful in 8s
CI / Rust Checks (pull_request) Successful in 35m42s
CI / Rust Feature Validation (pull_request) Skipped
CI / Frontend E2E (pull_request) Skipped
CI / Community Image Smoke (pull_request) Skipped
CI / Required Checks (pull_request) Successful in 1s
CI / Deploy (pull_request) Skipped

This commit is contained in:
bsodfather committed 2026-11-13 16:57:28 +00:00
1 parent 5611e81579
commit 3b30aad28e
12 files changed
+798 -151

No files matched your search

@@ -41,11 +41,11 @@ use tokio::sync::{mpsc, watch};
use super::rmcp_dispatch::handle_tools_command;
use super::{
AppState,
response::{ToolCommandPayload, tool_command_payload, tool_command_response},
response::{ToolCommandPayload, sdk_tools_payload, sdk_tools_response},
};
use crate::{
jsonrpc::request_id,
protocol::{ContinuationSupport, ServiceContext, ToolCallCommand, ToolsCommand, ToolsOutcome},
protocol::{ContinuationSupport, ServiceContext, ToolCallCommand, ToolsCommand},
transport::{ResponseMode, sse_response},
};
@@ -393,7 +393,7 @@ pub(crate) async fn run_tool_call(
});
let message = wire.message.clone();
let correlation = request.correlation.clone();
let protocol_version = wire.protocol_version.clone();
let response_mode = wire.response_mode;
@@ -411,13 +411,7 @@ pub(crate) async fn run_tool_call(
outcome = &mut call => outcome,
_ = lifecycle.cancelled() => return cancelled_response(),
};
return tool_command_response(
&message,
response_mode,
&protocol_version,
&correlation,
outcome,
);
return sdk_tools_response(&message, response_mode, &protocol_version, outcome);
};
debug_assert!(matches!(response_mode, ResponseMode::Sse));
@@ -430,7 +424,6 @@ pub(crate) async fn run_tool_call(
token,
message,
protocol_version: protocol_version.clone(),
correlation,
pending: VecDeque::new(),
finished: false,
logging: crate::protocol::carry_scope(),
@@ -451,7 +444,7 @@ async fn call_future(
request: ToolCallRequest,
lifecycle: ToolCallLifecycle,
command: ToolCallCommand,
) -> ToolsOutcome {
) -> super::rmcp_tools_runtime::Outcome {
handle_tools_command(
&state,
ServiceContext {
@@ -478,13 +471,12 @@ fn cancelled_response() -> Response {
}
struct CallStream {
call: Pin<Box<dyn Future<Output = ToolsOutcome> + Send>>,
call: Pin<Box<dyn Future<Output = super::rmcp_tools_runtime::Outcome> + Send>>,
events: mpsc::Receiver<ProgressEvent>,
cancel: CancelSignal,
token: ProgressToken,
message: Value,
protocol_version: String,
correlation: CorrelationContext,
pending: VecDeque<Event>,
finished: bool,
/// The request's logging context, so the terminal event of the stream is projected exactly as the
@@ -496,7 +488,7 @@ struct CallStream {
enum Step {
Progress(ProgressEvent),
Outcome(ToolsOutcome),
Outcome(super::rmcp_tools_runtime::Outcome),
Cancelled,
}
@@ -541,12 +533,7 @@ async fn next_event_in_scope(
}
Step::Outcome(outcome) => {
call.finished = true;
let payload = match tool_command_payload(
&call.message,
&call.protocol_version,
&call.correlation,
outcome,
) {
let payload = match sdk_tools_payload(&call.message, &call.protocol_version, outcome) {
ToolCommandPayload::Ok(payload) => payload,
ToolCommandPayload::Internal(_) => jsonrpc_internal_error(&call.message),
};