Skip to main content
Glama

get_hashtag_media

Retrieve top or recent Instagram posts for a hashtag using its ID from search_hashtag, supporting up to 50 posts per request.

Instructions

Get top or recent media for a hashtag. Use search_hashtag first to get the hashtag ID.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
hashtag_idYesHashtag ID from search_hashtag
media_typeNoGet top or recent mediatop
limitNoNumber of posts (max 50)

Implementation Reference

  • Implementation of the getHashtagMedia method which calls the Instagram API.
    async getHashtagMedia(
      hashtagId: string,
      mediaType: "top" | "recent" = "top",
      limit = 25
    ): Promise<IGMedia[]> {
      const fields =
        "id,media_type,media_url,permalink,caption,timestamp,like_count,comments_count";
      const data = await this.request(
        "GET",
        `${hashtagId}/${mediaType}_media`,
        {
          params: {
            user_id: this.aid(),
            fields,
            limit: String(Math.min(limit, 50)),
          },
        }
      );
      return data.data ?? [];
    }
  • Tool definition and input schema for get_hashtag_media.
    name: "get_hashtag_media",
    description:
      "Get top or recent media for a hashtag. Use search_hashtag first to get the hashtag ID.",
    inputSchema: {
      type: "object" as const,
      properties: {
        hashtag_id: { type: "string", description: "Hashtag ID from search_hashtag" },
        media_type: { type: "string", enum: ["top", "recent"], description: "Get top or recent media", default: "top" },
        limit: { type: "integer", description: "Number of posts (max 50)", minimum: 1, maximum: 50, default: 25 },
      },
      required: ["hashtag_id"],
    },
  • src/index.ts:448-451 (registration)
    Handler logic routing for get_hashtag_media.
    case "get_hashtag_media": {
      const media = await c.getHashtagMedia(args.hashtag_id, args.media_type ?? "top", args.limit ?? 25);
      return JSON.stringify({ hashtag_id: args.hashtag_id, media, count: media.length }, null, 2);
    }

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/mcpware/instagram-mcp'

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