Skip to main content
Glama
crazyrabbitLTC

Twitter MCP Server

searchTweets

Search for tweets using specific queries to find relevant content and analyze Twitter data through customizable filters and result parameters.

Instructions

Search for tweets using a query string

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
queryYesThe search query
maxResultsNoMaximum number of results to return
tweetFieldsNoFields to include in the tweet objects

Implementation Reference

  • The core handler function that executes the searchTweets tool logic. It performs a Twitter v2 search using the provided query, handles expansions for authors, formats the results, and includes tier requirement checks.
    export const handleSearchTweets: TwitterHandler<SearchTweetsArgs> = async (
        client: TwitterClient | null,
        { query, maxResults = 10, tweetFields }: SearchTweetsArgs
    ): Promise<HandlerResponse> => {
        if (!client) {
            return createMissingTwitterApiKeyResponse('searchTweets');
        }
        try {
            const searchResult = await client.v2.search(query, {
                max_results: maxResults,
                'tweet.fields': tweetFields?.join(',') || 'created_at,public_metrics',
                expansions: ['author_id'],
                'user.fields': ['username']
            });
    
            const tweets = Array.isArray(searchResult.data) ? searchResult.data : [];
            if (tweets.length === 0) {
                return createResponse(`No tweets found for query: ${query}`);
            }
    
            const formattedTweets = tweets.map((tweet: TweetV2): TweetWithAuthor => ({
                ...tweet,
                author: searchResult.includes?.users?.find((u: UserV2) => u.id === tweet.author_id)
            }));
    
            return createResponse(`Search results: ${JSON.stringify(formattedTweets, null, 2)}`);
        } catch (error) {
            if (error instanceof Error) {
                if (error.message.includes('400') && error.message.includes('Invalid Request')) {
                    throw new Error(`Search functionality requires Pro tier access ($5,000/month) or higher. Current Basic tier ($200/month) does not include recent search API access. Consider upgrading at https://developer.x.com/en/portal/products/pro or use alternative data sources.`);
                }
                throw new Error(formatTwitterError(error, 'searching tweets'));
            }
            throw error;
        }
    };
  • MCP tool schema definition for searchTweets, including description and inputSchema used for tool listing and validation.
    searchTweets: {
        description: 'Search for tweets using a query string',
        inputSchema: {
            type: 'object',
            properties: {
                query: {
                    type: 'string',
                    description: 'The search query'
                },
                maxResults: {
                    type: 'number',
                    description: 'Maximum number of results to return'
                },
                tweetFields: {
                    type: 'array',
                    items: {
                        type: 'string'
                    },
                    description: 'Fields to include in the tweet objects'
                }
            },
            required: ['query']
        }
    },
  • src/index.ts:313-316 (registration)
    Registration in the main server request handler: dispatches CallToolRequest for 'searchTweets' to the handleSearchTweets function.
    case 'searchTweets': {
        const { query, maxResults } = request.params.arguments as { query: string; maxResults?: number };
        response = await handleSearchTweets(client, { query, maxResults });
        break;
  • TypeScript interface defining the input arguments for searchTweets handler.
    export interface SearchTweetsArgs {
        query: string;
        since?: string;
        until?: string;
        tweetFields?: string[];
    }
  • src/index.ts:48-50 (registration)
    Import of the handleSearchTweets handler function into the main index.ts for use in tool dispatching.
        handleSearchTweets,
        handleHashtagAnalytics
    } from './handlers/search.handlers.js';
Behavior2/5

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

With no annotations provided, the description carries full burden but offers minimal behavioral insight. It doesn't disclose whether this is a read-only operation, what permissions are needed, rate limits, pagination behavior, or what the return format looks like. For a search tool with zero annotation coverage, this is inadequate.

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

Conciseness5/5

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

The description is a single, efficient sentence with zero waste. It's appropriately sized and front-loaded, though it could benefit from more detail given the tool's complexity.

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 tool's complexity (3 parameters, no annotations, no output schema), the description is incomplete. It doesn't explain return values, error conditions, or behavioral traits, leaving significant gaps for the agent to operate effectively.

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 documents all parameters (query, maxResults, tweetFields). The description adds no additional meaning beyond what's in the schema—it doesn't explain query syntax, default values, or field options. Baseline 3 is appropriate when the 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 'Search for tweets using a query string' clearly states the verb ('search') and resource ('tweets'), but it's vague about scope and doesn't differentiate from sibling tools like 'advancedTweetSearch' or 'historicalTweetSearch'. It provides a basic purpose but lacks specificity about what kind of search this performs.

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 like 'advancedTweetSearch' or 'historicalTweetSearch'. The description doesn't mention any prerequisites, context, or exclusions, leaving the agent to guess based on 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/crazyrabbitLTC/mcp-twitter-server'

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