Skip to main content
Glama

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
NameRequiredDescriptionDefault
queryYesSearch query for tweets
countNoNumber of tweets to retrieve (max 100)

Implementation Reference

  • 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}`,
          },
        ],
      };
    }
  • 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);

Tool Definition Quality

Score is being calculated. Check back soon.

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

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