wp_update_media
Modify metadata for existing WordPress media items including title, alt text, caption, and description to improve content management and SEO.
Instructions
Updates the metadata of an existing media item.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| site | No | The ID of the WordPress site to target (from mcp-wordpress.config.json). Required if multiple sites are configured. | |
| id | Yes | The ID of the media item to update. | |
| title | No | The new title for the media item. | |
| alt_text | No | The new alternative text. | |
| caption | No | The new caption. | |
| description | No | The new description. |
Implementation Reference
- src/tools/media.ts:246-254 (handler)MCP tool handler for wp_update_media. Validates parameters, delegates to WordPressClient.updateMedia, returns success message or error.public async handleUpdateMedia(client: WordPressClient, params: Record<string, unknown>): Promise<unknown> { const updateParams = params as unknown as UpdateMediaRequest & { id: number }; try { const media = await client.updateMedia(updateParams); return `✅ Media ${media.id} updated successfully.`; } catch (_error) { throw new Error(`Failed to update media: ${getErrorMessage(_error)}`); } }
- src/tools/media.ts:142-174 (registration)Tool definition and registration within MediaTools.getTools(), including name, description, input parameters schema, and handler reference.{ name: "wp_update_media", description: "Updates the metadata of an existing media item.", parameters: [ { name: "id", type: "number", required: true, description: "The ID of the media item to update.", }, { name: "title", type: "string", description: "The new title for the media item.", }, { name: "alt_text", type: "string", description: "The new alternative text.", }, { name: "caption", type: "string", description: "The new caption.", }, { name: "description", type: "string", description: "The new description.", }, ], handler: this.handleUpdateMedia.bind(this), },
- src/types/wordpress.ts:510-519 (schema)TypeScript interface UpdateMediaRequest defining the structure of input parameters for media updates, imported and used in the tool handler.export interface UpdateMediaRequest { id: number; title?: string; alt_text?: string; caption?: string; description?: string; post?: number; status?: PostStatus; author?: number; }
- Low-level helper that destructures the id and performs the actual HTTP PUT request to WordPress REST API endpoint /wp/v2/media/{id}.async updateMedia(data: UpdateMediaRequest): Promise<WordPressMedia> { const { id, ...updateData } = data; return this.client.put<WordPressMedia>(`media/${id}`, updateData); }
- src/server/ToolRegistry.ts:45-62 (registration)Generic registration of all tools including MediaTools (which contains wp_update_media) by instantiating tool classes and calling getTools() to register each with the MCP server.public registerAllTools(): void { // Register all tools from the tools directory Object.values(Tools).forEach((ToolClass) => { let toolInstance: { getTools(): unknown[] }; // Cache and Performance tools need the clients map if (ToolClass.name === "CacheTools" || ToolClass.name === "PerformanceTools") { toolInstance = new ToolClass(this.wordpressClients); } else { toolInstance = new (ToolClass as new () => { getTools(): unknown[] })(); } const tools = toolInstance.getTools(); tools.forEach((tool: unknown) => { this.registerTool(tool as ToolDefinition); }); });