Skip to main content
Glama

instagram_like_post

Like Instagram posts or reels by media ID using authenticated access through the Insta MCP Server integration.

Instructions

Like an Instagram post or reel by media ID. Requires authentication.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
mediaIdYesPost/media ID to like
moduleNoModule info for tracking (e.g., 'feed_timeline', 'profile', 'explore')

Implementation Reference

  • Implements the core logic for liking an Instagram post: validates input, checks authentication, initializes client, calls igpapi.media.like, handles specific errors like auth, rate limits, already liked.
    async execute(args: { mediaId: string; module?: string }): Promise<ToolResult> {
      const { mediaId, module } = args;
    
      // Validate mediaId
      if (!mediaId || typeof mediaId !== "string") {
        throw new Error("mediaId is required and must be a string");
      }
    
      const mediaIdTrimmed = mediaId.trim();
      if (mediaIdTrimmed.length === 0) {
        throw new Error("mediaId cannot be empty");
      }
    
      // Validate module if provided
      if (module !== undefined && (typeof module !== "string" || module.trim().length === 0)) {
        throw new Error("module must be a non-empty string if provided");
      }
    
      // Check if logged in
      if (!igpapiClient.isLoggedIn()) {
        throw new Error("Not logged in. Please use the instagram_login tool to authenticate first.");
      }
    
      // Ensure client is initialized
      if (!igpapiClient.isInitialized()) {
        await igpapiClient.initialize();
      }
    
      const client = igpapiClient.getClient();
    
      try {
        // Call the API to like the post
        // moduleInfo is required - use feed_timeline as default, or use provided module if it matches a valid module_name
        const moduleInfo = module?.trim() 
          ? { module_name: module.trim() as any }
          : { module_name: 'feed_timeline' as const };
        
        await client.media.like({
          mediaId: mediaIdTrimmed,
          moduleInfo,
          d: 1,
        });
    
        // Format success response
        let response = `Successfully liked post with media ID: ${mediaIdTrimmed}`;
        if (module) {
          response += ` (module: ${module.trim()})`;
        }
    
        return {
          content: [
            {
              type: "text",
              text: response,
            },
          ],
        };
      } catch (error: any) {
        // Handle specific error cases
        if (error?.message) {
          const errorMessage = error.message.toLowerCase();
    
          // Authentication errors
          if (
            errorMessage.includes("not logged in") ||
            errorMessage.includes("login") ||
            errorMessage.includes("authentication") ||
            errorMessage.includes("unauthorized") ||
            error?.response?.status === 401
          ) {
            throw new Error("Authentication required. Please use the instagram_login tool to authenticate first.");
          }
    
          // Session expired
          if (
            errorMessage.includes("session") ||
            errorMessage.includes("expired") ||
            errorMessage.includes("invalid")
          ) {
            throw new Error("Session has expired. Please use the instagram_login tool to re-authenticate.");
          }
    
          // Media not found
          if (
            errorMessage.includes("not found") ||
            errorMessage.includes("invalid media") ||
            errorMessage.includes("media not found") ||
            error?.response?.status === 404
          ) {
            throw new Error(`Media not found with ID "${mediaIdTrimmed}". Please verify the media ID is correct.`);
          }
    
          // Rate limiting
          if (
            errorMessage.includes("rate limit") ||
            errorMessage.includes("too many requests") ||
            error?.response?.status === 429
          ) {
            throw new Error("Rate limit exceeded. Please wait before trying again.");
          }
    
          // Already liked (Instagram API may return success, but handle if it throws)
          if (errorMessage.includes("already liked") || errorMessage.includes("duplicate")) {
            return {
              content: [
                {
                  type: "text",
                  text: `Post with media ID "${mediaIdTrimmed}" is already liked.`,
                },
              ],
            };
          }
        }
    
        // Re-throw other errors to be handled by base error handling
        throw error;
      }
    }
  • Defines the tool name 'instagram_like_post', description, and input schema requiring 'mediaId'.
    getDefinition(): ToolDefinition {
      return {
        name: "instagram_like_post",
        description: "Like an Instagram post or reel by media ID. Requires authentication.",
        inputSchema: {
          type: "object",
          properties: {
            mediaId: {
              type: "string",
              description: "Post/media ID to like",
            },
            module: {
              type: "string",
              description: "Module info for tracking (e.g., 'feed_timeline', 'profile', 'explore')",
            },
          },
          required: ["mediaId"],
        },
      };
    }
  • Imports the LikePostTool class.
    import { LikePostTool } from "./like_post.js";
  • Instantiates and registers LikePostTool in the central tools array used for getAllToolDefinitions() and executeTool().
    new LikePostTool(),
Behavior2/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure. It mentions authentication requirements, which is helpful, but fails to describe other critical behaviors such as rate limits, error handling, or whether the action is reversible. For a mutation tool, this leaves significant gaps in understanding its operation.

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—just one sentence that directly states the action and key requirement. It's front-loaded with the core purpose and wastes no words, making it efficient and easy to parse.

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

Completeness2/5

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

Given this is a mutation tool with no annotations and no output schema, the description is incomplete. It lacks details on behavioral traits (e.g., side effects, error cases) and doesn't explain return values or success indicators, leaving the agent with insufficient context for reliable use.

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

Parameters3/5

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

Schema description coverage is 100%, so the schema already documents both parameters thoroughly. The description adds no additional meaning beyond what the schema provides, such as examples or context for parameter usage. Baseline 3 is appropriate when the schema does the heavy lifting.

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

Purpose4/5

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

The description clearly states the action ('Like') and target ('Instagram post or reel by media ID'), making the purpose specific and understandable. However, it doesn't explicitly differentiate from sibling tools like 'instagram_like_comment', which could cause confusion about when to use each.

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

Usage Guidelines2/5

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

The description mentions 'Requires authentication', which provides some context about prerequisites, but offers no guidance on when to use this tool versus alternatives like 'instagram_like_comment' or other engagement tools. There's no explicit when/when-not usage advice.

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

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