MW
Tutorial 10 min read

Media library tool — AI-powered uploads & metadata

Upload, transcode, caption, alt-text — every media operation as a typed MCP tool.

Media AI Uploads Alt text
Agent
media.*
WP Media

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

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.

Media that writes its own alt text

One MCP tool. Accessibility win. Bonus: duplicate detection for free.

  • AI-native
  • A11y
  • Composable