diff --git a/.gitignore b/.gitignore index 0036855..e3aa019 100644 --- a/.gitignore +++ b/.gitignore @@ -29,6 +29,7 @@ CLAUDE.md AGENTS.md codex-workflow.md CODING_STANDARDS.md +tools/product-videos/ # Generated LLM docs internal/infrastructure/llmdocs/generated/* diff --git a/internal/infrastructure/mcpserver/server.go b/internal/infrastructure/mcpserver/server.go index 2abc34b..0f5093c 100644 --- a/internal/infrastructure/mcpserver/server.go +++ b/internal/infrastructure/mcpserver/server.go @@ -6,12 +6,15 @@ import ( "encoding/base64" "encoding/json" "fmt" + "mime" "mime/multipart" "net/http" + "net/textproto" "net/url" "os" "path/filepath" "strconv" + "strings" "github.com/modelcontextprotocol/go-sdk/mcp" ) @@ -228,7 +231,14 @@ func (s *server) uploadMedia(ctx context.Context, _ *mcp.CallToolRequest, in upl } var form bytes.Buffer writer := multipart.NewWriter(&form) - part, err := writer.CreateFormFile("file", name) + contentType, err := uploadMediaType(name) + if err != nil { + return nil, nil, err + } + header := make(textproto.MIMEHeader) + header.Set("Content-Disposition", mime.FormatMediaType("form-data", map[string]string{"name": "file", "filename": name})) + header.Set("Content-Type", contentType) + part, err := writer.CreatePart(header) if err != nil { return nil, nil, err } @@ -241,6 +251,21 @@ func (s *server) uploadMedia(ctx context.Context, _ *mcp.CallToolRequest, in upl return result(s.client.Do(ctx, http.MethodPost, "/v1/media/", nil, form.Bytes(), writer.FormDataContentType())) } +func uploadMediaType(filename string) (string, error) { + switch strings.ToLower(filepath.Ext(filename)) { + case ".png": + return "image/png", nil + case ".jpg", ".jpeg": + return "image/jpeg", nil + case ".webp": + return "image/webp", nil + case ".svg": + return "image/svg+xml", nil + default: + return "", fmt.Errorf("filename must end in .png, .jpg, .jpeg, .webp or .svg") + } +} + func uploadContent(in uploadMediaInput) (string, []byte, error) { switch { case in.Path != "" && in.Base64 != "":