Replace mcp_core::resource::* with rmcp types (#3563)
This commit is contained in:
@@ -14,12 +14,11 @@ use std::os::unix::fs::PermissionsExt;
|
||||
use mcp_core::{
|
||||
handler::{PromptError, ResourceError, ToolError},
|
||||
protocol::{JsonRpcMessage, ServerCapabilities},
|
||||
resource::Resource,
|
||||
tool::{Tool, ToolAnnotations},
|
||||
};
|
||||
use mcp_server::router::CapabilitiesBuilder;
|
||||
use mcp_server::Router;
|
||||
use rmcp::model::{Content, Prompt};
|
||||
use rmcp::model::{AnnotateAble, Content, Prompt, RawResource, Resource};
|
||||
|
||||
mod docx_tool;
|
||||
mod pdf_tool;
|
||||
@@ -585,14 +584,16 @@ impl ComputerControllerRouter {
|
||||
.map_err(|_| ToolError::ExecutionError("Invalid cache path".into()))?
|
||||
.to_string();
|
||||
|
||||
let resource = Resource::new(
|
||||
uri.clone(),
|
||||
Some(mime_type.to_string()),
|
||||
Some(cache_path.to_string_lossy().into_owned()),
|
||||
)
|
||||
.map_err(|e| ToolError::ExecutionError(e.to_string()))?;
|
||||
|
||||
self.active_resources.lock().unwrap().insert(uri, resource);
|
||||
let mut resource = RawResource::new(uri.clone(), cache_path.to_string_lossy().into_owned());
|
||||
resource.mime_type = Some(if mime_type == "blob" {
|
||||
"blob".to_string()
|
||||
} else {
|
||||
"text".to_string()
|
||||
});
|
||||
self.active_resources
|
||||
.lock()
|
||||
.unwrap()
|
||||
.insert(uri, resource.no_annotation());
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -1175,17 +1176,17 @@ impl Router for ComputerControllerRouter {
|
||||
.to_file_path()
|
||||
.map_err(|_| ResourceError::NotFound("Invalid file path in URI".into()))?;
|
||||
|
||||
match resource.mime_type.as_str() {
|
||||
"text" | "json" => fs::read_to_string(&path).map_err(|e| {
|
||||
match resource.raw.mime_type.as_deref() {
|
||||
Some("text") | Some("json") | None => fs::read_to_string(&path).map_err(|e| {
|
||||
ResourceError::ExecutionError(format!("Failed to read file: {}", e))
|
||||
}),
|
||||
"binary" => {
|
||||
Some("binary") => {
|
||||
let bytes = fs::read(&path).map_err(|e| {
|
||||
ResourceError::ExecutionError(format!("Failed to read file: {}", e))
|
||||
})?;
|
||||
Ok(base64::prelude::BASE64_STANDARD.encode(bytes))
|
||||
}
|
||||
mime_type => Err(ResourceError::NotFound(format!(
|
||||
Some(mime_type) => Err(ResourceError::NotFound(format!(
|
||||
"Unsupported mime type: {}",
|
||||
mime_type
|
||||
))),
|
||||
|
||||
@@ -26,12 +26,11 @@ use mcp_core::tool::ToolAnnotations;
|
||||
use mcp_core::{
|
||||
handler::{PromptError, ResourceError, ToolError},
|
||||
protocol::{JsonRpcMessage, JsonRpcNotification, ServerCapabilities},
|
||||
resource::Resource,
|
||||
tool::Tool,
|
||||
};
|
||||
use mcp_server::router::CapabilitiesBuilder;
|
||||
use mcp_server::Router;
|
||||
use rmcp::model::{Content, Prompt, PromptArgument, PromptTemplate};
|
||||
use rmcp::model::{Content, Prompt, PromptArgument, PromptTemplate, Resource};
|
||||
|
||||
use rmcp::model::Role;
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ use mcp_core::protocol::JsonRpcMessage;
|
||||
use mcp_core::tool::ToolAnnotations;
|
||||
use oauth_pkce::PkceOAuth2Client;
|
||||
use regex::Regex;
|
||||
use rmcp::model::{Content, Prompt};
|
||||
use rmcp::model::{AnnotateAble, Content, Prompt, RawResource, Resource};
|
||||
use serde_json::{json, Value};
|
||||
use std::io::Cursor;
|
||||
use std::{env, fs, future::Future, path::Path, pin::Pin, sync::Arc};
|
||||
@@ -21,7 +21,6 @@ use tokio::sync::mpsc;
|
||||
use mcp_core::{
|
||||
handler::{PromptError, ResourceError, ToolError},
|
||||
protocol::ServerCapabilities,
|
||||
resource::Resource,
|
||||
tool::Tool,
|
||||
};
|
||||
use mcp_server::router::CapabilitiesBuilder;
|
||||
@@ -1888,12 +1887,15 @@ impl GoogleDriveRouter {
|
||||
Ok(r) => {
|
||||
r.1.files
|
||||
.map(|files| {
|
||||
files.into_iter().map(|f| Resource {
|
||||
uri: f.id.unwrap_or_default(),
|
||||
mime_type: f.mime_type.unwrap_or_default(),
|
||||
name: f.name.unwrap_or_default(),
|
||||
description: None,
|
||||
annotations: None,
|
||||
files.into_iter().map(|f| {
|
||||
RawResource {
|
||||
uri: f.id.unwrap_or_default(),
|
||||
mime_type: f.mime_type,
|
||||
name: f.name.unwrap_or_default(),
|
||||
description: None,
|
||||
size: None,
|
||||
}
|
||||
.no_annotation()
|
||||
})
|
||||
})
|
||||
.into_iter()
|
||||
|
||||
@@ -15,12 +15,11 @@ use tokio::sync::mpsc;
|
||||
use mcp_core::{
|
||||
handler::{PromptError, ResourceError, ToolError},
|
||||
protocol::{JsonRpcMessage, ServerCapabilities},
|
||||
resource::Resource,
|
||||
tool::{Tool, ToolAnnotations, ToolCall},
|
||||
};
|
||||
use mcp_server::router::CapabilitiesBuilder;
|
||||
use mcp_server::Router;
|
||||
use rmcp::model::{Content, Prompt};
|
||||
use rmcp::model::{Content, Prompt, Resource};
|
||||
|
||||
// MemoryRouter implementation
|
||||
#[derive(Clone)]
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
use anyhow::Result;
|
||||
use include_dir::{include_dir, Dir};
|
||||
use indoc::formatdoc;
|
||||
use rmcp::model::{Content, Prompt, Role};
|
||||
use rmcp::model::{Content, Prompt, Resource, Role};
|
||||
use serde_json::{json, Value};
|
||||
use std::{future::Future, pin::Pin};
|
||||
use tokio::sync::mpsc;
|
||||
@@ -9,7 +9,6 @@ use tokio::sync::mpsc;
|
||||
use mcp_core::{
|
||||
handler::{PromptError, ResourceError, ToolError},
|
||||
protocol::{JsonRpcMessage, ServerCapabilities},
|
||||
resource::Resource,
|
||||
tool::{Tool, ToolAnnotations},
|
||||
};
|
||||
use mcp_server::router::CapabilitiesBuilder;
|
||||
|
||||
Reference in New Issue
Block a user