CI / UI Checks (pull_request) Successful in 12s
CI / Rust Checks (pull_request) Successful in 49m59s
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 2s
CI / Deploy (pull_request) Skipped
70 lines
2.6 KiB
Rust
70 lines
2.6 KiB
Rust
//! Typed negotiation results; admission and session lifecycle remain in the HTTP adapter.
|
|
|
|
use rmcp::model::InitializeRequestParams;
|
|
#[cfg(test)]
|
|
use rmcp::model::{InitializeResult, ServerCapabilities};
|
|
use serde_json::Value;
|
|
|
|
pub(crate) fn initialize_params(
|
|
params: &Value,
|
|
) -> Result<InitializeRequestParams, serde_json::Error> {
|
|
// Only protocolVersion was validated here; ignored client fields must not acquire SDK constraints.
|
|
serde_json::from_value(serde_json::json!({
|
|
"protocolVersion": params.get("protocolVersion"),
|
|
"capabilities": {},
|
|
"clientInfo": {"name": "", "version": ""}
|
|
}))
|
|
}
|
|
|
|
#[cfg(test)]
|
|
fn capabilities(advertised: &Value) -> ServerCapabilities {
|
|
serde_json::from_value(advertised.clone())
|
|
.expect("registry capability fragments match SDK capability shapes")
|
|
}
|
|
|
|
#[cfg(test)]
|
|
fn restore_registry_extensions(result: &mut Value, advertised: Value) {
|
|
let capabilities = result["capabilities"]
|
|
.as_object_mut()
|
|
.expect("SDK server capabilities serialize as an object");
|
|
// SDK ServerCapabilities has no flattened map for extra registry capability names.
|
|
for (name, settings) in advertised
|
|
.as_object()
|
|
.expect("registry capabilities are an object")
|
|
{
|
|
capabilities
|
|
.entry(name.clone())
|
|
.or_insert_with(|| settings.clone());
|
|
}
|
|
}
|
|
|
|
pub(crate) fn initialized_notification(message: &Value) -> rmcp::model::ClientNotification {
|
|
// Admission already checked the envelope; ignored params must not acquire SDK constraints.
|
|
let notification: rmcp::model::InitializedNotification =
|
|
serde_json::from_value(serde_json::json!({"method": message["method"]}))
|
|
.expect("registry dispatched a validated initialized notification");
|
|
#[cfg(test)]
|
|
crate::app::dispatch_observer::sdk_initialized_notification_decoded(¬ification);
|
|
notification.into()
|
|
}
|
|
|
|
#[cfg(test)]
|
|
mod tests {
|
|
use super::*;
|
|
use serde_json::json;
|
|
|
|
#[test]
|
|
fn lifecycle_sdk_retains_extra_registry_capabilities_without_replacing_sdk_fields() {
|
|
let advertised =
|
|
json!({"tools":{"listChanged":false}, "inert_test_capability":{"enabled":true}});
|
|
let mut result = serde_json::to_value(InitializeResult::new(capabilities(&advertised)))
|
|
.expect("typed result serializes");
|
|
assert_eq!(
|
|
result["capabilities"],
|
|
json!({"tools":{"listChanged":false}})
|
|
);
|
|
restore_registry_extensions(&mut result, advertised.clone());
|
|
assert_eq!(result["capabilities"], advertised);
|
|
}
|
|
}
|