wpnav_get_media
Retrieve a WordPress media item by ID to access its URL, dimensions, and file metadata for content management and integration purposes.
Instructions
Get a single media item by ID. Returns full metadata including URL, dimensions, and file info.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| id | Yes | WordPress media ID |
Implementation Reference
- src/tools/content/index.ts:732-746 (handler)Executes the wpnav_get_media tool: validates input ID, fetches media from WP REST API `/wp/v2/media/${id}`, extracts key fields (id, title, source_url, mime_type, alt_text, caption, description, media_details), formats as JSON, and returns as text content.handler: async (args, context) => { validateRequired(args, ['id']); const id = validateId(args.id, 'Media'); const media = await context.wpRequest(`/wp/v2/media/${id}`); const summary = extractSummary(media, [ 'id', 'title.rendered', 'source_url', 'mime_type', 'alt_text', 'caption.rendered', 'description.rendered', 'media_details', ]); return { content: [{ type: 'text', text: context.clampText(JSON.stringify(summary, null, 2)) }], }; },
- src/tools/content/index.ts:724-730 (schema)Input schema definition for wpnav_get_media: requires a numeric 'id' parameter for the WordPress media ID.inputSchema: { type: 'object', properties: { id: { type: 'number', description: 'WordPress media ID' }, }, required: ['id'], },
- src/tools/content/index.ts:720-748 (registration)Full registration of the wpnav_get_media tool with toolRegistry, including definition (name, description, inputSchema), handler function, and category.toolRegistry.register({ definition: { name: 'wpnav_get_media', description: 'Get a single media item by ID. Returns full metadata including URL, dimensions, and file info.', inputSchema: { type: 'object', properties: { id: { type: 'number', description: 'WordPress media ID' }, }, required: ['id'], }, }, handler: async (args, context) => { validateRequired(args, ['id']); const id = validateId(args.id, 'Media'); const media = await context.wpRequest(`/wp/v2/media/${id}`); const summary = extractSummary(media, [ 'id', 'title.rendered', 'source_url', 'mime_type', 'alt_text', 'caption.rendered', 'description.rendered', 'media_details', ]); return { content: [{ type: 'text', text: context.clampText(JSON.stringify(summary, null, 2)) }], }; }, category: ToolCategory.CONTENT, });
- src/tools.ts:336-349 (schema)Tool schema exported in the main tools list, used for MCP tool discovery/advertising the available tools.name: 'wpnav_get_media', description: 'Get a single media item by ID. Returns full metadata including URL, dimensions, and file info.', inputSchema: { type: 'object' as const, properties: { id: { type: 'number' as const, description: 'WordPress media ID', }, }, required: ['id'], }, },