Skip to main content
Glama
crazyrabbitLTC

Twitter MCP Server

trackVirality

Analyze tweet engagement velocity and spread patterns to identify viral content trends on Twitter.

Instructions

Track viral spread patterns and engagement velocity

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
tweetIdYesTweet ID to track virality for
trackingPeriodNoPeriod to track (default: "24h")
analyzeSpreadNoInclude detailed spread analysis (default: true)

Implementation Reference

  • The core handler function that implements the trackVirality tool logic. It searches for retweets, quotes, and discussions related to a given tweet ID, analyzes spread patterns over time, calculates virality metrics including velocity, peak hours, top spreaders, and a viral score.
    export const handleTrackVirality: SocialDataHandler<ViralityTrackingArgs> = async (
        _client: any,
        { tweetId, trackingPeriod = '24h', analyzeSpread = true }: ViralityTrackingArgs
    ) => {
        try {
            const socialClient = getSocialDataClient();
            
            if (!socialClient) {
                return createMissingApiKeyResponse('Virality Tracking');
            }
            
            // Search for retweets and mentions of the tweet
            const viralQuery = `${tweetId} OR url:${tweetId}`;
            const viralResult = await socialClient.searchTweets({
                query: viralQuery,
                maxResults: 100
            });
    
            // Search for quotes and discussions
            const discussionQuery = `"${tweetId}"`;
            const discussionResult = await socialClient.searchTweets({
                query: discussionQuery,
                maxResults: 50
            });
    
            const allInteractions = [...(viralResult.data || []), ...(discussionResult.data || [])];
            
            if (allInteractions.length === 0) {
                return createSocialDataResponse(`No viral spread detected for tweet ${tweetId}`);
            }
    
            // Analyze spread pattern
            const spreadAnalysis: any = {
                tweet_id: tweetId,
                tracking_period: trackingPeriod,
                total_interactions: allInteractions.length,
                spread_metrics: {
                    direct_shares: viralResult.data?.length || 0,
                    discussions: discussionResult.data?.length || 0,
                    unique_users: new Set(allInteractions.map(t => t.user?.screen_name)).size
                }
            };
    
            if (analyzeSpread) {
                // Group by time to see spread velocity
                const timeGroups = new Map();
                allInteractions.forEach((tweet: any) => {
                    const hour = new Date(tweet.tweet_created_at).toISOString().substring(0, 13);
                    if (!timeGroups.has(hour)) {
                        timeGroups.set(hour, []);
                    }
                    timeGroups.get(hour).push(tweet);
                });
    
                const spreadVelocity = Array.from(timeGroups.entries())
                    .map(([hour, tweets]: [string, any[]]) => ({
                        hour,
                        interactions: tweets.length,
                        cumulative: 0 // Will be calculated below
                    }))
                    .sort((a, b) => a.hour.localeCompare(b.hour));
    
                // Calculate cumulative spread
                let cumulative = 0;
                spreadVelocity.forEach(period => {
                    cumulative += period.interactions;
                    period.cumulative = cumulative;
                });
    
                // Find peak spread hour
                const peakHour = spreadVelocity.reduce((max, current) => 
                    current.interactions > max.interactions ? current : max);
    
                // Analyze influential spreaders
                const userEngagement = new Map();
                allInteractions.forEach((tweet: any) => {
                    const user = tweet.user?.screen_name;
                    if (user) {
                        const engagement = (tweet.favorite_count || 0) + (tweet.retweet_count || 0);
                        userEngagement.set(user, (userEngagement.get(user) || 0) + engagement);
                    }
                });
    
                const topSpreaders = Array.from(userEngagement.entries())
                    .sort(([,a], [,b]) => b - a)
                    .slice(0, 10)
                    .map(([user, engagement]) => ({ user, engagement }));
    
                spreadAnalysis.virality_analysis = {
                    spread_velocity: spreadVelocity,
                    peak_spread_hour: peakHour.hour,
                    viral_coefficient: Math.round(allInteractions.length / Math.max(1, timeGroups.size)),
                    spread_pattern: spreadVelocity.length > 5 ? 
                        (peakHour.interactions > spreadVelocity[0].interactions * 3 ? 'Exponential' : 'Linear') : 'Limited',
                    top_spreaders: topSpreaders,
                    reach_estimate: topSpreaders.reduce((sum, spreader) => sum + spreader.engagement, 0),
                    viral_score: Math.min(100, Math.round(
                        (allInteractions.length * 0.3) + 
                        (userEngagement.size * 0.4) + 
                        (peakHour.interactions * 0.3)
                    ))
                };
            }
    
            return createSocialDataResponse(
                formatAnalytics(spreadAnalysis, `Virality Tracking for Tweet ${tweetId}`)
            );
        } catch (error) {
            throw new Error(formatSocialDataError(error as Error, 'virality tracking'));
        }
    };
  • JSON Schema definition for the trackVirality tool, defining input parameters, descriptions, and requirements for tool discovery and validation.
    trackVirality: {
        description: 'Track viral spread patterns and engagement velocity',
        inputSchema: {
            type: 'object',
            properties: {
                tweetId: {
                    type: 'string',
                    description: 'Tweet ID to track virality for'
                },
                trackingPeriod: {
                    type: 'string',
                    description: 'Period to track (default: "24h")'
                },
                analyzeSpread: {
                    type: 'boolean',
                    description: 'Include detailed spread analysis (default: true)'
                }
            },
            required: ['tweetId']
        }
    }
  • TypeScript interface defining the typed arguments for the handleTrackVirality function.
    interface ViralityTrackingArgs {
        tweetId: string;
        trackingPeriod?: string;
        analyzeSpread?: boolean;
    }
  • src/index.ts:499-503 (registration)
    Registration in the main MCP server tool request handler switch statement, dispatching calls to the trackVirality tool to the appropriate handler function.
    case 'trackVirality': {
        const args = request.params.arguments as any;
        response = await handleTrackVirality(client, args);
        break;
    }
