Skip to main content
Glama

threads_reply

Reply to Threads posts or comments with text and optional media attachments using the Meta platform API.

Instructions

Reply to a Threads post or another reply.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
reply_to_idYesPost ID to reply to
textYesReply text
image_urlNoOptional image URL to attach
video_urlNoOptional video URL to attach

Implementation Reference

  • Implementation of the 'threads_reply' tool handler, which validates input parameters, creates a thread container, handles optional media (with video processing wait), and publishes the reply.
    // ─── threads_reply ───────────────────────────────────────────
    server.tool(
      "threads_reply",
      "Reply to a Threads post or another reply.",
      {
        reply_to_id: z.string().describe("Post ID to reply to"),
        text: z.string().max(500).describe("Reply text"),
        image_url: z.string().url().optional().describe("Optional image URL to attach"),
        video_url: z.string().url().optional().describe("Optional video URL to attach"),
      },
      async ({ reply_to_id, text, image_url, video_url }) => {
        try {
          let mediaType = "TEXT";
          if (image_url) mediaType = "IMAGE";
          if (video_url) mediaType = "VIDEO";
          const params: Record<string, unknown> = {
            media_type: mediaType,
            text,
            reply_to_id,
          };
          if (image_url) params.image_url = image_url;
          if (video_url) params.video_url = video_url;
          const { data: container } = await client.threads("POST", `/${client.threadsUserId}/threads`, params);
          const containerId = (container as { id: string }).id;
          if (video_url) {
            // Wait for video processing
            const interval = 2000;
            const maxAttempts = 15;
            for (let i = 0; i < maxAttempts; i++) {
              const { data: status } = await client.threads("GET", `/${containerId}`, { fields: "status" });
              const s = (status as { status?: string }).status;
              if (s === "FINISHED") break;
              if (s === "ERROR") throw new Error("Video processing failed");
              await new Promise((r) => setTimeout(r, interval));
            }
          }
          const { data, rateLimit } = await client.threads("POST", `/${client.threadsUserId}/threads_publish`, {
            creation_id: containerId,
          });
          return { content: [{ type: "text", text: JSON.stringify({ ...data as object, _rateLimit: rateLimit }, null, 2) }] };
        } catch (error) {
          return { content: [{ type: "text", text: `Reply failed: ${error instanceof Error ? error.message : String(error)}` }], isError: true };
        }
      }
    );

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