feat: ToolError migration to ErrorData (#4051)

This commit is contained in:
Alex Hancock
2025-08-12 16:18:41 -04:00
committed by GitHub
parent 88b013194c
commit bd1eff52a4
35 changed files with 2459 additions and 1336 deletions
+7 -5
View File
@@ -603,12 +603,12 @@ impl Message {
mod tests {
use crate::conversation::message::{Message, MessageContent};
use crate::conversation::*;
use mcp_core::handler::ToolError;
use mcp_core::ToolCall;
use rmcp::model::{
AnnotateAble, PromptMessage, PromptMessageContent, PromptMessageRole, RawEmbeddedResource,
RawImageContent, ResourceContents,
};
use rmcp::model::{ErrorCode, ErrorData};
use serde_json::{json, Value};
#[test]
@@ -683,9 +683,11 @@ mod tests {
fn test_error_serialization() {
let message = Message::assistant().with_tool_request(
"tool123",
Err(ToolError::ExecutionError(
"Something went wrong".to_string(),
)),
Err(ErrorData {
code: ErrorCode::INTERNAL_ERROR,
message: std::borrow::Cow::from("Something went wrong".to_string()),
data: None,
}),
);
let json_str = serde_json::to_string_pretty(&message).unwrap();
@@ -697,7 +699,7 @@ mod tests {
// Check tool_call serialization with error
let tool_call = &value["content"][0]["toolCall"];
assert_eq!(tool_call["status"], "error");
assert_eq!(tool_call["error"], "Execution failed: Something went wrong");
assert_eq!(tool_call["error"], "-32603: Something went wrong");
}
#[test]
@@ -1,6 +1,8 @@
use mcp_core::handler::{ToolError, ToolResult};
use mcp_core::ToolResult;
use rmcp::model::{ErrorCode, ErrorData};
use serde::ser::SerializeStruct;
use serde::{Deserialize, Deserializer, Serialize, Serializer};
use std::borrow::Cow;
pub fn serialize<T, S>(value: &ToolResult<T>, serializer: S) -> Result<S::Ok, S::Error>
where
@@ -52,7 +54,11 @@ where
}
ResultFormat::Error { status, error } => {
if status == "error" {
Ok(Err(ToolError::ExecutionError(error)))
Ok(Err(ErrorData {
code: ErrorCode::INTERNAL_ERROR,
message: Cow::from(error),
data: None,
}))
} else {
Err(serde::de::Error::custom(format!(
"Expected status 'error', got '{}'",