getConversationTree
Analyze and map the full structure of Twitter conversations, including replies and quotes, starting from a root tweet ID, with customizable depth and quote inclusion settings.
Instructions
Map complete conversation structure including replies and quotes
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| includeQuotes | No | Include quote tweets in analysis (default: true) | |
| maxDepth | No | Maximum conversation depth to analyze (default: 3) | |
| tweetId | Yes | The root tweet ID to map conversation for |
Implementation Reference
- The core implementation of the getConversationTree tool handler. Fetches direct replies and optional quote tweets using SocialData client, builds a structured conversation tree with engagement metrics, and formats the response.export const handleGetConversationTree: SocialDataHandler<ConversationTreeArgs> = async ( _client: any, { tweetId, maxDepth = 3, includeQuotes = true }: ConversationTreeArgs ) => { try { const socialClient = getSocialDataClient(); if (!socialClient) { return createMissingApiKeyResponse('Conversation Tree Analysis'); } // Get direct replies const repliesQuery = `to:* ${tweetId}`; const repliesResult = await socialClient.searchTweets({ query: repliesQuery, maxResults: 50 }); // Get quote tweets if requested let quoteTweets: any[] = []; if (includeQuotes) { const quotesQuery = `url:${tweetId} OR ${tweetId}`; const quotesResult = await socialClient.searchTweets({ query: quotesQuery, maxResults: 25 }); quoteTweets = quotesResult.data || []; } const conversationTree = { root_tweet_id: tweetId, max_depth_analyzed: maxDepth, direct_replies: { count: repliesResult.data?.length || 0, tweets: repliesResult.data?.map((tweet: any) => ({ id: tweet.id_str, text: tweet.text?.substring(0, 280), author: tweet.user?.screen_name, created_at: tweet.tweet_created_at, metrics: { likes: tweet.favorite_count || 0, retweets: tweet.retweet_count || 0 } })) || [] }, quote_tweets: { count: quoteTweets.length, tweets: quoteTweets.map((tweet: any) => ({ id: tweet.id_str, text: tweet.text?.substring(0, 280), author: tweet.user?.screen_name, created_at: tweet.tweet_created_at })) }, engagement_summary: { total_interactions: (repliesResult.data?.length || 0) + quoteTweets.length, reply_rate: repliesResult.data?.length || 0, quote_rate: quoteTweets.length } }; return createSocialDataResponse( formatAnalytics(conversationTree, `Conversation Tree for ${tweetId}`) ); } catch (error) { throw new Error(formatSocialDataError(error as Error, 'conversation tree analysis')); } };
- src/socialdata-tools.ts:194-216 (schema)Input schema and description definition for the getConversationTree tool, specifying parameters: tweetId (required), maxDepth (1-5), includeQuotes (boolean).getConversationTree: { description: 'Map complete conversation structure including replies and quotes', inputSchema: { type: 'object', properties: { tweetId: { type: 'string', description: 'The root tweet ID to map conversation for' }, maxDepth: { type: 'number', description: 'Maximum conversation depth to analyze (default: 3)', minimum: 1, maximum: 5 }, includeQuotes: { type: 'boolean', description: 'Include quote tweets in analysis (default: true)' } }, required: ['tweetId'] } },
- src/tools.ts:736-738 (registration)Tool registration: spreads all SOCIALDATA_TOOLS (including getConversationTree schema) into the main TOOLS object exported for MCP ListTools handler.// SocialData.tools enhanced research and analytics ...SOCIALDATA_TOOLS };
- src/index.ts:462-465 (registration)Runtime dispatch registration in MCP CallToolRequestHandler: maps 'getConversationTree' tool calls to the handleGetConversationTree function.case 'getConversationTree': { const args = request.params.arguments as any; response = await handleGetConversationTree(client, args); break;