Skip to main content
Glama

ig_get_media_insights

Retrieve analytics for any Instagram media post by providing its media ID. Access metrics like views, reach, saved, shares, likes, comments, reposts, and reels skip rate to evaluate post performance.

Instructions

Get insights/analytics for a specific media post. Note: 'impressions' and 'video_views' were deprecated in v22.0 — use 'views' instead. Available metrics: views, reach, saved, shares, likes, comments, reposts, reels_skip_rate.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
media_idYesMedia ID
metricNoComma-separated metrics (default: views,reach,saved,shares). For REEL add: likes,comments,reposts,reels_skip_rate

Implementation Reference

  • The handler function for the 'ig_get_media_insights' tool. It accepts a media_id (required) and an optional metric string (default: 'views,reach,saved,shares'). It calls the Meta API GET /{media_id}/insights with the specified metrics and returns the insights data as JSON.
    // ─── ig_get_media_insights ───────────────────────────────────
    server.tool(
      "ig_get_media_insights",
      "Get insights/analytics for a specific media post. Note: 'impressions' and 'video_views' were deprecated in v22.0 — use 'views' instead. Available metrics: views, reach, saved, shares, likes, comments, reposts, reels_skip_rate.",
      {
        media_id: z.string().describe("Media ID"),
        metric: z.string().optional().describe("Comma-separated metrics (default: views,reach,saved,shares). For REEL add: likes,comments,reposts,reels_skip_rate"),
      },
      async ({ media_id, metric }) => {
        try {
          const m = metric || "views,reach,saved,shares";
          const { data, rateLimit } = await client.ig("GET", `/${media_id}/insights`, { metric: m });
          return { content: [{ type: "text", text: JSON.stringify({ ...data as object, _rateLimit: rateLimit }, null, 2) }] };
        } catch (error) {
          return { content: [{ type: "text", text: `Get media insights failed: ${error instanceof Error ? error.message : String(error)}` }], isError: true };
        }
      }
    );
  • Input schema for the tool: media_id (string, required) and metric (string, optional, description mentions default and REEL-specific metrics).
    {
      media_id: z.string().describe("Media ID"),
      metric: z.string().optional().describe("Comma-separated metrics (default: views,reach,saved,shares). For REEL add: likes,comments,reposts,reels_skip_rate"),
    },
  • The tool is registered via 'server.tool("ig_get_media_insights", ...)' inside the registerIgMediaTools function, which is exported and called from src/index.ts (line 43) with the McpServer instance.
    export function registerIgMediaTools(server: McpServer, client: MetaClient): void {
      // ─── ig_get_media_list ───────────────────────────────────────
      server.tool(
        "ig_get_media_list",
        "Get list of media published on the Instagram account.",
        {
          limit: z.number().optional().describe("Number of results (max 100, default 25)"),
          after: z.string().optional().describe("Pagination cursor for next page"),
          before: z.string().optional().describe("Pagination cursor for previous page"),
        },
        async ({ limit, after, before }) => {
          try {
            const params: Record<string, unknown> = {
              fields: "id,caption,media_type,media_url,permalink,thumbnail_url,timestamp,like_count,comments_count",
            };
            if (limit) params.limit = limit;
            if (after) params.after = after;
            if (before) params.before = before;
            const { data, rateLimit } = await client.ig("GET", `/${client.igUserId}/media`, params);
            return { content: [{ type: "text", text: JSON.stringify({ ...data as object, _rateLimit: rateLimit }, null, 2) }] };
          } catch (error) {
            return { content: [{ type: "text", text: `Get media list failed: ${error instanceof Error ? error.message : String(error)}` }], isError: true };
          }
        }
      );
    
      // ─── ig_get_media ────────────────────────────────────────────
      server.tool(
        "ig_get_media",
        "Get details of a specific Instagram media post.",
        {
          media_id: z.string().describe("Media ID"),
          fields: z.string().optional().describe("Comma-separated fields (default: id,caption,media_type,media_url,permalink,timestamp,like_count,comments_count)"),
        },
        async ({ media_id, fields }) => {
          try {
            const f = fields || "id,caption,media_type,media_url,permalink,thumbnail_url,timestamp,like_count,comments_count";
            const { data, rateLimit } = await client.ig("GET", `/${media_id}`, { fields: f });
            return { content: [{ type: "text", text: JSON.stringify({ ...data as object, _rateLimit: rateLimit }, null, 2) }] };
          } catch (error) {
            return { content: [{ type: "text", text: `Get media failed: ${error instanceof Error ? error.message : String(error)}` }], isError: true };
          }
        }
      );
    
      // ─── ig_delete_media ─────────────────────────────────────────
      server.tool(
        "ig_delete_media",
        "Delete an Instagram media post (posts, carousels, reels, stories). This action is irreversible. Requires instagram_manage_contents permission.",
        {
          media_id: z.string().describe("Media ID to delete"),
        },
        async ({ media_id }) => {
          try {
            const { data, rateLimit } = await client.ig("DELETE", `/${media_id}`);
            return { content: [{ type: "text", text: JSON.stringify({ success: true, ...data as object, _rateLimit: rateLimit }, null, 2) }] };
          } catch (error) {
            return { content: [{ type: "text", text: `Delete media failed: ${error instanceof Error ? error.message : String(error)}` }], isError: true };
          }
        }
      );
    
      // ─── ig_get_media_insights ───────────────────────────────────
      server.tool(
        "ig_get_media_insights",
        "Get insights/analytics for a specific media post. Note: 'impressions' and 'video_views' were deprecated in v22.0 — use 'views' instead. Available metrics: views, reach, saved, shares, likes, comments, reposts, reels_skip_rate.",
        {
          media_id: z.string().describe("Media ID"),
          metric: z.string().optional().describe("Comma-separated metrics (default: views,reach,saved,shares). For REEL add: likes,comments,reposts,reels_skip_rate"),
        },
        async ({ media_id, metric }) => {
          try {
            const m = metric || "views,reach,saved,shares";
            const { data, rateLimit } = await client.ig("GET", `/${media_id}/insights`, { metric: m });
            return { content: [{ type: "text", text: JSON.stringify({ ...data as object, _rateLimit: rateLimit }, null, 2) }] };
          } catch (error) {
            return { content: [{ type: "text", text: `Get media insights failed: ${error instanceof Error ? error.message : String(error)}` }], isError: true };
          }
        }
      );
    
      // ─── ig_toggle_comments ──────────────────────────────────────
      server.tool(
        "ig_toggle_comments",
        "Enable or disable comments on an Instagram media post.",
        {
          media_id: z.string().describe("Media ID"),
          enabled: z.boolean().describe("true to enable comments, false to disable"),
        },
        async ({ media_id, enabled }) => {
          try {
            const { data, rateLimit } = await client.ig("POST", `/${media_id}`, {
              comment_enabled: enabled,
            });
            return { content: [{ type: "text", text: JSON.stringify({ success: true, comment_enabled: enabled, ...data as object, _rateLimit: rateLimit }, null, 2) }] };
          } catch (error) {
            return { content: [{ type: "text", text: `Toggle comments failed: ${error instanceof Error ? error.message : String(error)}` }], isError: true };
          }
        }
      );
    }
  • The MetaClient.ig() method is the helper that makes the actual HTTP GET request to the Facebook Graph API (v25.0). The handler calls 'client.ig("GET", `/${media_id}/insights`, { metric: m })' which builds and sends the request.
    async ig(
      method: string,
      path: string,
      params?: Record<string, unknown>
    ): Promise<ClientResponse> {
      if (!this.config.instagramAccessToken) {
        throw new Error("INSTAGRAM_ACCESS_TOKEN is not configured.");
      }
      return this.request(IG_BASE, this.config.instagramAccessToken, method, path, params);
    }
Behavior4/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations, the description carries the full burden. It discloses the deprecation of 'impressions' and 'video_views' and lists all available metrics. This is good transparency for the metric parameter, though it does not mention permissions, rate limits, or output format.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is extremely concise, consisting of just two sentences. The first sentence states the purpose, and the second provides essential details (deprecation and metric list). No unnecessary words.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's simplicity (2 params, no output schema), the description is mostly complete. It covers purpose, deprecation, and metrics. However, it could be enhanced by briefly describing the expected return structure or error conditions.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The input schema already describes both parameters with 100% coverage. The description adds value by summarizing all valid metrics and noting deprecation, which goes beyond the schema's default and REEL note.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the action ('Get insights/analytics') and the target resource ('a specific media post'). It distinguishes from sibling tools like 'ig_get_account_insights' (account-level) and 'ig_get_media' (basic data) by specifying media post analytics.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines3/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides clear context for using the tool (e.g., mention of deprecation and available metrics). However, it does not explicitly state when to use this tool over alternatives, nor does it include exclusions or prerequisites.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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/mikusnuz/meta-mcp'

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