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);
Behavior2/5

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

With no annotations, the description carries the full burden but provides minimal behavioral insight. It mentions searching but doesn't disclose key traits like rate limits, authentication needs, result format, or pagination. This is inadequate for a search tool that likely involves API constraints.

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

Conciseness4/5

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

The description is a single, efficient sentence with no wasted words, making it appropriately concise. However, it lacks front-loaded detail that could better guide usage, slightly reducing its effectiveness.

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 no annotations or output schema, the description is incomplete. It fails to explain behavioral aspects like result structure, error handling, or constraints, which are critical for a search tool. This leaves significant gaps for agent operation.

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 fully documents parameters (query and count). The description adds no additional meaning beyond implying a 'query' is used, aligning with the baseline score when schema does the heavy lifting.

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

Purpose3/5

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

The description states the verb ('search') and resource ('tweets') with a basic action, making the purpose understandable but vague. It doesn't specify what aspects of tweets are searched (e.g., text, hashtags, users) or distinguish it from sibling tools like 'get_user_timeline' for user-specific tweets.

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 alternatives. It doesn't mention scenarios like general searches versus user-specific timelines (get_user_timeline) or creating tweets (post_tweet), leaving the agent to infer usage from tool names alone.

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

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