Skip to main content
Glama

instagram_search_accounts

Find Instagram accounts by username or name query to retrieve profile information for matching results.

Instructions

Search for Instagram accounts by username query. Returns a list of matching accounts with their profile information.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
queryYesThe search query (username or name to search for)
limitNoMaximum number of results to return (default: 20, max: 50)

Implementation Reference

  • The 'execute' method contains the core handler logic for the 'instagram_search_accounts' tool. It validates input, checks login status, performs the user search via igpapiClient, limits and formats the results, and returns a structured ToolResult.
    async execute(args: { query: string; limit?: number }): Promise<ToolResult> {
      const { query, limit = 20 } = args;
    
      // Validate inputs
      if (!query || query.trim().length === 0) {
        throw new Error("Search query is required and cannot be empty");
      }
    
      const searchLimit = Math.min(Math.max(1, limit || 20), 50);
    
      // 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 {
        // Perform account search
        const searchResponse = await client.user.search(query) as UserRepositorySearchResponseRootObject;
    
        // Extract users array from response
        // The response structure contains a 'users' property with the array of results
        const users = searchResponse.users || [];
        const totalResults = users.length;
    
        // Limit results
        const limitedResults = users.slice(0, searchLimit);
    
        // Format results
        if (limitedResults.length === 0) {
          return {
            content: [
              {
                type: "text",
                text: `No accounts found matching "${query}"`,
              },
            ],
          };
        }
    
        const formattedResults = limitedResults.map((user, index: number) => {
          const profile = {
            rank: index + 1,
            username: user.username || "N/A",
            fullName: user.full_name || "N/A",
            userId: user.pk || "N/A",
            isVerified: user.is_verified || false,
            isPrivate: user.is_private || false,
            followerCount: user.follower_count || 0,
          };
    
          return `\n${profile.rank}. @${profile.username}${profile.isVerified ? " ✓" : ""}
     Full Name: ${profile.fullName}
     User ID: ${profile.userId}
     ${profile.isPrivate ? "🔒 Private Account" : "🌐 Public Account"}
     Followers: ${profile.followerCount.toLocaleString()}`;
        }).join("\n");
    
        const summary = `Found ${limitedResults.length} account${limitedResults.length === 1 ? "" : "s"} matching "${query}"${totalResults > searchLimit ? ` (showing first ${searchLimit} of ${totalResults} total)` : ""}:`;
    
        return {
          content: [
            {
              type: "text",
              text: `${summary}${formattedResults}`,
            },
          ],
        };
      } catch (error) {
        // Re-throw to be handled by base error handling
        throw error;
      }
    }
  • The 'getDefinition' method provides the tool schema, including name 'instagram_search_accounts', description, and input schema requiring a 'query' string with optional 'limit'.
    getDefinition(): ToolDefinition {
      return {
        name: "instagram_search_accounts",
        description: "Search for Instagram accounts by username query. Returns a list of matching accounts with their profile information.",
        inputSchema: {
          type: "object",
          properties: {
            query: {
              type: "string",
              description: "The search query (username or name to search for)",
            },
            limit: {
              type: "number",
              description: "Maximum number of results to return (default: 20, max: 50)",
              default: 20,
            },
          },
          required: ["query"],
        },
      };
  • The tool is imported and instantiated as 'new SearchAccountsTool()' in the central tools registry array, which is used by getAllToolDefinitions() for MCP registration and executeTool() for invocation.
    import { SearchAccountsTool } from "./search_accounts.js";
    import { LogoutTool } from "./logout.js";
    import { GetUserProfileTool } from "./get_user_profile.js";
    import { GetCurrentUserProfileTool } from "./get_current_user_profile.js";
    import { GetUserPostsTool } from "./get_user_posts.js";
    import { LikePostTool } from "./like_post.js";
    import { LikeCommentTool } from "./like_comment.js";
    import { CommentOnPostTool } from "./comment_on_post.js";
    import { GetPostCommentsTool } from "./get_post_comments.js";
    import { GetPostDetailsTool } from "./get_post_details.js";
    import { GetUserStoriesTool } from "./get_user_stories.js";
    import { GetTimelineFeedTool } from "./get_timeline_feed.js";
    import { FollowUserTool } from "./follow_user.js";
    import type { BaseTool } from "./base.js";
    
    // Import all tools
    const tools: BaseTool[] = [
      new LoginTool(),
      new Complete2FATool(),
      new SearchAccountsTool(),
Behavior2/5

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

No annotations are provided, so the description carries the full burden of behavioral disclosure. It mentions the return type ('list of matching accounts with their profile information'), which is helpful, but lacks details on rate limits, authentication requirements, error handling, or pagination. For a search tool with no annotation coverage, this is insufficient to inform safe and effective use.

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 two concise sentences with zero waste: the first states the purpose, and the second specifies the return value. It's front-loaded and efficiently communicates core information without redundancy or fluff.

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 no annotations and no output schema, the description is incomplete for a search tool in this context. It doesn't address authentication needs (implied by login/logout siblings), rate limits, or what 'profile information' entails (e.g., fields returned). For a tool with 2 parameters and behavioral uncertainty, more context is needed to ensure proper 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 input schema fully documents the parameters ('query' and 'limit'). The description adds no additional semantic meaning beyond what's in the schema (e.g., it doesn't clarify search algorithm, ranking, or what 'profile information' includes). Baseline 3 is appropriate as the schema handles parameter documentation adequately.

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 tool's purpose: 'Search for Instagram accounts by username query' specifies the verb (search) and resource (Instagram accounts). It distinguishes from siblings like 'instagram_get_user_profile' by focusing on search rather than retrieval of a specific profile. However, it doesn't explicitly differentiate from all siblings (e.g., 'instagram_get_timeline_feed' also involves retrieval but of different content).

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 provides no guidance on when to use this tool versus alternatives. It doesn't mention when to prefer this over 'instagram_get_user_profile' for known usernames, or how it relates to other search-like siblings (e.g., 'instagram_get_user_posts' for content search). There's no context on prerequisites, such as whether authentication is required, which is a gap given the sibling tools include login/logout operations.

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