Skip to main content
Glama

search_tweets

Find tweets matching a search query and retrieve up to 100 results. Use this tool to analyze or monitor social media content on X (Twitter) with precision.

Instructions

Search for tweets using a query

Input Schema

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

Implementation Reference

  • The handler function that executes the search_tweets tool. It validates input, searches tweets using Twitter API v2, 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}`, }, ], }; }
  • The input schema definition for the search_tweets tool, defining the expected parameters: query (required string) and optional count.
    { 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)
    The registration/dispatch point in the tool handler switch statement that routes calls to search_tweets to the searchTweets method.
    case "search_tweets": return await this.searchTweets(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