Skip to main content
Glama

wp_get_media

Retrieve a specific media file from a WordPress site by providing its unique ID to access or manage the item directly.

Instructions

Retrieves a single media item by its ID.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
siteNoThe ID of the WordPress site to target (from mcp-wordpress.config.json). Required if multiple sites are configured.
idYesThe unique identifier for the media item.

Implementation Reference

  • The handler function that implements the core logic of the wp_get_media tool. It takes a WordPressClient and parameters, extracts the media ID, fetches the media item details via client.getMediaItem(id), formats a markdown-style response string with key metadata (title, URL, type, date, alt text, caption), and handles errors by throwing a descriptive message.
    public async handleGetMedia(client: WordPressClient, params: Record<string, unknown>): Promise<unknown> {
      const { id } = params as { id: number };
      try {
        const media = await client.getMediaItem(id);
        const content =
          `**Media Details (ID: ${media.id})**\n\n` +
          `- **Title:** ${media.title.rendered}\n` +
          `- **URL:** ${media.source_url}\n` +
          `- **Type:** ${media.media_type} (${media.mime_type})\n` +
          `- **Date:** ${new Date(media.date).toLocaleString()}\n` +
          (media.alt_text ? `- **Alt Text:** ${media.alt_text}\n` : "") +
          (media.caption.rendered ? `- **Caption:** ${media.caption.rendered}\n` : "");
        return content;
      } catch (_error) {
        throw new Error(`Failed to get media item: ${getErrorMessage(_error)}`);
      }
    }
  • The registration of the wp_get_media tool within the MediaTools.getTools() method's return array. It specifies the tool's name, description, input schema (parameters), and binds the handler function for execution.
    {
      name: "wp_get_media",
      description: "Retrieves a single media item by its ID.",
      parameters: [
        {
          name: "id",
          type: "number",
          required: true,
          description: "The unique identifier for the media item.",
        },
      ],
      handler: this.handleGetMedia.bind(this),
    },
  • The input schema definition for the wp_get_media tool, specifying a single required 'id' parameter of type number with description.
    parameters: [
      {
        name: "id",
        type: "number",
        required: true,
        description: "The unique identifier for the media item.",
      },
    ],

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/docdyhr/mcp-wordpress'

If you have feedback or need assistance with the MCP directory API, please join our Discord server