Replace mcp_core::resource::* with rmcp types (#3563)
This commit is contained in:
@@ -20,7 +20,7 @@ use crate::prompt_template;
|
||||
use mcp_client::client::{ClientCapabilities, ClientInfo, McpClient, McpClientTrait};
|
||||
use mcp_client::transport::{SseTransport, StdioTransport, StreamableHttpTransport, Transport};
|
||||
use mcp_core::{Tool, ToolCall, ToolError};
|
||||
use rmcp::model::{Content, Prompt};
|
||||
use rmcp::model::{Content, Prompt, Resource, ResourceContents};
|
||||
use serde_json::Value;
|
||||
|
||||
// By default, we set it to Jan 1, 2020 if the resource does not have a timestamp
|
||||
@@ -427,23 +427,15 @@ impl ExtensionManager {
|
||||
for resource in resources.resources {
|
||||
// Skip reading the resource if it's not marked active
|
||||
// This avoids blowing up the context with inactive resources
|
||||
if !resource.is_active() {
|
||||
if !resource_is_active(&resource) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if let Ok(contents) = client_guard.read_resource(&resource.uri).await {
|
||||
for content in contents.contents {
|
||||
let (uri, content_str) = match content {
|
||||
mcp_core::resource::ResourceContents::TextResourceContents {
|
||||
uri,
|
||||
text,
|
||||
..
|
||||
} => (uri, text),
|
||||
mcp_core::resource::ResourceContents::BlobResourceContents {
|
||||
uri,
|
||||
blob,
|
||||
..
|
||||
} => (uri, blob),
|
||||
ResourceContents::TextResourceContents { uri, text, .. } => (uri, text),
|
||||
ResourceContents::BlobResourceContents { uri, blob, .. } => (uri, blob),
|
||||
};
|
||||
|
||||
result.push(ResourceItem::new(
|
||||
@@ -550,8 +542,7 @@ impl ExtensionManager {
|
||||
let mut result = Vec::new();
|
||||
for content in read_result.contents {
|
||||
// Only reading the text resource content; skipping the blob content cause it's too long
|
||||
if let mcp_core::resource::ResourceContents::TextResourceContents { text, .. } = content
|
||||
{
|
||||
if let ResourceContents::TextResourceContents { text, .. } = content {
|
||||
let content_str = format!("{}\n\n{}", uri, text);
|
||||
result.push(Content::text(content_str));
|
||||
}
|
||||
@@ -825,6 +816,10 @@ impl ExtensionManager {
|
||||
}
|
||||
}
|
||||
|
||||
fn resource_is_active(resource: &Resource) -> bool {
|
||||
resource.priority().is_some_and(|p| (p - 1.0).abs() < 1e-6)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
Reference in New Issue
Block a user