fix(mcp): propagate internal serialization errors instead of silently swallowing them to prevent LLM hallucination
This commit is contained in:
1 parent
f8925050db
commit
8f32a09399
13 files changed
+235
-63
No files matched your search
@@ -1,9 +1,9 @@
|
||||
use crate::AppState;
|
||||
use crate::state::GenericEvent;
|
||||
use axum::extract::{Query, State};
|
||||
use axum::response::IntoResponse;
|
||||
use std::collections::HashMap;
|
||||
use std::sync::Arc;
|
||||
use crate::state::GenericEvent;
|
||||
|
||||
pub async fn wait_for_event_handler(
|
||||
State(state): State<Arc<AppState>>,
|
||||
@@ -18,7 +18,9 @@ pub async fn wait_for_event_handler(
|
||||
match rx.recv().await {
|
||||
Ok(event) => {
|
||||
let topic_matches = topic.as_ref().map_or(true, |t| t == &event.topic);
|
||||
let session_matches = session_id.as_ref().map_or(true, |s| Some(s) == event.session_id.as_ref());
|
||||
let session_matches = session_id
|
||||
.as_ref()
|
||||
.map_or(true, |s| Some(s) == event.session_id.as_ref());
|
||||
|
||||
if topic_matches && session_matches {
|
||||
return axum::Json(event);
|
||||
@@ -46,14 +48,14 @@ pub async fn post_event_handler(
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::state::MemoryState;
|
||||
use crate::router::MemoryHandler;
|
||||
use tempfile::tempdir;
|
||||
use crate::state::MemoryState;
|
||||
use axum::extract::Query;
|
||||
use axum::extract::State;
|
||||
use std::collections::HashMap;
|
||||
use std::sync::atomic::AtomicUsize;
|
||||
use std::sync::RwLock;
|
||||
use std::sync::atomic::AtomicUsize;
|
||||
use tempfile::tempdir;
|
||||
|
||||
#[tokio::test]
|
||||
async fn test_events_wait_and_post() {
|
||||
@@ -70,7 +72,7 @@ mod tests {
|
||||
let mut params = HashMap::new();
|
||||
params.insert("topic".to_string(), "test_topic".to_string());
|
||||
params.insert("session_id".to_string(), "123".to_string());
|
||||
|
||||
|
||||
let wait_task = tokio::spawn(async move {
|
||||
let res = wait_for_event_handler(State(app_state_clone), Query(params)).await;
|
||||
// axum::Json<GenericEvent> is returned, we need to extract it somehow, but just returning is enough for testing
|
||||
|
||||
Reference in new issue
Block a user