search_tweets
Find tweets by entering search queries to retrieve relevant content from X (Twitter). Specify the number of results to get targeted information.
Instructions
Search for tweets using a query
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| query | Yes | Search query for tweets | |
| count | No | Number of tweets to retrieve (max 100) |
Implementation Reference
- src/index.ts:232-263 (handler)The handler function that performs the tweet search using TwitterApi v2.search, validates input, formats results, and returns them.private async searchTweets(args: any) { if (!this.twitterClient) { throw new Error("Twitter client not initialized"); } const { query, count = 10 } = args; if (!query || typeof query !== "string") { throw new Error("Query is required and must be a string"); } const searchCount = Math.min(count, 100); const tweets = await this.twitterClient.v2.search(query, { max_results: searchCount, "tweet.fields": ["created_at", "author_id"], }); const tweetList = tweets.data.data || []; const formattedTweets = tweetList .map((tweet) => `- ${tweet.text} (by @${tweet.author_id})`) .join("\n"); return { content: [ { type: "text", text: `Search results for "${query}":\n${formattedTweets}`, }, ], }; }
- src/index.ts:67-81 (schema)Input schema definition for the search_tweets tool, specifying query and optional count parameters.inputSchema: { type: "object", properties: { query: { type: "string", description: "Search query for tweets", }, count: { type: "number", description: "Number of tweets to retrieve (max 100)", default: 10, }, }, required: ["query"], },
- src/index.ts:64-82 (registration)Tool registration in getTools() method, defining name, description, and input schema for listTools response.{ name: "search_tweets", description: "Search for tweets using a query", inputSchema: { type: "object", properties: { query: { type: "string", description: "Search query for tweets", }, count: { type: "number", description: "Number of tweets to retrieve (max 100)", default: 10, }, }, required: ["query"], }, },
- src/index.ts:113-114 (registration)Dispatch case in the CallToolRequest handler that routes to the searchTweets method.case "search_tweets": return await this.searchTweets(args);