Commit 1e27822

mo khan <mo@mokhan.ca>
2025-08-15 15:33:06
refactor: use mime package
1 parent 519f3fb
Changed files (1)
pkg
filesystem
pkg/filesystem/server.go
@@ -3,6 +3,7 @@ package filesystem
 import (
   "encoding/json"
   "fmt"
+  "mime"
   "os"
   "path/filepath"
   "strings"
@@ -175,18 +176,24 @@ func (fs *Server) ListResources() []mcp.Resource {
 func (fs *Server) discoverFiles(dirPath string) []mcp.Resource {
   var resources []mcp.Resource
   
-  exts := map[string]string{
-    ".go": "text/x-go", ".js": "text/javascript", ".ts": "text/typescript", 
-    ".py": "text/x-python", ".rs": "text/x-rust", ".java": "text/x-java",
-    ".c": "text/x-c", ".cpp": "text/x-c++", ".h": "text/x-c", ".hpp": "text/x-c++",
-    ".md": "text/markdown", ".txt": "text/plain", ".json": "application/json",
-    ".xml": "application/xml", ".yaml": "application/x-yaml", ".yml": "application/x-yaml",
-    ".html": "text/html", ".css": "text/css", ".sh": "text/x-shellscript",
+  programmingMimeTypes := map[string]string{
+    ".go": "text/x-go", 
+    ".rs": "text/x-rust", 
+    ".py": "text/x-python",
+    ".java": "text/x-java",
+    ".c": "text/x-c", 
+    ".cpp": "text/x-c++", 
+    ".h": "text/x-c", 
+    ".hpp": "text/x-c++",
+    ".sh": "text/x-shellscript",
   }
   
-  files := map[string]string{
-    "Makefile": "text/x-makefile", "README": "text/plain", "LICENSE": "text/plain",
-    "package.json": "application/json", "go.mod": "text/x-go-mod", "Cargo.toml": "application/toml",
+  specialFiles := map[string]string{
+    "Makefile": "text/x-makefile", 
+    "README": "text/plain", 
+    "LICENSE": "text/plain",
+    "go.mod": "text/x-go-mod", 
+    "Cargo.toml": "application/toml",
   }
   
   const maxFiles = 500
@@ -219,12 +226,16 @@ func (fs *Server) discoverFiles(dirPath string) []mcp.Resource {
     ext := strings.ToLower(filepath.Ext(fileName))
     
     var mimeType string
-    var isProgFile bool
     
-    if mimeType, isProgFile = exts[ext]; isProgFile {
-    } else if mimeType, isProgFile = files[fileName]; isProgFile {
+    if progType, exists := programmingMimeTypes[ext]; exists {
+      mimeType = progType
+    } else if specialType, exists := specialFiles[fileName]; exists {
+      mimeType = specialType
     } else {
-      return nil
+      mimeType = mime.TypeByExtension(ext)
+      if mimeType == "" {
+        return nil
+      }
     }
     
     fileURI := "file://" + path