@@ -1,11 +1,11 @@
|
||||
use crate::mcp_utils::ToolResult;
|
||||
use chrono::Utc;
|
||||
use mcp_core::{ToolCall, ToolResult};
|
||||
use rmcp::model::{
|
||||
AnnotateAble, CallToolRequestParam, Content, ImageContent, JsonObject, PromptMessage,
|
||||
PromptMessageContent, PromptMessageRole, RawContent, RawImageContent, RawTextContent,
|
||||
ResourceContents, Role, TextContent,
|
||||
AnnotateAble, Content, ImageContent, PromptMessage, PromptMessageContent, PromptMessageRole,
|
||||
RawContent, RawImageContent, RawTextContent, ResourceContents, Role, TextContent,
|
||||
};
|
||||
use serde::{Deserialize, Deserializer, Serialize};
|
||||
use serde_json::Value;
|
||||
use std::collections::HashSet;
|
||||
use std::fmt;
|
||||
use utoipa::ToSchema;
|
||||
@@ -46,7 +46,7 @@ pub struct ToolRequest {
|
||||
pub id: String,
|
||||
#[serde(with = "tool_result_serde")]
|
||||
#[schema(value_type = Object)]
|
||||
pub tool_call: ToolResult<CallToolRequestParam>,
|
||||
pub tool_call: ToolResult<ToolCall>,
|
||||
}
|
||||
|
||||
impl ToolRequest {
|
||||
@@ -81,7 +81,7 @@ pub struct ToolResponse {
|
||||
pub struct ToolConfirmationRequest {
|
||||
pub id: String,
|
||||
pub tool_name: String,
|
||||
pub arguments: JsonObject,
|
||||
pub arguments: Value,
|
||||
pub prompt: Option<String>,
|
||||
}
|
||||
|
||||
@@ -102,7 +102,7 @@ pub struct FrontendToolRequest {
|
||||
pub id: String,
|
||||
#[serde(with = "tool_result_serde")]
|
||||
#[schema(value_type = Object)]
|
||||
pub tool_call: ToolResult<CallToolRequestParam>,
|
||||
pub tool_call: ToolResult<ToolCall>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, ToSchema)]
|
||||
@@ -188,10 +188,7 @@ impl MessageContent {
|
||||
)
|
||||
}
|
||||
|
||||
pub fn tool_request<S: Into<String>>(
|
||||
id: S,
|
||||
tool_call: ToolResult<CallToolRequestParam>,
|
||||
) -> Self {
|
||||
pub fn tool_request<S: Into<String>>(id: S, tool_call: ToolResult<ToolCall>) -> Self {
|
||||
MessageContent::ToolRequest(ToolRequest {
|
||||
id: id.into(),
|
||||
tool_call,
|
||||
@@ -208,7 +205,7 @@ impl MessageContent {
|
||||
pub fn tool_confirmation_request<S: Into<String>>(
|
||||
id: S,
|
||||
tool_name: String,
|
||||
arguments: JsonObject,
|
||||
arguments: Value,
|
||||
prompt: Option<String>,
|
||||
) -> Self {
|
||||
MessageContent::ToolConfirmationRequest(ToolConfirmationRequest {
|
||||
@@ -230,10 +227,7 @@ impl MessageContent {
|
||||
MessageContent::RedactedThinking(RedactedThinkingContent { data: data.into() })
|
||||
}
|
||||
|
||||
pub fn frontend_tool_request<S: Into<String>>(
|
||||
id: S,
|
||||
tool_call: ToolResult<CallToolRequestParam>,
|
||||
) -> Self {
|
||||
pub fn frontend_tool_request<S: Into<String>>(id: S, tool_call: ToolResult<ToolCall>) -> Self {
|
||||
MessageContent::FrontendToolRequest(FrontendToolRequest {
|
||||
id: id.into(),
|
||||
tool_call,
|
||||
@@ -563,7 +557,7 @@ impl Message {
|
||||
pub fn with_tool_request<S: Into<String>>(
|
||||
self,
|
||||
id: S,
|
||||
tool_call: ToolResult<CallToolRequestParam>,
|
||||
tool_call: ToolResult<ToolCall>,
|
||||
) -> Self {
|
||||
self.with_content(MessageContent::tool_request(id, tool_call))
|
||||
}
|
||||
@@ -582,7 +576,7 @@ impl Message {
|
||||
self,
|
||||
id: S,
|
||||
tool_name: String,
|
||||
arguments: JsonObject,
|
||||
arguments: Value,
|
||||
prompt: Option<String>,
|
||||
) -> Self {
|
||||
self.with_content(MessageContent::tool_confirmation_request(
|
||||
@@ -593,7 +587,7 @@ impl Message {
|
||||
pub fn with_frontend_tool_request<S: Into<String>>(
|
||||
self,
|
||||
id: S,
|
||||
tool_call: ToolResult<CallToolRequestParam>,
|
||||
tool_call: ToolResult<ToolCall>,
|
||||
) -> Self {
|
||||
self.with_content(MessageContent::frontend_tool_request(id, tool_call))
|
||||
}
|
||||
@@ -734,13 +728,13 @@ impl Message {
|
||||
mod tests {
|
||||
use crate::conversation::message::{Message, MessageContent, MessageMetadata};
|
||||
use crate::conversation::*;
|
||||
use mcp_core::ToolCall;
|
||||
use rmcp::model::{
|
||||
AnnotateAble, CallToolRequestParam, PromptMessage, PromptMessageContent, PromptMessageRole,
|
||||
RawEmbeddedResource, RawImageContent, ResourceContents,
|
||||
AnnotateAble, PromptMessage, PromptMessageContent, PromptMessageRole, RawEmbeddedResource,
|
||||
RawImageContent, ResourceContents,
|
||||
};
|
||||
use rmcp::model::{ErrorCode, ErrorData};
|
||||
use rmcp::object;
|
||||
use serde_json::Value;
|
||||
use serde_json::{json, Value};
|
||||
|
||||
#[test]
|
||||
fn test_sanitize_with_text() {
|
||||
@@ -762,10 +756,7 @@ mod tests {
|
||||
.with_text("Hello, I'll help you with that.")
|
||||
.with_tool_request(
|
||||
"tool123",
|
||||
Ok(CallToolRequestParam {
|
||||
name: "test_tool".into(),
|
||||
arguments: Some(object!({"param": "value"})),
|
||||
}),
|
||||
Ok(ToolCall::new("test_tool", json!({"param": "value"}))),
|
||||
);
|
||||
|
||||
let json_str = serde_json::to_string_pretty(&message).unwrap();
|
||||
@@ -865,7 +856,7 @@ mod tests {
|
||||
assert_eq!(req.id, "tool123");
|
||||
if let Ok(tool_call) = &req.tool_call {
|
||||
assert_eq!(tool_call.name, "test_tool");
|
||||
assert_eq!(tool_call.arguments, Some(object!({"param": "value"})))
|
||||
assert_eq!(tool_call.arguments, json!({"param": "value"}));
|
||||
} else {
|
||||
panic!("Expected successful tool call");
|
||||
}
|
||||
@@ -1019,9 +1010,9 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_message_with_tool_request() {
|
||||
let tool_call = Ok(CallToolRequestParam {
|
||||
name: "test_tool".into(),
|
||||
arguments: Some(object!({})),
|
||||
let tool_call = Ok(ToolCall {
|
||||
name: "test_tool".to_string(),
|
||||
arguments: serde_json::json!({}),
|
||||
});
|
||||
|
||||
let message = Message::assistant().with_tool_request("req1", tool_call);
|
||||
|
||||
Reference in New Issue
Block a user