Skip to main content
Glama

publish_carousel

Publish Instagram carousel posts with 2-10 images or videos using publicly accessible URLs. Add captions to share multiple photos or videos in a single post.

Instructions

Publish a carousel (album) post with 2-10 images or videos. All media must be publicly accessible URLs.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
image_urlsYesList of 2-10 image/video URLs
captionNoCaption for the carousel post (optional)

Implementation Reference

  • The `publishCarousel` method handles the logic for creating media containers for each image/video and then creating a carousel container, followed by publishing the carousel via the Instagram API.
    async publishCarousel(
      imageUrls: string[],
      caption?: string
    ): Promise<IGPublishResult> {
      const id = this.aid();
      if (imageUrls.length < 2)
        throw new InstagramAPIError("Carousel requires at least 2 items");
      if (imageUrls.length > 10)
        throw new InstagramAPIError("Carousel supports maximum 10 items");
    
      const containerIds: string[] = [];
      for (const url of imageUrls) {
        const isVideo = /\.(mp4|mov)$/i.test(url);
        const body: Record<string, any> = { is_carousel_item: "true" };
        if (isVideo) {
          body.video_url = url;
          body.media_type = "VIDEO";
        } else {
          body.image_url = url;
        }
        const resp = await this.request("POST", `${id}/media`, { body });
        containerIds.push(resp.id);
      }
    
      const carouselBody: Record<string, any> = {
        media_type: "CAROUSEL",
        children: containerIds.join(","),
      };
      if (caption) carouselBody.caption = caption;
      const carousel = await this.request("POST", `${id}/media`, {
        body: carouselBody,
      });
    
      const result = await this.request("POST", `${id}/media_publish`, {
        body: { creation_id: carousel.id },
      });
      return { id: result.id };
    }
  • src/index.ts:114-126 (registration)
    The `publish_carousel` tool registration in the MCP tool definitions, including its schema (image_urls as array, caption as string).
    {
      name: "publish_carousel",
      description:
        "Publish a carousel (album) post with 2-10 images or videos. All media must be publicly accessible URLs.",
      inputSchema: {
        type: "object" as const,
        properties: {
          image_urls: { type: "array", items: { type: "string", format: "uri" }, description: "List of 2-10 image/video URLs", minItems: 2, maxItems: 10 },
          caption: { type: "string", description: "Caption for the carousel post (optional)" },
        },
        required: ["image_urls"],
      },
    },
  • The `handleTool` switch case that executes `c.publishCarousel` when the `publish_carousel` tool is called.
    case "publish_carousel": {
      const result = await c.publishCarousel(args.image_urls, args.caption);
      return JSON.stringify(result, 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