Skip to main content
Glama
crazyrabbitLTC

Twitter MCP Server

getThreadMetrics

Analyze Twitter thread performance and engagement distribution to measure audience interaction and content effectiveness.

Instructions

Analyze thread performance and engagement distribution

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
tweetIdYesThe thread root tweet ID
analyzeEngagementNoInclude detailed engagement analysis (default: true)
timeframeNoAnalysis timeframe (default: "24h")

Implementation Reference

  • Main handler function implementing getThreadMetrics: fetches conversation tweets using SocialData client, computes aggregate engagement metrics (likes, retweets, replies), per-tweet averages, engagement distribution across thread positions, and identifies top-performing tweet.
    export const handleGetThreadMetrics: SocialDataHandler<ThreadMetricsArgs> = async (
        _client: any,
        { tweetId, analyzeEngagement = true, timeframe = '24h' }: ThreadMetricsArgs
    ) => {
        try {
            const socialClient = getSocialDataClient();
            
            if (!socialClient) {
                return createMissingApiKeyResponse('Thread Metrics Analysis');
            }
            
            // Get thread data
            const threadQuery = `conversation_id:${tweetId}`;
            const threadResult = await socialClient.searchTweets({
                query: threadQuery,
                maxResults: 100
            });
    
            const tweets = threadResult.data || [];
            
            if (tweets.length === 0) {
                return createSocialDataResponse(`No thread data found for tweet ${tweetId}`);
            }
    
            let metrics: any = {
                thread_id: tweetId,
                thread_length: tweets.length,
                timeframe_analyzed: timeframe
            };
    
            if (analyzeEngagement) {
                const totalLikes = tweets.reduce((sum: number, tweet: any) => 
                    sum + (tweet.favorite_count || 0), 0);
                const totalRetweets = tweets.reduce((sum: number, tweet: any) => 
                    sum + (tweet.retweet_count || 0), 0);
                const totalReplies = tweets.reduce((sum: number, tweet: any) => 
                    sum + (tweet.reply_count || 0), 0);
    
                metrics.engagement_metrics = {
                    total_likes: totalLikes,
                    total_retweets: totalRetweets,
                    total_replies: totalReplies,
                    avg_likes_per_tweet: Math.round(totalLikes / tweets.length),
                    avg_retweets_per_tweet: Math.round(totalRetweets / tweets.length),
                    engagement_distribution: tweets.map((tweet: any, index: number) => ({
                        position: index + 1,
                        likes: tweet.favorite_count || 0,
                        retweets: tweet.retweet_count || 0,
                        engagement_score: (tweet.favorite_count || 0) + (tweet.retweet_count || 0) * 2
                    })).sort((a: any, b: any) => b.engagement_score - a.engagement_score)
                };
    
                // Find the most engaging tweet in thread
                const topTweet = metrics.engagement_metrics.engagement_distribution[0];
                metrics.top_performing_tweet = {
                    position: topTweet.position,
                    engagement_score: topTweet.engagement_score,
                    performance_boost: tweets.length > 1 ? 
                        Math.round((topTweet.engagement_score / (totalLikes + totalRetweets * 2)) * 100) : 100
                };
            }
    
            return createSocialDataResponse(
                formatAnalytics(metrics, `Thread Performance Metrics for ${tweetId}`)
            );
        } catch (error) {
            throw new Error(formatSocialDataError(error as Error, 'thread metrics analysis'));
        }
    };
  • src/index.ts:467-470 (registration)
    Tool call registration in main server request handler switch statement: routes 'getThreadMetrics' calls to the handleGetThreadMetrics function.
    case 'getThreadMetrics': {
        const args = request.params.arguments as any;
        response = await handleGetThreadMetrics(client, args);
        break;
  • Tool schema definition in SOCIALDATA_TOOLS object: includes description and Zod-compatible inputSchema for listing and validation.
    getThreadMetrics: {
        description: 'Analyze thread performance and engagement distribution',
        inputSchema: {
            type: 'object',
            properties: {
                tweetId: {
                    type: 'string',
                    description: 'The thread root tweet ID'
                },
                analyzeEngagement: {
                    type: 'boolean',
                    description: 'Include detailed engagement analysis (default: true)'
                },
                timeframe: {
                    type: 'string',
                    description: 'Analysis timeframe (default: "24h")'
                }
            },
            required: ['tweetId']
        }
    },
  • TypeScript interface defining input arguments for the handler function.
    export interface ThreadMetricsArgs {
        tweetId: string;
        analyzeEngagement?: boolean;
        timeframe?: string;
    }
Behavior2/5

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

No annotations are provided, so the description carries the full burden of behavioral disclosure. It mentions 'performance and engagement distribution' but lacks details on what metrics are returned, rate limits, authentication needs, or data freshness. For an analysis tool with no annotations, this leaves significant gaps in understanding its behavior.

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 front-loaded and appropriately sized for its purpose, making it easy to parse without unnecessary elaboration.

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 a 3-parameter tool for analysis, the description is incomplete. It doesn't explain return values, error conditions, or behavioral traits, leaving the agent with insufficient context to use the tool effectively beyond basic parameter input.

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 all parameters (tweetId, analyzeEngagement, timeframe). The description adds no additional meaning beyond the schema, such as explaining what 'engagement distribution' entails or how the timeframe affects analysis. 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.

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 as 'Analyze thread performance and engagement distribution,' which specifies the verb ('analyze') and resource ('thread performance and engagement distribution'). It distinguishes from siblings like getConversation or getFullThread by focusing on metrics/analysis rather than retrieval, though it doesn't explicitly name alternatives.

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. It doesn't mention prerequisites, context, or exclusions, such as how it differs from other analysis tools like analyzeSentiment or trackVirality. The agent must infer usage from the name and parameters 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