Skip to content

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

Done

Description

@shlokbam

MCPFile and prompt-template resources pick text or binary from mimetypes.guess_type. Python's table has no entry for many common source and config files, so guess_mime_type returns application/octet-stream and the file is sent as a base64 blob. The provider converters then replace it with a placeholder, and the model gets no content:

from pathlib import Path
from fast_agent.mcp.mcp_content import MCPFile

res = MCPFile(Path("main.go"))["content"].resource
print(type(res).__name__, res.mime_type)
# BlobResourceContents application/octet-stream

OpenAI converter output for "Review this file" plus main.go:

{"type": "text", "text": "[Binary resource: main.go (application/octet-stream)]"}

The Anthropic converter gives Embedded Resource file:///…/main.go with unsupported format application/octet-stream (N characters).

On macOS with Python 3.13, mimetypes has no type for .go, .tsx, .jsx, .yaml, .toml, .kt, .swift, .rb, .php, .vue or .ipynb, among others. On Linux the result also depends on whether /etc/mime.types exists, which slim containers often don't have. The same applies to @file mentions of local files in interactive mode, which go through MCPFile, and to resources in prompt templates (load_resource_content).

This is the same symptom as #1025, which fixed it for XML with a charset parameter.

I found this by reading mime_utils.py and checking which extensions mimetypes knows, not while using fast-agent on a project.

A related case I left out of the PR: .ts is registered as video/mp2t (MPEG transport stream), so TypeScript files are sent as video blobs too. Changing that means overriding .ts globally, so that's your call.

Also, on Linux even known types like .rb (application/x-ruby) are treated as binary, because they're not in TEXT_MIME_TYPES.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions