Skip to content

fix(mcp): leave the media type out when the URL has no known extension - #102

Merged
Zernio-Elean merged 3 commits into
developfrom
fix/mcp-untyped-unknown-extension
Nov 18, 2026
Merged

Zernio-Elean merged 3 commits into
developfrom
fix/mcp-untyped-unknown-extension

Conversation

@Zernio-Elean

Copy link
Copy Markdown
Contributor

Why

The ChatGPT connector (and posts_create / posts_cross_post) sent type: "image" for any media URL without a known extension. A Google Drive link to an MP4 went out as an image: the API rehosts it as .mp4 and rejects the image type on create ("Media type mismatch"), and validate runs the TikTok image check ("unrecognized file format"). Customer report: Crisp session_d8f442e1, SUP-2031.

What

  • New late/mcp/media_items.py media_item(url): typed only when the path extension proves it (video, gif, pdf as document, known image extensions); any other URL is sent without type, which the API infers (documented in createPost).
  • chatgpt_server._media_items, server.posts_create and server.posts_cross_post use it. server.py now matches the path suffix instead of a substring (so a.movie.com/x.jpg is no longer sent as video).
  • Tests: unit cases for the ChatGPT helper, and both server.py tools checked on the outgoing request body.

@Zernio-Elean

Copy link
Copy Markdown
Contributor Author

pr-review (fresh context): APPROVE

Checked: diff at 84e6334, the API side in Schedule-Posts-API (create.ts rehost then normalizeMediaTypes, update-existing-post.ts same order, media-processor.ts guessMediaType, /v1/tools/validate/post), tests run locally (17 passed), ruff clean, no em dashes, PR body has no attribution line, scope limited to the fix.

Correctness

  • Drive link without type: create (create.ts ~934) and update (update-existing-post.ts ~143) rehost Drive to a file with a real extension before normalizeMediaTypes, which fills the missing type from that extension. The "Media type mismatch" on a Drive MP4 goes away on both POST /v1/posts and PUT /v1/posts/{id} (ChatGPT edit tool also goes through _media_items).
  • Extensionless image CDNs (e.g. images.example.com/photo/123?w=800): before, sent type: image; now untyped, and guessMediaType defaults unknown to image. Same stored result, no regression on create/update.
  • Nothing in the MCP reads item["type"] downstream (only len(media_items) in the summary text and m["url"] in _shape_post). MediaType import removal is clean.

Notes (non-blocking)

  1. src/late/mcp/media_items.py:8 / server.py:900,1002: substring to suffix-after-? changes one case for the worse. Old server.py typed https://host/download?file=clip.mp4 as video (substring hit); now it is untyped, guessMediaType returns image, and the API stores it as image (the API "trusts the caller" only when a type is given). Before, this URL worked via posts_create. Rare (extension only in the query), and the ChatGPT path already behaved this way, so I accept it; worth a line in the PR body.
  2. /v1/tools/validate/post does not call normalizeMediaTypes, so untyped items skip every type-based check there: TikTok image dimension checks no longer run for an extensionless image URL (validate passes, create may still fail later), and YouTube validate for a Drive MP4 still says "requires video content" (no regression, it said that with type: image too). API-side follow-up, out of this PR's scope.
  3. media_items.py:17 comment says the API infers the type "from the fetched file"; it infers from the URL extension (after Drive rehost), defaulting to image. Comment policy note only.
  4. Tests: test_chatgpt_server.py parametrized case and test_mcp_media_items.py both assert the outgoing body, which is the right level. No gif case and no #fragment case; optional.

Verdict: APPROVE.

The MCP servers sent type "image" for any media URL without a video, gif
or pdf extension, so a Google Drive link to an MP4 went out as an image.
The API then rehosts the Drive file as .mp4 and rejects the explicit
image type on create, and validate runs the TikTok image check on it.

Media items are now typed only when the extension proves it (video, gif,
document, image); any other URL is sent without type and the API infers
it. One helper serves the ChatGPT server and posts_create/posts_cross_post.
@Zernio-Elean
Zernio-Elean force-pushed the fix/mcp-untyped-unknown-extension branch from 990bc7a to 1a0e0c6 Compare November 18, 2026 14:59
@Zernio-Elean
Zernio-Elean force-pushed the fix/mcp-untyped-unknown-extension branch from 1a0e0c6 to 4a6b47c Compare November 18, 2026 15:05
@Zernio-Elean
Zernio-Elean merged commit abd63d0 into develop Nov 18, 2026
4 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.

1 participant