Skip to content

fix: attach UTF-8 files with an unregistered extension as text - #1115

Merged
evalstate merged 2 commits into
evalstate:mainfrom
shlokbam:fix/unknown-text-files-as-text
Nov 25, 2026
Merged

evalstate merged 2 commits into
evalstate:mainfrom
shlokbam:fix/unknown-text-files-as-text

Conversation

@shlokbam

Copy link
Copy Markdown
Contributor

Fixes #1114

MCPFile and load_resource_content treat a file as binary when mimetypes doesn'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) to mime_utils. It returns the extension's type as before, except when that's application/octet-stream and the file's bytes are UTF-8 without NUL bytes, in which case it returns text/plain. MCPFile (only when no mime_type is passed) and load_resource_content use 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:

  • New tests/unit/fast_agent/mcp/test_unregistered_text_files.py: .go, .tsx and .yaml files through MCPFile and load_resource_content become 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).
  • With the change, the OpenAI converter sends main.go as <fastagent:file title="main.go" mimetype="text/plain">…</fastagent:file> with the code.
  • ruff check and ruff format --check (0.17.5) pass on the changed files. I did not run ty.

shlokbam and others added 2 commits November 24, 2026 22:20
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.
@evalstate
evalstate merged commit 184ffe0 into evalstate:main Nov 25, 2026
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Text files whose extension Python doesn't know (.go, .tsx, .yaml) are attached as binary, so the model never sees them

2 participants