Behavior2/5

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

No annotations are provided, so the description carries full burden for behavioral disclosure. 'Track viral spread patterns and engagement velocity' implies a read-only analytics operation, but it doesn't specify whether this requires special permissions, has rate limits, returns real-time vs. historical data, or what the output format looks like. For a tool with no annotation coverage, this leaves significant behavioral gaps.

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 extremely concise with just one sentence containing no wasted words. It's front-loaded with the core purpose and uses efficient phrasing. Every word earns its place in communicating the tool's function.

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, no output schema, and multiple sibling tools with potential overlap, the description is incomplete. It doesn't address when to use this versus similar analytics tools, doesn't describe output format or behavioral constraints, and leaves the agent guessing about the tool's full context. For a 3-parameter analytics tool with rich sibling context, this is inadequate.

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 three parameters thoroughly. The description adds no additional parameter semantics beyond what's in the schema - it doesn't explain how 'trackingPeriod' values affect analysis, what 'analyzeSpread' entails, or provide examples. Baseline 3 is appropriate when schema does the heavy lifting.

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's purpose with specific verbs ('track viral spread patterns' and 'engagement velocity') and identifies the resource (tweets via tweetId parameter). It distinguishes from siblings like 'getTweetById' or 'getThreadMetrics' by focusing on virality analysis rather than retrieval. However, it doesn't explicitly differentiate from 'mapInfluenceNetwork' or 'userInfluenceMetrics' which might have overlapping analytics functions.

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?

The description provides no guidance on when to use this tool versus alternatives. With siblings like 'getThreadMetrics', 'userInfluenceMetrics', and 'mapInfluenceNetwork' that might offer related analytics, there's no indication of when this specific virality tracking tool is preferred. No prerequisites, exclusions, or comparative context are mentioned.

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