feat(mcp): route Tools requests through typed rmcp runtime seam
CI / Rust Checks (pull_request) Successful in 24m17s
CI / Rust Feature Validation (pull_request) Skipped
CI / UI Checks (pull_request) Successful in 7s
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
CI / Rust Checks (pull_request) Successful in 24m17s
CI / Rust Feature Validation (pull_request) Skipped
CI / UI Checks (pull_request) Successful in 7s
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:
1 parent
4ec9d9201b
commit
7f18bce679
9 files changed
+450
-7
No files matched your search
@@ -7,6 +7,7 @@
|
||||
|
||||
use super::request::{InitializeParams, ToolCallParams};
|
||||
use super::response::take_confirmation_token;
|
||||
use super::rmcp_dispatch::handle_tools_command;
|
||||
use crate::{
|
||||
auth::VerifiedMachineCredential,
|
||||
jsonrpc::{
|
||||
@@ -19,7 +20,7 @@ use crate::{
|
||||
ResourceReadCommand, ResourcesCommand, ResourcesListCommand, ResourcesOutcome,
|
||||
ServiceContext, ToolCallCommand, ToolsCommand, ToolsListCommand, ToolsOutcome,
|
||||
declared_mcp_method, discover_result, handle_completion_command, handle_prompts_command,
|
||||
handle_resources_command, handle_tools_command, validate_modern_request_name,
|
||||
handle_resources_command, validate_modern_request_name,
|
||||
},
|
||||
session::SessionState,
|
||||
tool_error::execution_locale,
|
||||
|
||||
@@ -51,9 +51,15 @@ pub(crate) struct CounterSet {
|
||||
era_modern: AtomicUsize,
|
||||
era_legacy: AtomicUsize,
|
||||
tools_service: AtomicUsize,
|
||||
sdk_tools_dispatch: AtomicUsize,
|
||||
}
|
||||
|
||||
impl CounterSet {
|
||||
/// SDK typed Tools dispatch entries, separate from the existing era/service snapshot.
|
||||
pub(crate) fn sdk_tools_dispatch(&self) -> usize {
|
||||
self.sdk_tools_dispatch.load(Ordering::SeqCst)
|
||||
}
|
||||
|
||||
/// Read the counters of one observed request as one comparable snapshot.
|
||||
pub(crate) fn snapshot(&self) -> Snapshot {
|
||||
Snapshot {
|
||||
@@ -134,6 +140,11 @@ pub(crate) fn tools_service_enter() {
|
||||
increment(|counters| &counters.tools_service);
|
||||
}
|
||||
|
||||
/// `SDK_TOOLS_DISPATCH`: entered the real SDK typed Tools dispatch, not just admission.
|
||||
pub(crate) fn sdk_tools_dispatch_enter() {
|
||||
increment(|counters| &counters.sdk_tools_dispatch);
|
||||
}
|
||||
|
||||
fn increment(counter: impl Fn(&CounterSet) -> &AtomicUsize) {
|
||||
let _ = OBSERVER.try_with(|counters| {
|
||||
counter(counters).fetch_add(1, Ordering::SeqCst);
|
||||
@@ -153,3 +164,7 @@ pub(crate) mod support;
|
||||
#[cfg(test)]
|
||||
#[path = "../dispatch_observer_harness.rs"]
|
||||
mod tests;
|
||||
|
||||
#[cfg(test)]
|
||||
#[path = "../rmcp_runtime_tests.rs"]
|
||||
mod rmcp_runtime_tests;
|
||||
@@ -24,6 +24,7 @@ use super::response::{
|
||||
resource_templates_list_result, resources_list_result, take_confirmation_token,
|
||||
tools_list_result,
|
||||
};
|
||||
use super::rmcp_dispatch::handle_tools_command;
|
||||
use super::{AgentRoutePath, AppState};
|
||||
use crate::{
|
||||
auth::VerifiedMachineCredential,
|
||||
@@ -38,7 +39,6 @@ use crate::{
|
||||
ResourcesCommand, ResourcesListCommand, ResourcesOutcome, ServiceContext, SetLevelCommand,
|
||||
ToolCallCommand, ToolsCommand, ToolsListCommand, ToolsOutcome, handle_completion_command,
|
||||
handle_logging_command, handle_prompts_command, handle_resources_command,
|
||||
handle_tools_command,
|
||||
},
|
||||
tool_error::execution_locale,
|
||||
transport::{ResponseMode, session_id_from_headers, transport_response},
|
||||
|
||||
@@ -37,16 +37,14 @@ use futures_util::stream;
|
||||
use serde_json::{Number, Value, json};
|
||||
use tokio::sync::{mpsc, watch};
|
||||
|
||||
use super::rmcp_dispatch::handle_tools_command;
|
||||
use super::{
|
||||
AppState,
|
||||
response::{ToolCommandPayload, tool_command_payload, tool_command_response},
|
||||
};
|
||||
use crate::{
|
||||
jsonrpc::request_id,
|
||||
protocol::{
|
||||
ContinuationSupport, ServiceContext, ToolCallCommand, ToolsCommand, ToolsOutcome,
|
||||
handle_tools_command,
|
||||
},
|
||||
protocol::{ContinuationSupport, ServiceContext, ToolCallCommand, ToolsCommand, ToolsOutcome},
|
||||
transport::{ResponseMode, sse_response},
|
||||
};
|
||||
|
||||
|
||||
@@ -0,0 +1,67 @@
|
||||
//! Runtime SDK Tools dispatch; admission, lifecycle and response projection stay with the caller.
|
||||
|
||||
use std::sync::Arc;
|
||||
|
||||
use rmcp::model::{CallToolRequestParams, PaginatedRequestParams};
|
||||
use serde_json::Value;
|
||||
|
||||
use super::{AppState, lifecycle::ToolCallLifecycle};
|
||||
use crate::protocol::{
|
||||
ServiceContext, ToolCallCommand, ToolCallOutcome, ToolsCommand, ToolsListCommand, ToolsOutcome,
|
||||
};
|
||||
|
||||
// Crank extensions are not SDK fields and must survive the typed request boundary unchanged.
|
||||
enum SdkToolsCommand {
|
||||
List {
|
||||
params: PaginatedRequestParams,
|
||||
limit: Option<usize>,
|
||||
},
|
||||
Call {
|
||||
params: CallToolRequestParams,
|
||||
confirmation_token: Option<String>,
|
||||
},
|
||||
}
|
||||
|
||||
pub(super) async fn handle_tools_command(
|
||||
state: &Arc<AppState>,
|
||||
context: ServiceContext<'_>,
|
||||
command: ToolsCommand,
|
||||
lifecycle: Option<ToolCallLifecycle>,
|
||||
) -> ToolsOutcome {
|
||||
let request = match command {
|
||||
ToolsCommand::List(list) => SdkToolsCommand::List {
|
||||
params: PaginatedRequestParams::default().with_cursor(list.cursor),
|
||||
limit: list.limit,
|
||||
},
|
||||
ToolsCommand::Call(call) => {
|
||||
let Value::Object(arguments) = call.arguments else {
|
||||
return ToolsOutcome::Call(ToolCallOutcome::InvalidParams(
|
||||
"tool arguments must be an object".to_owned(),
|
||||
));
|
||||
};
|
||||
SdkToolsCommand::Call {
|
||||
params: CallToolRequestParams::new(call.tool_name).with_arguments(arguments),
|
||||
confirmation_token: call.confirmation_token,
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
#[cfg(test)]
|
||||
super::dispatch_observer::sdk_tools_dispatch_enter();
|
||||
|
||||
let command = match request {
|
||||
SdkToolsCommand::List { params, limit } => ToolsCommand::List(ToolsListCommand {
|
||||
cursor: params.cursor,
|
||||
limit,
|
||||
}),
|
||||
SdkToolsCommand::Call {
|
||||
params,
|
||||
confirmation_token,
|
||||
} => ToolsCommand::Call(ToolCallCommand {
|
||||
tool_name: params.name.into_owned(),
|
||||
arguments: Value::Object(params.arguments.unwrap_or_default()),
|
||||
confirmation_token,
|
||||
}),
|
||||
};
|
||||
crate::protocol::handle_tools_command(state, context, command, lifecycle).await
|
||||
}
|
||||
Reference in new issue
Block a user