feat: ToolError migration to ErrorData (#4051)
This commit is contained in:
@@ -2,11 +2,10 @@
|
||||
//! add a tool you want to have around and then add the client to the extension router
|
||||
|
||||
use mcp_client::client::{Error, McpClientTrait};
|
||||
use mcp_core::ToolError;
|
||||
use rmcp::{
|
||||
model::{
|
||||
CallToolResult, Content, GetPromptResult, ListPromptsResult, ListResourcesResult,
|
||||
ListToolsResult, ReadResourceResult, ServerNotification, Tool,
|
||||
CallToolResult, Content, ErrorData, GetPromptResult, ListPromptsResult,
|
||||
ListResourcesResult, ListToolsResult, ReadResourceResult, ServerNotification, Tool,
|
||||
},
|
||||
object,
|
||||
};
|
||||
@@ -17,7 +16,7 @@ use tokio_util::sync::CancellationToken;
|
||||
|
||||
pub struct MockClient {
|
||||
tools: HashMap<String, Tool>,
|
||||
handlers: HashMap<String, Box<dyn Fn(&Value) -> Result<Vec<Content>, ToolError> + Send + Sync>>,
|
||||
handlers: HashMap<String, Box<dyn Fn(&Value) -> Result<Vec<Content>, ErrorData> + Send + Sync>>,
|
||||
}
|
||||
|
||||
impl MockClient {
|
||||
@@ -30,7 +29,7 @@ impl MockClient {
|
||||
|
||||
pub(crate) fn add_tool<F>(mut self, tool: Tool, handler: F) -> Self
|
||||
where
|
||||
F: Fn(&Value) -> Result<Vec<Content>, ToolError> + Send + Sync + 'static,
|
||||
F: Fn(&Value) -> Result<Vec<Content>, ErrorData> + Send + Sync + 'static,
|
||||
{
|
||||
let tool_name = tool.name.to_string();
|
||||
self.tools.insert(tool_name.clone(), tool);
|
||||
|
||||
@@ -34,9 +34,9 @@ use goose::config::Config;
|
||||
use goose::providers::pricing::initialize_pricing_cache;
|
||||
use goose::session;
|
||||
use input::InputResult;
|
||||
use mcp_core::handler::ToolError;
|
||||
use rmcp::model::PromptMessage;
|
||||
use rmcp::model::ServerNotification;
|
||||
use rmcp::model::{ErrorCode, ErrorData};
|
||||
|
||||
use goose::conversation::message::{Message, MessageContent};
|
||||
use rand::{distributions::Alphanumeric, Rng};
|
||||
@@ -927,7 +927,7 @@ impl Session {
|
||||
let mut response_message = Message::user();
|
||||
response_message.content.push(MessageContent::tool_response(
|
||||
confirmation.id.clone(),
|
||||
Err(ToolError::ExecutionError("Tool call cancelled by user".to_string()))
|
||||
Err(ErrorData { code: ErrorCode::INVALID_REQUEST, message: std::borrow::Cow::from("Tool call cancelled by user".to_string()), data: None })
|
||||
));
|
||||
self.messages.push(response_message);
|
||||
if let Some(session_file) = &self.session_file {
|
||||
@@ -1294,7 +1294,11 @@ impl Session {
|
||||
for (req_id, _) in &tool_requests {
|
||||
response_message.content.push(MessageContent::tool_response(
|
||||
req_id.clone(),
|
||||
Err(ToolError::ExecutionError(notification.clone())),
|
||||
Err(ErrorData {
|
||||
code: ErrorCode::INTERNAL_ERROR,
|
||||
message: std::borrow::Cow::from(notification.clone()),
|
||||
data: None,
|
||||
}),
|
||||
));
|
||||
}
|
||||
self.push_message(response_message);
|
||||
|
||||
Reference in New Issue
Block a user