get_twitter_tweets
Retrieve tweets from any Twitter/X user by providing their username to access their posting history and content.
Instructions
Get tweets from a Twitter/X user
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| handle | Yes | Twitter username |
Input Schema (JSON Schema)
{
"properties": {
"handle": {
"description": "Twitter username",
"type": "string"
}
},
"required": [
"handle"
],
"type": "object"
}
Implementation Reference
- src/index.ts:445-464 (handler)The handler function for the 'get_twitter_tweets' tool. It extracts the 'handle' parameter, makes an API request to fetch tweets, processes them with extractTwitterTweets, and returns the result as JSON.if (name === "get_twitter_tweets") { const { handle } = args as { handle: string }; const response = await axios.get(`${BASE_URL}/twitter/user-tweets`, { headers: { "X-API-Key": API_KEY }, params: { handle }, }); const extracted = extractTwitterTweets(response.data, 10); return { content: [ { type: "text", text: JSON.stringify( { handle, tweets: extracted, total_returned: extracted.length }, null, 2 ), }, ], }; }
- src/index.ts:279-288 (schema)The tool schema definition including name, description, and input schema for 'get_twitter_tweets'.name: "get_twitter_tweets", description: "Get tweets from a Twitter/X user", inputSchema: { type: "object", properties: { handle: { type: "string", description: "Twitter username" }, }, required: ["handle"], }, },
- src/index.ts:122-136 (helper)Helper function to extract and format up to 10 tweets from the API response data.function extractTwitterTweets(data: any, limit = 10) { const tweets = data?.data?.tweets || data?.tweets || data?.data || []; const tweetsArray = Array.isArray(tweets) ? tweets : tweets.timeline || []; return tweetsArray.slice(0, limit).map((tweet: any) => { return { id: tweet.id_str || tweet.id, text: tweet.full_text || tweet.text, created_at: tweet.created_at, retweets: tweet.retweet_count || 0, likes: tweet.favorite_count || tweet.like_count || 0, replies: tweet.reply_count || 0, is_retweet: tweet.retweeted || false, }; }); }
- src/index.ts:349-350 (registration)Registration of the ListToolsRequestSchema handler which returns the list of tools including 'get_twitter_tweets'.server.setRequestHandler(ListToolsRequestSchema, async () => ({ tools }));