Skip to main content
Glama
crazyrabbitLTC

Twitter MCP Server

getUserTimeline

Fetch tweets from a specific user's timeline by providing their username, with options to control result count and include additional tweet fields.

Instructions

Get tweets from a specific user's timeline

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
usernameYesThe username of the user whose timeline to fetch
maxResultsNoMaximum number of tweets to return (default: 10, max: 100)
tweetFieldsNoAdditional tweet fields to include

Implementation Reference

  • Core handler function that executes the getUserTimeline tool logic using Twitter API v2 to fetch recent tweets from a user's timeline.
    export const handleGetUserTimeline = async (
        client: TwitterClient | null,
        { userId, maxResults = 10, tweetFields = ['created_at', 'public_metrics', 'author_id'], expansions = ['author_id' as TTweetv2Expansion], userFields = ['username' as TTweetv2UserField] }: GetUserTimelineArgs
    ): Promise<HandlerResponse> => {
        if (!client) {
            return createMissingTwitterApiKeyResponse('Get User Timeline');
        }
    
        try {
            const timeline = await client.getUserTimeline(userId, {
                max_results: maxResults,
                'tweet.fields': tweetFields.join(','),
                expansions,
                'user.fields': userFields
            });
    
            if (!timeline.data || timeline.data.length === 0) {
                return createResponse(`No tweets found in timeline for user: ${userId}`);
            }
    
            return createResponse(`Timeline tweets: ${JSON.stringify(timeline.data, null, 2)}`);
        } catch (error) {
            if (error instanceof Error) {
                throw new Error(formatTwitterError(error, 'getting user timeline'));
            }
            throw new Error('Failed to get user timeline: Unknown error occurred');
        }
    };
  • MCP tool schema definition including input validation (username required, optional maxResults and tweetFields) and description.
    getUserTimeline: {
        description: 'Get tweets from a specific user\'s timeline',
        inputSchema: {
            type: 'object',
            properties: {
                username: { 
                    type: 'string', 
                    description: 'The username of the user whose timeline to fetch' 
                },
                maxResults: { 
                    type: 'number', 
                    description: 'Maximum number of tweets to return (default: 10, max: 100)' 
                },
                tweetFields: { 
                    type: 'array', 
                    items: { type: 'string' },
                    description: 'Additional tweet fields to include' 
                }
            },
            required: ['username']
        }
    },
  • src/index.ts:222-258 (registration)
    Registers the getUserTimeline tool in the MCP server dispatch switch: converts username to userId using getUserByUsername, then calls the handler.
                case 'getUserTimeline': {
                    const { username, maxResults, tweetFields } = request.params.arguments as { 
                        username: string; 
                        maxResults?: number; 
                        tweetFields?: string[] 
                    };
                    
                    if (!client) {
                        response = { response: `📋 **Get User Timeline requires Twitter API credentials**
    
    To use Twitter tools, please:
    
    1. **Create a Twitter Developer Account** at https://developer.twitter.com
    2. **Create a new Twitter App** and generate API keys
    3. **Add to your .env file:**
       \`\`\`
       X_API_KEY=your_api_key_here
       X_API_SECRET=your_api_secret_here
       X_ACCESS_TOKEN=your_access_token_here
       X_ACCESS_TOKEN_SECRET=your_access_token_secret_here
       \`\`\`
    4. **Restart the MCP server**
    
    **Alternative:** Use the enhanced SocialData.tools research tools instead (if available)`, tools: [] };
                        break;
                    }
                    
                    // Convert username to userId
                    const userResponse = await client.getUserByUsername(username);
                    const userId = userResponse.data.id;
                    
                    response = await handleGetUserTimeline(client, { 
                        userId, 
                        maxResults, 
                        tweetFields 
                    });
                    break;
  • TypeScript interface defining arguments for the handler function (userId required, optional fields matching Twitter API v2 parameters).
    export interface GetUserTimelineArgs {
        userId: string;
        maxResults?: number;
        tweetFields?: string[];
        expansions?: TTweetv2Expansion[];
        userFields?: TTweetv2UserField[];
    }
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 states what the tool does but doesn't mention rate limits, authentication needs, pagination, or error handling. For a read operation with potential API constraints, this leaves significant gaps in understanding how the tool behaves beyond basic functionality.

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 directly states the tool's purpose with no wasted words. It's front-loaded and appropriately sized for a simple retrieval tool, making it easy to parse quickly.

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, no output schema, and a read operation with potential complexities (e.g., rate limits, data format), the description is incomplete. It doesn't address what the tool returns, error cases, or behavioral constraints, which are crucial for an agent to use it effectively in a real-world context.

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 already documents all parameters thoroughly. The description adds no additional meaning about parameters beyond implying 'username' is required, which is covered in the schema. This meets the baseline for high schema coverage without extra value.

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 ('Get') and resource ('tweets from a specific user's timeline'), making the purpose immediately understandable. However, it doesn't differentiate from sibling tools like 'getTweetsByIds' or 'getLikedTweets', which also retrieve tweets but from different sources, so it misses explicit sibling distinction.

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 such as 'getTweetsByIds' for specific tweets or 'searchTweets' for broader queries. It lacks context about prerequisites or exclusions, leaving the agent to infer usage from the name alone.

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/crazyrabbitLTC/mcp-twitter-server'

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