Skip to main content
Glama
rafaljanicki

X (Twitter) MCP server

by rafaljanicki

get_user_followers

Retrieve a list of followers for a specific user on X (Twitter) using user ID, with options to set count and cursor for pagination.

Instructions

Retrieves a list of followers for a given user

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
countNo
cursorNo
user_idYes

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • The handler function for the 'get_user_followers' tool. It checks rate limits, initializes the Twitter client, fetches the followers using Tweepy's get_users_followers method, and returns a list of user dictionaries.
    @server.tool(name="get_user_followers", description="Retrieves a list of followers for a given user")
    async def get_user_followers(user_id: str, count: Optional[int] = 100, cursor: Optional[str] = None) -> List[Dict]:
        """Retrieves a list of followers for a given user.
    
        Args:
            user_id (str): The user ID whose followers are to be retrieved.
            count (Optional[int]): The number of followers to retrieve per page. Default is 100. Max is 100 for V2 API.
            cursor (Optional[str]): A pagination token for fetching the next set of results.
        """
        if not check_rate_limit("follow_actions"):
            raise Exception("Follow action rate limit exceeded")
        client, _ = initialize_twitter_clients()
        followers = client.get_users_followers(id=user_id, max_results=count, pagination_token=cursor, user_fields=["id", "name", "username"])
        return [user.data for user in followers.data]
  • The @server.tool decorator registers the get_user_followers function as an MCP tool with the specified name and description.
    @server.tool(name="get_user_followers", description="Retrieves a list of followers for a given user")
  • The function signature and docstring define the input schema (parameters: user_id (str), count (Optional[int]=100), cursor (Optional[str]=None)) and output (List[Dict]).
    async def get_user_followers(user_id: str, count: Optional[int] = 100, cursor: Optional[str] = None) -> List[Dict]:
        """Retrieves a list of followers for a given user.
    
        Args:
            user_id (str): The user ID whose followers are to be retrieved.
            count (Optional[int]): The number of followers to retrieve per page. Default is 100. Max is 100 for V2 API.
            cursor (Optional[str]): A pagination token for fetching the next set of results.
        """
  • Helper function to lazily initialize the Tweepy Twitter v2 Client and v1.1 API.
    def initialize_twitter_clients() -> tuple[tweepy.Client, tweepy.API]:
        """Initialize Twitter API clients on-demand."""
        global _twitter_client, _twitter_v1_api
    
        if _twitter_client is not None and _twitter_v1_api is not None:
            return _twitter_client, _twitter_v1_api
    
        # Verify required environment variables
        required_env_vars = [
            "TWITTER_API_KEY",
            "TWITTER_API_SECRET",
            "TWITTER_ACCESS_TOKEN",
            "TWITTER_ACCESS_TOKEN_SECRET",
            "TWITTER_BEARER_TOKEN",
        ]
        for var in required_env_vars:
            if not os.getenv(var):
                raise EnvironmentError(f"Missing required environment variable: {var}")
    
        # Initialize v2 API client
        _twitter_client = tweepy.Client(
            consumer_key=os.getenv("TWITTER_API_KEY"),
            consumer_secret=os.getenv("TWITTER_API_SECRET"),
            access_token=os.getenv("TWITTER_ACCESS_TOKEN"),
            access_token_secret=os.getenv("TWITTER_ACCESS_TOKEN_SECRET"),
            bearer_token=os.getenv("TWITTER_BEARER_TOKEN")
        )
    
        # Initialize v1.1 API for media uploads and other unsupported v2 endpoints
        auth = tweepy.OAuth1UserHandler(
            consumer_key=os.getenv("TWITTER_API_KEY"),
            consumer_secret=os.getenv("TWITTER_API_SECRET"),
            access_token=os.getenv("TWITTER_ACCESS_TOKEN"),
            access_token_secret=os.getenv("TWITTER_ACCESS_TOKEN_SECRET")
        )
        _twitter_v1_api = tweepy.API(auth)
    
        return _twitter_client, _twitter_v1_api
  • Helper function to check rate limits before performing actions like fetching followers.
    def check_rate_limit(action_type: str) -> bool:
        """Check if the action is within rate limits."""
        config = RATE_LIMITS.get(action_type)
        if not config:
            return True  # No limit defined
        counter = rate_limit_counters[action_type]
        now = datetime.now()
        if now >= counter["reset_time"]:
            counter["count"] = 0
            counter["reset_time"] = now + config["window"]
        if counter["count"] >= config["limit"]:
            return False
        counter["count"] += 1
        return True
Behavior2/5

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

With no annotations provided, the description carries full burden for behavioral disclosure. It mentions retrieval but doesn't describe important behaviors like pagination (implied by 'cursor' parameter), rate limits, authentication requirements, error conditions, or what the returned list contains. For a tool with 3 parameters and no annotation coverage, this is inadequate.

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 a single, efficient sentence that gets straight to the point with zero wasted words. It's appropriately sized for a retrieval tool and front-loads the core functionality.

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

Completeness3/5

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

Given the tool has an output schema (which handles return values), no annotations, and 3 parameters with 0% schema coverage, the description is incomplete. It covers the basic purpose but misses parameter explanations, behavioral context, and sibling differentiation that would make it fully adequate for agent use.

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

Parameters2/5

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

Schema description coverage is 0%, so the description must compensate by explaining parameters. It mentions 'for a given user' which hints at the 'user_id' parameter, but doesn't explain 'count' (defaults to 100) or 'cursor' (pagination). With 3 undocumented parameters, the description adds minimal value beyond what's inferred from the tool name.

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 verb ('retrieves') and resource ('list of followers for a given user'), making the purpose immediately understandable. It doesn't explicitly differentiate from sibling tools like 'get_user_followers_you_know' or 'get_user_following', which would be needed for a perfect score.

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 like 'get_user_followers_you_know' or 'get_user_following', nor does it mention prerequisites or context for usage. It simply states what the tool does without indicating appropriate scenarios.

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

Related 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/rafaljanicki/x-twitter-mcp-server'

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