refactor(mcp): migrate compatible logging paths to rmcp SDK
CI / UI Checks (pull_request) Successful in 9s
CI / Rust Checks (pull_request) Successful in 27m19s
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
CI / UI Checks (pull_request) Successful in 9s
CI / Rust Checks (pull_request) Successful in 27m19s
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:
1 parent
5bf4e3e9bf
commit
4832878468
6 files changed
+516
-28
No files matched your search
@@ -41,6 +41,9 @@ use std::{
|
||||
sync::{Mutex, MutexGuard},
|
||||
};
|
||||
|
||||
// Both pinned revisions still require logging despite the SDK's SEP-2577 deprecation.
|
||||
#[allow(deprecated)]
|
||||
use rmcp::model::{LoggingLevel, LoggingMessageNotificationParam, SetLevelRequestParams};
|
||||
use serde::Deserialize;
|
||||
use serde_json::{Value, json};
|
||||
use tokio::task_local;
|
||||
@@ -61,7 +64,8 @@ pub(crate) enum LogLevel {
|
||||
}
|
||||
|
||||
impl LogLevel {
|
||||
/// The exact wire literal of this level.
|
||||
/// The exact wire literal of this level (contract assertions only; runtime uses SDK serde).
|
||||
#[cfg(test)]
|
||||
pub(crate) const fn as_str(self) -> &'static str {
|
||||
match self {
|
||||
Self::Debug => "debug",
|
||||
@@ -80,17 +84,47 @@ impl LogLevel {
|
||||
/// Nothing is coerced: no case folding, no aliases (`warn`), no numeric severities. A value that
|
||||
/// is not one of the pinned strings is malformed, which is what the pinned `LoggingLevel` type
|
||||
/// says and what `InvalidParamsError` is for.
|
||||
#[allow(deprecated)]
|
||||
pub(crate) fn parse(value: &str) -> Option<Self> {
|
||||
match value {
|
||||
"debug" => Some(Self::Debug),
|
||||
"info" => Some(Self::Info),
|
||||
"notice" => Some(Self::Notice),
|
||||
"warning" => Some(Self::Warning),
|
||||
"error" => Some(Self::Error),
|
||||
"critical" => Some(Self::Critical),
|
||||
"alert" => Some(Self::Alert),
|
||||
"emergency" => Some(Self::Emergency),
|
||||
_ => None,
|
||||
if value.len() > MAX_LEVEL_BYTES {
|
||||
return None;
|
||||
}
|
||||
let level: LoggingLevel = serde_json::from_value(Value::String(value.to_owned())).ok()?;
|
||||
#[cfg(test)]
|
||||
crate::app::dispatch_observer::sdk_logging_level_parsed();
|
||||
Some(level.into())
|
||||
}
|
||||
}
|
||||
|
||||
// Keep domain severity ordering independent of SDK enum discriminants (which have no Ord).
|
||||
#[allow(deprecated)]
|
||||
impl From<LoggingLevel> for LogLevel {
|
||||
fn from(level: LoggingLevel) -> Self {
|
||||
match level {
|
||||
LoggingLevel::Debug => Self::Debug,
|
||||
LoggingLevel::Info => Self::Info,
|
||||
LoggingLevel::Notice => Self::Notice,
|
||||
LoggingLevel::Warning => Self::Warning,
|
||||
LoggingLevel::Error => Self::Error,
|
||||
LoggingLevel::Critical => Self::Critical,
|
||||
LoggingLevel::Alert => Self::Alert,
|
||||
LoggingLevel::Emergency => Self::Emergency,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(deprecated)]
|
||||
impl From<LogLevel> for LoggingLevel {
|
||||
fn from(level: LogLevel) -> Self {
|
||||
match level {
|
||||
LogLevel::Debug => Self::Debug,
|
||||
LogLevel::Info => Self::Info,
|
||||
LogLevel::Notice => Self::Notice,
|
||||
LogLevel::Warning => Self::Warning,
|
||||
LogLevel::Error => Self::Error,
|
||||
LogLevel::Critical => Self::Critical,
|
||||
LogLevel::Alert => Self::Alert,
|
||||
LogLevel::Emergency => Self::Emergency,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -135,11 +169,20 @@ pub(crate) struct SetLevelCommand {
|
||||
impl SetLevelCommand {
|
||||
/// The bounded input contract of AC2: the level is length-bounded and compared exactly, so a
|
||||
/// malformed or oversized value is refused with bounded work and one safe detail.
|
||||
pub(crate) fn validate(&self) -> Result<LogLevel, &'static str> {
|
||||
#[allow(deprecated)]
|
||||
pub(crate) fn validate(&self) -> Result<SetLevelRequestParams, &'static str> {
|
||||
if self.level.is_empty() || self.level.len() > MAX_LEVEL_BYTES {
|
||||
return Err(INVALID_LEVEL);
|
||||
}
|
||||
LogLevel::parse(&self.level).ok_or(INVALID_LEVEL)
|
||||
// Only level was part of the old command: unknown members (including _meta) stay ignored.
|
||||
let request =
|
||||
serde_json::from_value(json!({"level": self.level})).map_err(|_| INVALID_LEVEL)?;
|
||||
#[cfg(test)]
|
||||
{
|
||||
crate::app::dispatch_observer::sdk_logging_level_parsed();
|
||||
crate::app::dispatch_observer::sdk_logging_dispatch_enter();
|
||||
}
|
||||
Ok(request)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -282,19 +325,22 @@ pub(crate) fn take_notifications() -> Vec<Value> {
|
||||
}
|
||||
std::mem::take(&mut log.pending)
|
||||
.into_iter()
|
||||
.map(|event| {
|
||||
json!({
|
||||
.filter_map(|event| {
|
||||
#[allow(deprecated)]
|
||||
let params = LoggingMessageNotificationParam::new(
|
||||
event.level.into(),
|
||||
json!({"event": event.event, "outcome": event.outcome}),
|
||||
)
|
||||
.with_logger(LOGGER_NAME);
|
||||
// Logging remains best-effort: a serialization failure drops only this event.
|
||||
let params = serde_json::to_value(params).ok()?;
|
||||
#[cfg(test)]
|
||||
crate::app::dispatch_observer::sdk_logging_notification_serialized();
|
||||
Some(json!({
|
||||
"jsonrpc": "2.0",
|
||||
"method": "notifications/message",
|
||||
"params": {
|
||||
"level": event.level.as_str(),
|
||||
"logger": LOGGER_NAME,
|
||||
"data": {
|
||||
"event": event.event,
|
||||
"outcome": event.outcome,
|
||||
}
|
||||
}
|
||||
})
|
||||
"params": params,
|
||||
}))
|
||||
})
|
||||
.collect()
|
||||
})
|
||||
@@ -354,7 +400,9 @@ pub(crate) fn handle_logging_command(
|
||||
command: SetLevelCommand,
|
||||
) -> LoggingOutcome {
|
||||
match command.validate() {
|
||||
Ok(level) => {
|
||||
Ok(request) => {
|
||||
#[allow(deprecated)]
|
||||
let level = request.level.into();
|
||||
store.set(session_id, level);
|
||||
LoggingOutcome::Applied(level)
|
||||
}
|
||||
|
||||
@@ -10,7 +10,8 @@ use super::*;
|
||||
/// is malformed (which the adapter answers with the same safe detail).
|
||||
fn validate(level: &str) -> Option<Result<LogLevel, &'static str>> {
|
||||
let command: SetLevelCommand = serde_json::from_value(json!({ "level": level })).ok()?;
|
||||
Some(command.validate())
|
||||
#[allow(deprecated)]
|
||||
Some(command.validate().map(|request| request.level.into()))
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -291,8 +292,11 @@ fn the_modern_level_is_read_from_the_pinned_meta_key_only() {
|
||||
fn the_command_records_the_level_of_its_own_session_only() {
|
||||
let store = LogLevelStore::new();
|
||||
store.set("other-session", LogLevel::Debug);
|
||||
let command: SetLevelCommand =
|
||||
serde_json::from_value(json!({ "level": "critical" })).expect("a pinned level parses");
|
||||
// Unknown members were ignored by the legacy command; SDK metadata must not narrow that wire.
|
||||
let command: SetLevelCommand = serde_json::from_value(json!({
|
||||
"level": "critical", "_meta": 7, "unknown": {"private": "ignored"}
|
||||
}))
|
||||
.expect("a pinned level parses regardless of unknown members");
|
||||
let outcome = handle_logging_command(&store, "this-session", command);
|
||||
assert!(matches!(
|
||||
outcome,
|
||||
|
||||
Reference in new issue
Block a user