Repository navigation
fix: attach UTF-8 files with an unregistered extension as text - #1115
Merged
evalstate merged 2 commits intoNov 25, 2026
Merged
Conversation
mimetypes has no type for many source and config files (.go, .tsx, .yaml on macOS), so MCPFile and prompt resources sent them as application/octet-stream blobs, which the provider converters replace with a placeholder. When the extension's type is unknown and the content is UTF-8 without NUL bytes, use text/plain.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1114
MCPFileandload_resource_contenttreat a file as binary whenmimetypesdoesn't know its extension (.go,.tsx,.yaml, … on macOS). The converters then replace it with a "binary resource" or "unsupported format" placeholder, so the model never sees the file.This adds
guess_file_mime_type(path)tomime_utils. It returns the extension's type as before, except when that'sapplication/octet-streamand the file's bytes are UTF-8 without NUL bytes, in which case it returnstext/plain.MCPFile(only when nomime_typeis passed) andload_resource_contentuse it. Files with a known type, and real binary files with an unknown extension, are handled as before..ts(video/mp2t) is left as it is; see the issue.Testing:
tests/unit/fast_agent/mcp/test_unregistered_text_files.py:.go,.tsxand.yamlfiles throughMCPFileandload_resource_contentbecome text (6 cases, fail on main), and two binary files with an unknown extension stay binary (pass on both).test_resource_utils.py,test_mime_utils.py,test_mcp_prompt_resource_like.py,tests/unit/fast_agent/mcp/prompts/: 64 passed with the new tests (58 on main, plus the 6 failures).main.goas<fastagent:file title="main.go" mimetype="text/plain">…</fastagent:file>with the code.ruff checkandruff format --check(0.17.5) pass on the changed files. I did not runty.