update to RMCP 0.6.2 (#4523)

This commit is contained in:
Max Novich
2025-09-05 06:54:10 -07:00
committed by GitHub
parent 0db329bac4
commit 195f389972
24 changed files with 191 additions and 24 deletions
@@ -95,9 +95,10 @@ impl McpClientTrait for MockClient {
if let Some(handler) = self.handlers.get(name) {
match handler(&arguments) {
Ok(content) => Ok(CallToolResult {
content: content,
content,
is_error: None,
structured_content: None,
meta: None,
}),
Err(_e) => Err(Error::UnexpectedResponse),
}
+20
View File
@@ -256,6 +256,7 @@ pub fn tool_response_to_markdown(resp: &ToolResponse, export_all_content: bool)
uri,
mime_type,
text,
meta: _,
} => {
// Extract file extension from the URI for syntax highlighting
let file_extension = uri.split('.').next_back().unwrap_or("");
@@ -287,6 +288,7 @@ pub fn tool_response_to_markdown(resp: &ToolResponse, export_all_content: bool)
uri,
mime_type,
blob,
..
} => {
md.push_str(&format!(
"**Binary File:** `{}` (type: {}, {} bytes)\n\n",
@@ -297,6 +299,10 @@ pub fn tool_response_to_markdown(resp: &ToolResponse, export_all_content: bool)
}
}
}
RawContent::ResourceLink(_link) => {
// Show a simple placeholder for resource links when exporting
md.push_str("[resource link]\n\n");
}
RawContent::Audio(_) => {
md.push_str("[audio content not displayed in Markdown export]\n\n")
}
@@ -527,6 +533,7 @@ mod tests {
let text_content = TextContent {
raw: RawTextContent {
text: "Command executed successfully".to_string(),
meta: None,
},
annotations: None,
};
@@ -546,6 +553,7 @@ mod tests {
let text_content = TextContent {
raw: RawTextContent {
text: json_text.to_string(),
meta: None,
},
annotations: None,
};
@@ -650,6 +658,7 @@ if __name__ == "__main__":
let text_content = TextContent {
raw: RawTextContent {
text: python_code.to_string(),
meta: None,
},
annotations: None,
};
@@ -689,6 +698,7 @@ if __name__ == "__main__":
let text_content = TextContent {
raw: RawTextContent {
text: git_output.to_string(),
meta: None,
},
annotations: None,
};
@@ -736,6 +746,7 @@ warning: unused variable `x`
let text_content = TextContent {
raw: RawTextContent {
text: build_output.to_string(),
meta: None,
},
annotations: None,
};
@@ -781,6 +792,7 @@ warning: unused variable `x`
let text_content = TextContent {
raw: RawTextContent {
text: api_response.to_string(),
meta: None,
},
annotations: None,
};
@@ -815,6 +827,7 @@ warning: unused variable `x`
let text_content = TextContent {
raw: RawTextContent {
text: "File created successfully".to_string(),
meta: None,
},
annotations: None,
};
@@ -870,6 +883,7 @@ def process_data(data: List[Dict]) -> List[Dict]:
let text_content = TextContent {
raw: RawTextContent {
text: python_code.to_string(),
meta: None,
},
annotations: None,
};
@@ -905,6 +919,7 @@ Command failed with exit code 2"#;
let text_content = TextContent {
raw: RawTextContent {
text: error_output.to_string(),
meta: None,
},
annotations: None,
};
@@ -943,6 +958,7 @@ Command failed with exit code 2"#;
let text_content = TextContent {
raw: RawTextContent {
text: script_output.to_string(),
meta: None,
},
annotations: None,
};
@@ -988,6 +1004,7 @@ drwx------ 3 user staff 96 Dec 6 16:20 com.apple.launchd.abc
let text_content = TextContent {
raw: RawTextContent {
text: multi_output.to_string(),
meta: None,
},
annotations: None,
};
@@ -1029,6 +1046,7 @@ src/middleware.rs:12:async fn auth_middleware(req: Request, next: Next) -> Resul
let text_content = TextContent {
raw: RawTextContent {
text: grep_output.to_string(),
meta: None,
},
annotations: None,
};
@@ -1067,6 +1085,7 @@ src/middleware.rs:12:async fn auth_middleware(req: Request, next: Next) -> Resul
let text_content = TextContent {
raw: RawTextContent {
text: json_output.to_string(),
meta: None,
},
annotations: None,
};
@@ -1106,6 +1125,7 @@ found 0 vulnerabilities"#;
let text_content = TextContent {
raw: RawTextContent {
text: npm_output.to_string(),
meta: None,
},
annotations: None,
};
+12 -4
View File
@@ -642,6 +642,7 @@ impl AutoVisualiserRouter {
uri: "ui://sankey/diagram".to_string(),
mime_type: Some("text/html".to_string()),
blob: base64_encoded,
meta: None,
};
Ok(vec![
@@ -686,6 +687,7 @@ impl AutoVisualiserRouter {
uri: "ui://radar/chart".to_string(),
mime_type: Some("text/html".to_string()),
blob: base64_encoded,
meta: None,
};
Ok(vec![
@@ -730,6 +732,7 @@ impl AutoVisualiserRouter {
uri: "ui://treemap/visualization".to_string(),
mime_type: Some("text/html".to_string()),
blob: base64_encoded,
meta: None,
};
Ok(vec![
@@ -774,6 +777,7 @@ impl AutoVisualiserRouter {
uri: "ui://chord/diagram".to_string(),
mime_type: Some("text/html".to_string()),
blob: base64_encoded,
meta: None,
};
Ok(vec![
@@ -818,6 +822,7 @@ impl AutoVisualiserRouter {
uri: "ui://donut/chart".to_string(),
mime_type: Some("text/html".to_string()),
blob: base64_encoded,
meta: None,
};
Ok(vec![
@@ -879,6 +884,7 @@ impl AutoVisualiserRouter {
uri: "ui://map/visualization".to_string(),
mime_type: Some("text/html".to_string()),
blob: base64_encoded,
meta: None,
};
Ok(vec![
@@ -923,6 +929,7 @@ impl AutoVisualiserRouter {
uri: "ui://chart/interactive".to_string(),
mime_type: Some("text/html".to_string()),
blob: base64_encoded,
meta: None,
};
Ok(vec![
@@ -1175,8 +1182,8 @@ mod tests {
assert_eq!(content[0].audience().unwrap(), &vec![Role::User]);
// Check it's a resource with HTML content
// Content is Annotated<RawContent>, deref to get RawContent
if let RawContent::Resource(resource) = &**&content[0] {
// Content is Annotated<RawContent>, access underlying RawContent via *
if let RawContent::Resource(resource) = &*content[0] {
if let ResourceContents::BlobResourceContents { uri, mime_type, .. } =
&resource.resource
{
@@ -1212,12 +1219,13 @@ mod tests {
assert_eq!(content[0].audience().unwrap(), &vec![Role::User]);
// Check it's a resource with HTML content
// Content is Annotated<RawContent>, deref to get RawContent
if let RawContent::Resource(resource) = &**&content[0] {
// Content is Annotated<RawContent>, access underlying RawContent via *
if let RawContent::Resource(resource) = &*content[0] {
if let ResourceContents::BlobResourceContents {
uri,
mime_type,
blob,
..
} = &resource.resource
{
assert_eq!(uri, "ui://radar/chart");
@@ -3,7 +3,7 @@ use ignore::gitignore::{Gitignore, GitignoreBuilder};
use include_dir::{include_dir, Dir};
use indoc::{formatdoc, indoc};
use rmcp::{
handler::server::{router::tool::ToolRouter, tool::Parameters},
handler::server::{router::tool::ToolRouter, wrapper::Parameters},
model::{
CallToolResult, Content, ErrorCode, ErrorData, GetPromptRequestParam, GetPromptResult,
Implementation, ListPromptsResult, LoggingLevel, LoggingMessageNotificationParam,
@@ -1242,7 +1242,7 @@ impl DeveloperServer {
#[cfg(test)]
mod tests {
use super::*;
use rmcp::handler::server::tool::Parameters;
use rmcp::handler::server::wrapper::Parameters;
use rmcp::model::NumberOrString;
use rmcp::service::serve_directly;
use serial_test::serial;
+3 -1
View File
@@ -9,7 +9,7 @@ use goose::session::info::SessionInfo;
use goose::session::SessionMetadata;
use rmcp::model::{
Annotations, Content, EmbeddedResource, ImageContent, RawEmbeddedResource, RawImageContent,
RawTextContent, ResourceContents, Role, TextContent, Tool, ToolAnnotations,
RawResource, RawTextContent, ResourceContents, Role, TextContent, Tool, ToolAnnotations,
};
use utoipa::{OpenApi, ToSchema};
@@ -319,6 +319,7 @@ derive_utoipa!(TextContent as TextContentSchema);
derive_utoipa!(RawTextContent as RawTextContentSchema);
derive_utoipa!(RawImageContent as RawImageContentSchema);
derive_utoipa!(RawEmbeddedResource as RawEmbeddedResourceSchema);
derive_utoipa!(RawResource as RawResourceSchema);
derive_utoipa!(Tool as ToolSchema);
derive_utoipa!(ToolAnnotations as ToolAnnotationsSchema);
derive_utoipa!(Annotations as AnnotationsSchema);
@@ -425,6 +426,7 @@ impl<'__s> ToSchema<'__s> for AnnotatedSchema {
RawTextContentSchema,
RawImageContentSchema,
RawEmbeddedResourceSchema,
RawResourceSchema,
AnnotatedSchema,
ToolResponse,
ToolRequest,
+2
View File
@@ -21,7 +21,9 @@ rmcp = { workspace = true, features = [
"reqwest",
"transport-child-process",
"transport-sse-client",
"transport-sse-client-reqwest",
"transport-streamable-http-client",
"transport-streamable-http-client-reqwest",
] }
anyhow = "1.0"
thiserror = "1.0"
@@ -1154,6 +1154,7 @@ mod tests {
content: vec![],
is_error: None,
structured_content: None,
meta: None,
}),
_ => Err(Error::TransportClosed),
}
@@ -255,6 +255,7 @@ mod tests {
vec![MessageContent::Text(
RawTextContent {
text: "Summary of conversation".to_string(),
meta: None,
}
.no_annotation(),
)],
@@ -101,6 +101,7 @@ mod tests {
vec![MessageContent::Text(
RawTextContent {
text: "Summarized content".to_string(),
meta: None,
}
.no_annotation(),
)],
+24 -3
View File
@@ -168,7 +168,13 @@ impl fmt::Display for MessageContent {
impl MessageContent {
pub fn text<S: Into<String>>(text: S) -> Self {
MessageContent::Text(RawTextContent { text: text.into() }.no_annotation())
MessageContent::Text(
RawTextContent {
text: text.into(),
meta: None,
}
.no_annotation(),
)
}
pub fn image<S: Into<String>, T: Into<String>>(data: S, mime_type: T) -> Self {
@@ -176,6 +182,7 @@ impl MessageContent {
RawImageContent {
data: data.into(),
mime_type: mime_type.into(),
meta: None,
}
.no_annotation(),
)
@@ -317,6 +324,7 @@ impl From<Content> for MessageContent {
RawContent::Image(image) => {
MessageContent::Image(image.optional_annotate(content.annotations))
}
RawContent::ResourceLink(_link) => MessageContent::text("[Resource link]"),
RawContent::Resource(resource) => {
let text = match &resource.resource {
ResourceContents::TextResourceContents { text, .. } => text.clone(),
@@ -347,6 +355,7 @@ impl From<PromptMessage> for Message {
PromptMessageContent::Image { image } => {
MessageContent::image(image.data.clone(), image.mime_type.clone())
}
PromptMessageContent::ResourceLink { .. } => MessageContent::text("[Resource link]"),
PromptMessageContent::Resource { resource } => {
// For resources, convert to text content with the resource text
match &resource.resource {
@@ -445,6 +454,7 @@ impl Message {
self.with_content(MessageContent::Text(
RawTextContent {
text: sanitized_text,
meta: None,
}
.no_annotation(),
))
@@ -756,6 +766,7 @@ mod tests {
image: RawImageContent {
data: "base64data".to_string(),
mime_type: "image/jpeg".to_string(),
meta: None,
}
.no_annotation(),
};
@@ -781,10 +792,15 @@ mod tests {
uri: "file:///test.txt".to_string(),
mime_type: Some("text/plain".to_string()),
text: "Resource content".to_string(),
meta: None,
};
let prompt_content = PromptMessageContent::Resource {
resource: RawEmbeddedResource { resource }.no_annotation(),
resource: RawEmbeddedResource {
resource,
meta: None,
}
.no_annotation(),
};
let prompt_message = PromptMessage {
@@ -807,10 +823,15 @@ mod tests {
uri: "file:///test.bin".to_string(),
mime_type: Some("application/octet-stream".to_string()),
blob: "binary_data".to_string(),
meta: None,
};
let prompt_content = PromptMessageContent::Resource {
resource: RawEmbeddedResource { resource }.no_annotation(),
resource: RawEmbeddedResource {
resource,
meta: None,
}
.no_annotation(),
};
let prompt_message = PromptMessage {
+1
View File
@@ -221,6 +221,7 @@ mod tests {
"Response from {} with model {}",
self.name, self.model_config.model_name
),
meta: None,
}
.no_annotation(),
)],
@@ -124,6 +124,9 @@ pub fn to_bedrock_tool_result_content_block(
RawContent::Image(image) => {
bedrock::ToolResultContentBlock::Image(to_bedrock_image(&image.data, &image.mime_type)?)
}
RawContent::ResourceLink(_link) => {
bedrock::ToolResultContentBlock::Text("[Resource link]".to_string())
}
RawContent::Resource(resource) => match &resource.resource {
ResourceContents::TextResourceContents { text, .. } => {
match to_bedrock_document(tool_use_id, &resource.resource)? {
@@ -381,6 +384,7 @@ mod tests {
let image = RawImageContent {
data: TEST_IMAGE_BASE64.to_string(),
mime_type: mime_type.to_string(),
meta: None,
}
.no_annotation();
@@ -396,6 +400,7 @@ mod tests {
let image = RawImageContent {
data: TEST_IMAGE_BASE64.to_string(),
mime_type: "image/bmp".to_string(),
meta: None,
}
.no_annotation();
@@ -411,6 +416,7 @@ mod tests {
let image = RawImageContent {
data: "invalid_base64_data!!!".to_string(),
mime_type: "image/png".to_string(),
meta: None,
}
.no_annotation();
@@ -425,6 +431,7 @@ mod tests {
let image = RawImageContent {
data: TEST_IMAGE_BASE64.to_string(),
mime_type: "image/png".to_string(),
meta: None,
}
.no_annotation();
@@ -490,6 +490,7 @@ mod tests {
vec![MessageContent::Text(
RawTextContent {
text: format!("Response from {}", self.name),
meta: None,
}
.no_annotation(),
)],
@@ -656,6 +657,7 @@ mod tests {
vec![MessageContent::Text(
RawTextContent {
text: format!("Response from {}", self.name),
meta: None,
}
.no_annotation(),
)],
@@ -203,6 +203,7 @@ mod tests {
vec![MessageContent::Text(TextContent {
raw: RawTextContent {
text: self.response.clone(),
meta: None,
},
annotations: None,
})],
+1
View File
@@ -374,6 +374,7 @@ pub fn load_image_file(path: &str) -> Result<ImageContent, ProviderError> {
Ok(RawImageContent {
mime_type: mime_type.to_string(),
data,
meta: None,
}
.no_annotation())
}
+1
View File
@@ -1406,6 +1406,7 @@ mod tests {
vec![MessageContent::Text(
RawTextContent {
text: "Mocked scheduled response".to_string(),
meta: None,
}
.no_annotation(),
)],
+1
View File
@@ -277,6 +277,7 @@ impl ProviderTester {
let image_content = RawImageContent {
data: base64_image,
mime_type: "image/png".to_string(),
meta: None,
}
.no_annotation();
-2
View File
@@ -220,8 +220,6 @@ where
}
JsonRpcMessage::Response(_)
| JsonRpcMessage::Notification(_)
| JsonRpcMessage::BatchRequest(_)
| JsonRpcMessage::BatchResponse(_)
| JsonRpcMessage::Error(_) => {
// Ignore responses, notifications, batch messages and error messages for now
continue;
+1
View File
@@ -235,6 +235,7 @@ pub trait Router: Send + Sync + 'static {
uri: uri.to_string(),
mime_type: Some("text/plain".to_string()),
text: contents,
meta: None,
}],
};