Skip to main content
Glama

get_user_timeline

Retrieve a user’s most recent tweets from X (Twitter) by specifying the number of tweets to fetch, up to a maximum of 100. Streamline timeline access for analysis or integration.

Instructions

Get the user's recent tweets

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
countNoNumber of tweets to retrieve (max 100)

Implementation Reference

  • The core handler function that implements the get_user_timeline tool logic: fetches the user's own timeline using Twitter API v2.userTimeline, handles errors by falling back to user info, and formats tweets as a text list.
    private async getUserTimeline(args: any) { if (!this.twitterClient) { throw new Error("Twitter client not initialized"); } const count = Math.min(args.count || 10, 100); try { const me = await this.twitterClient.v2.me(); const tweets = await this.twitterClient.v2.userTimeline(me.data.id, { max_results: count, "tweet.fields": ["created_at", "public_metrics"], expansions: ["author_id"], }); const tweetList = tweets.data.data || []; const formattedTweets = tweetList .map((tweet) => `- ${tweet.text} (${tweet.id})`) .join("\n"); return { content: [ { type: "text", text: `Your recent tweets:\n${formattedTweets}`, }, ], }; } catch (error) { // If timeline fails, just return user info const me = await this.twitterClient.v2.me(); return { content: [ { type: "text", text: `User: @${me.data.username} (${me.data.name})\nTimeline access may be restricted.`, }, ], }; } }
  • The tool schema definition in the getTools() method, including name, description, and inputSchema with optional 'count' parameter.
    { name: "get_user_timeline", description: "Get the user's recent tweets", inputSchema: { type: "object", properties: { count: { type: "number", description: "Number of tweets to retrieve (max 100)", default: 10, }, }, }, }, {
  • src/index.ts:111-112 (registration)
    Registration in the CallToolRequestSchema handler: switch case that routes calls to the getUserTimeline method.
    case "get_user_timeline": return await this.getUserTimeline(args);

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/krishna-paulraj/x-mcp-server'

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