aKode: avviso chiaro per i server MCP irraggiungibili in exec e login mcp:<server> senza avviso fuorviante

Trovati nel test end-to-end del plugin memoria con imeAI:
- `akode exec` ignorava mcpServer/startupStatus/updated: se il server MCP non
  rispondeva restavano solo le righe ERROR di rmcp. Ora l'uscita testuale
  stampa «warning: MCP server `memoria` is not reachable (...); aKode continues
  without its tools.» e quella JSON un elemento error; il filtro di exec lascia
  passare gli aggiornamenti del thread principale (o senza thread).
- `akode login --provider mcp:<server> --with-api-key` avvisava che il
  provider di modelli `mcp:<server>` non era in config.toml e suggeriva una
  sezione [model_providers.mcp:<server>] sbagliata; ora spiega che la chiave è
  il Bearer del server MCP. Gli avvisi per i provider di modelli restano.
- prove: messaggio e silenzio per gli altri stati, filtro per thread,
  avvisi di login per mcp: e per provider sconosciuti.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
andrea.difonzo
2026-11-14 19:56:48 +01:00
parent a005236bcb
commit ea5eef634a
6 changed files with 152 additions and 10 deletions

View File

@@ -1,6 +1,8 @@
use anyhow::Context;
use std::path::Path;
use akode_app_server_protocol::McpServerStartupState;
use akode_app_server_protocol::McpServerStatusUpdatedNotification;
use akode_app_server_protocol::ServerNotification;
use akode_core::config::Config;
use akode_exec_server::BoundOutput;
@@ -45,3 +47,66 @@ pub(crate) fn handle_last_message(
}
Ok(())
}
/// Message shown when an MCP server cannot be reached: the session goes on without its tools.
/// Returns `None` for every other startup state.
pub(crate) fn mcp_startup_failure_message(
notification: &McpServerStatusUpdatedNotification,
) -> Option<String> {
if notification.status != McpServerStartupState::Failed {
return None;
}
let detail = notification
.error
.as_deref()
.map(str::trim)
.filter(|error| !error.is_empty())
.map(|error| format!(" ({error})"))
.unwrap_or_default();
Some(format!(
"MCP server `{}` is not reachable{detail}; aKode continues without its tools.",
notification.name
))
}
#[cfg(test)]
mod mcp_startup_tests {
use super::*;
fn notification(
status: McpServerStartupState,
error: Option<&str>,
) -> McpServerStatusUpdatedNotification {
McpServerStatusUpdatedNotification {
thread_id: None,
name: "memoria".to_string(),
status,
error: error.map(str::to_string),
failure_reason: None,
}
}
#[test]
fn failed_server_gets_a_clear_message() {
let message = mcp_startup_failure_message(&notification(
McpServerStartupState::Failed,
Some("connection refused"),
))
.expect("message");
assert_eq!(
message,
"MCP server `memoria` is not reachable (connection refused); aKode continues without its tools."
);
}
#[test]
fn other_states_are_silent() {
for status in [
McpServerStartupState::Starting,
McpServerStartupState::Ready,
McpServerStartupState::Cancelled,
] {
assert_eq!(mcp_startup_failure_message(&notification(status, None)), None);
}
}
}

View File

@@ -243,6 +243,12 @@ impl EventProcessor for EventProcessorWithHumanOutput {
CodexStatus::Running
}
ServerNotification::Warning(notification) => self.process_warning(notification.message),
ServerNotification::McpServerStatusUpdated(notification) => {
match crate::event_processor::mcp_startup_failure_message(&notification) {
Some(message) => self.process_warning(message),
None => CodexStatus::Running,
}
}
ServerNotification::AuthRecoveryStarted(notification) => {
eprintln!("{}", notification.message);
CodexStatus::Running

View File

@@ -447,6 +447,16 @@ impl EventProcessorWithJsonOutput {
events.extend(warning.events);
warning.status
}
ServerNotification::McpServerStatusUpdated(notification) => {
match crate::event_processor::mcp_startup_failure_message(&notification) {
Some(message) => {
let warning = self.collect_warning(message);
events.extend(warning.events);
warning.status
}
None => CodexStatus::Running,
}
}
ServerNotification::Error(notification) => {
let message = match notification.error.additional_details {
Some(details) if !details.is_empty() => {

View File

@@ -1593,6 +1593,11 @@ fn should_process_notification(
.thread_id
.as_deref()
.is_none_or(|candidate| candidate == thread_id),
// MCP startup updates belong to the thread that owns the connection (or to none).
ServerNotification::McpServerStatusUpdated(notification) => notification
.thread_id
.as_deref()
.is_none_or(|candidate| candidate == thread_id),
ServerNotification::AuthRecoveryStarted(notification)
| ServerNotification::AuthRecoveryCompleted(notification) => {
notification.thread_id == thread_id && notification.turn_id == turn_id

View File

@@ -257,6 +257,28 @@ fn runtime_warnings_are_filtered_to_the_primary_thread() {
assert_eq!(outcomes, [true, true, false, false]);
}
#[test]
fn mcp_startup_updates_are_filtered_to_the_primary_thread() {
let primary_thread_id = "thread-1";
let outcomes = [None, Some(primary_thread_id), Some("thread-2")].map(|thread_id| {
should_process_notification(
&ServerNotification::McpServerStatusUpdated(
akode_app_server_protocol::McpServerStatusUpdatedNotification {
thread_id: thread_id.map(str::to_string),
name: "memoria".to_string(),
status: akode_app_server_protocol::McpServerStartupState::Failed,
error: Some("connection refused".to_string()),
failure_reason: None,
},
),
primary_thread_id,
"turn-1",
)
});
assert_eq!(outcomes, [true, true, false]);
}
#[tokio::test]
async fn resume_lookup_model_providers_filters_only_last_lookup() {
let codex_home = tempdir().expect("create temp codex home");