Skip to content

.ts typescript files get detected as video/mp2t #13

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
joidegn opened this issue Apr 30, 2025 · 2 comments
Open

.ts typescript files get detected as video/mp2t #13

joidegn opened this issue Apr 30, 2025 · 2 comments

Comments

@joidegn
Copy link

joidegn commented Apr 30, 2025

I have been using the mcp server pretty extensively to power coding with Claude.

One issue I have seen claude run into a lot is that .ts files get identified as video/mp2t.

For example here from the logs:

==> /Users/johannesdegn/Library/Logs/Claude/mcp.log <==
2025-04-29T13:27:51.014Z [info] [filesystem] Message from server: {"jsonrpc":"2.0","id":227,"result":{"content":[{"type":"text","text":"Binary file: /Users/johannesdegn/subledger/web/projects/accounting/src/page/Reconciliations/store.ts (video/mp2t, 1649 bytes)"},{"type":"resource","resource":{"uri":"file:///Users/johannesdegn/subledger/web/projects/accounting/src/page/Reconciliations/store.ts","mimeType":"video/mp2t","blob":"<the file blob>"}}]}}

This is because mime.TypeByExtension(ext) identifies .ts files like that. I hacked it by adding this just to solve my direct use case in detectMimeType:

		if mimeType != "" && mimeType != "video/mp2t" {
			return mimeType
		}

Im not sure what a proper solution should be, just thought I'd let you know

Here is detectMimeType with this little hack.

// detectMimeType tries to determine the MIME type of a file
func detectMimeType(path string) string {
	// First try by extension
	ext := filepath.Ext(path)
	if ext != "" {
		mimeType := mime.TypeByExtension(ext)
		if mimeType != "" && mimeType != "video/mp2t" {
			return mimeType
		}
	}

	// If that fails, try to read a bit of the file
	file, err := os.Open(path)
	if err != nil {
		return "application/octet-stream" // Default
	}
	defer file.Close()

	// Read first 512 bytes to detect content type
	buffer := make([]byte, 512)
	n, err := file.Read(buffer)
	if err != nil {
		return "application/octet-stream" // Default
	}

	// Use http.DetectContentType
	return http.DetectContentType(buffer[:n])
}
@ezynda3
Copy link
Contributor

ezynda3 commented May 1, 2025

If you create a PR for this I would be happy to merge it :)

@joidegn
Copy link
Author

joidegn commented May 3, 2025

Maybe like this?

#14

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

No branches or pull requests

2 participants