Skip to main content
Glama
EnesCinr

Twitter MCP Server

search_tweets

Find relevant tweets by providing a search query and specifying the number of results (10-100).

Instructions

Search for tweets on Twitter

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
queryYesSearch query
countYesNumber of tweets to return (10-100)

Implementation Reference

  • The handleSearchTweets method validates args via SearchTweetsSchema, calls TwitterClient.searchTweets(), formats the response using ResponseFormatter, and returns MCP TextContent.
    private async handleSearchTweets(args: unknown) {
      const result = SearchTweetsSchema.safeParse(args);
      if (!result.success) {
        throw new McpError(
          ErrorCode.InvalidParams,
          `Invalid parameters: ${result.error.message}`
        );
      }
    
      const { tweets, users } = await this.client.searchTweets(
        result.data.query,
        result.data.count
      );
    
      const formattedResponse = ResponseFormatter.formatSearchResponse(
        result.data.query,
        tweets,
        users
      );
    
      return {
        content: [{
          type: 'text',
          text: ResponseFormatter.toMcpResponse(formattedResponse)
        }] as TextContent[]
      };
    }
  • Zod schema for search_tweets input validation: requires 'query' (non-empty string) and 'count' (integer between 10 and 100).
    export const SearchTweetsSchema = z.object({
        query: z.string().min(1, 'Search query cannot be empty'),
        count: z.number()
            .int('Count must be an integer')
            .min(10, 'Minimum count is 10')
            .max(100, 'Maximum count is 100')
    });
  • src/index.ts:85-106 (registration)
    Registration of 'search_tweets' as a named tool in the ListToolsRequestSchema handler, with inputSchema specifying query (string) and count (number, 10-100).
        {
          name: 'search_tweets',
          description: 'Search for tweets on Twitter',
          inputSchema: {
            type: 'object',
            properties: {
              query: {
                type: 'string',
                description: 'Search query'
              },
              count: {
                type: 'number',
                description: 'Number of tweets to return (10-100)',
                minimum: 10,
                maximum: 100
              }
            },
            required: ['query', 'count']
          }
        } as Tool
      ]
    }));
  • src/index.ts:117-128 (registration)
    Dispatch in the CallToolRequestSchema handler that routes 'search_tweets' calls to handleSearchTweets.
          case 'search_tweets':
            return await this.handleSearchTweets(args);
          default:
            throw new McpError(
              ErrorCode.MethodNotFound,
              `Unknown tool: ${name}`
            );
        }
      } catch (error) {
        return this.handleError(error);
      }
    });
  • TwitterClient.searchTweets() method that calls Twitter API v2 search with expansions, maps response to Tweet/TwitterUser objects.
    async searchTweets(query: string, count: number): Promise<{ tweets: Tweet[], users: TwitterUser[] }> {
      try {
        const endpoint = 'tweets/search';
        await this.checkRateLimit(endpoint);
    
        const response = await this.client.v2.search(query, {
          max_results: count,
          expansions: ['author_id'],
          'tweet.fields': ['public_metrics', 'created_at'],
          'user.fields': ['username', 'name', 'verified']
        });
    
        console.error(`Fetched ${response.tweets.length} tweets for query: "${query}"`);
    
        const tweets = response.tweets.map(tweet => ({
          id: tweet.id,
          text: tweet.text,
          authorId: tweet.author_id ?? '',
          metrics: {
            likes: tweet.public_metrics?.like_count ?? 0,
            retweets: tweet.public_metrics?.retweet_count ?? 0,
            replies: tweet.public_metrics?.reply_count ?? 0,
            quotes: tweet.public_metrics?.quote_count ?? 0
          },
          createdAt: tweet.created_at ?? ''
        }));
    
        const users = response.includes.users.map(user => ({
          id: user.id,
          username: user.username,
          name: user.name,
          verified: user.verified ?? false
        }));
    
        return { tweets, users };
      } catch (error) {
        this.handleApiError(error);
      }
    }
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are present, so the description must bear the full burden. However, it only says 'Search for tweets' without disclosing any behavioral traits such as read-only nature, permissions required, rate limits, or result format. This is minimal disclosure.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness3/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is very concise with one sentence, but it lacks detail that could be included without significant bloat. While it is not verbose, it is also not optimally informative for its length.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the lack of output schema and annotations, the description should compensate by explaining return values or usage constraints. It does not; it only states the basic operation, leaving many contextual gaps.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so the schema already explains each parameter. The description does not add any additional meaning or context for the parameters beyond what the schema provides, so it meets the baseline.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool searches for tweets on Twitter, which is a specific verb+resource. It distinguishes from the sibling tool 'post_tweet' implicitly (search vs. post), but does not explicitly state the difference.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

No guidance is provided on when to use this tool versus the sibling 'post_tweet' or any alternatives. The description simply states what it does, without context on appropriate usage scenarios.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

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/EnesCinr/twitter-mcp'

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