1. Overview
Media is awkward over REST — multipart bodies, large payloads, derivatives. MCP smooths it: media.upload returns a stable attachment id you can use with later tools.
2. AI enhancement
Where AI helps
Generate alt text on upload (a11y win). Suggest captions. Detect duplicates by perceptual hash. Reject blurry images.
3. Upload tool
tools/media.upload.ts typescript
server.tool('media.upload', 'Upload an image with AI-generated alt text.', {
url: z.string().url(),
title: z.string().optional(),
}, async ({ url, title }) => {
const blob = await fetch(url).then(r => r.blob())
const form = new FormData()
form.set('file', blob, title ?? 'upload.png')
const wp = await wpPost('/wp/v2/media', form)
const alt = await visionDescribe(blob)
await wpPatch(`/wp/v2/media/${wp.id}`, { alt_text: alt })
return { content: [{ type:'text', text: `Uploaded #${wp.id} • alt: ${alt}` }] }
}) 4. Metadata & AI
Request
request.json json
{ "name":"media.upload", "arguments": { "url":"https://example.com/hero.jpg" } } Response
response.json json
{ "content":[{ "type":"text", "text":"Uploaded #482 • alt: A laptop on a wooden desk" }] } 5. Workflow example
Ask the agent to "import every image from this Google Doc and attach them to draft #128." With media.upload + posts.update, the whole workflow is two tool calls.