Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion crates/rmcp/src/handler/server/skill_catalog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,8 @@ impl SkillCatalog {
.mime_type
.is_some_and(is_textual)
.then(|| std::str::from_utf8(&file.bytes).ok())
.flatten();
.flatten()
.filter(|text| !text.contains('\0'));

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I went with a NUL check instead of trying to detect the charset from a BOM or XML declaration. We still don't transcode, and readable text shouldn't contain \0, so treating it as a blob is the safer fallback.

let contents = match text {
Some(text) => ResourceContents::text(text, uri),
None => ResourceContents::blob(BASE64_STANDARD.encode(&file.bytes), uri),
Expand Down
21 changes: 21 additions & 0 deletions crates/rmcp/tests/test_skill_catalog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,27 @@ mod serving {
));
}

#[test]
fn should_serve_a_text_type_containing_nul_as_a_blob() {
let dir = skills_tree();
let utf16le: Vec<u8> = "<a/>".bytes().flat_map(|b| [b, 0]).collect();
write(dir.path(), "pdf-processing/form.xml", &utf16le);
let catalog = load(&dir);

let result = catalog
.read_resource("skill://pdf-processing/form.xml")
.expect("served");

assert!(matches!(
&result.contents[0],
ResourceContents::BlobResourceContents { mime_type: Some(mime), .. } if mime == "application/xml"
));
assert_eq!(
read_bytes(&catalog, "skill://pdf-processing/form.xml"),
utf16le
);
}

#[test]
fn should_omit_the_mime_type_of_an_unknown_extension() {
let dir = skills_tree();
Expand Down
Loading