Skip to main content
Glama
crazyrabbitLTC

Twitter MCP Server

mapInfluenceNetwork

Analyze Twitter user influence by mapping connections and patterns around a central account to understand network relationships.

Instructions

Map user influence network and connection patterns

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
centerUserYesCentral user to map network around
depthNoNetwork depth to analyze (default: 2)
connectionTypesNoTypes of connections to analyze

Implementation Reference

  • Main handler function implementing the mapInfluenceNetwork tool. Builds an influence network by analyzing tweet mentions to/from the center user, calculating metrics like incoming/outgoing connections, influence scores, and network insights.
    export const handleMapInfluenceNetwork: SocialDataHandler<NetworkMappingArgs> = async (
        _client: any,
        { centerUser, depth = 2, connectionTypes = ['followers', 'following', 'mutual'] }: NetworkMappingArgs
    ) => {
        try {
            const socialClient = getSocialDataClient();
            
            if (!socialClient) {
                return createMissingApiKeyResponse('Influence Network Mapping');
            }
            
            // Get users who frequently interact with the center user
            const mentionsQuery = `@${centerUser}`;
            const mentionsResult = await socialClient.searchTweets({
                query: mentionsQuery,
                maxResults: 100
            });
    
            // Get users the center user mentions
            const centerMentionsQuery = `from:${centerUser} @`;
            const centerMentionsResult = await socialClient.searchTweets({
                query: centerMentionsQuery,
                maxResults: 50
            });
    
            // Build network map
            const networkNodes = new Map();
            
            // Add center user
            networkNodes.set(centerUser, {
                username: centerUser,
                type: 'center',
                connections: [],
                influence_score: 100
            });
    
            // Process mentions TO the center user (incoming connections)
            const incomingConnections = new Map();
            mentionsResult.data?.forEach((tweet: any) => {
                const user = tweet.user;
                if (user && user.screen_name !== centerUser) {
                    const existing = incomingConnections.get(user.screen_name) || 0;
                    incomingConnections.set(user.screen_name, existing + 1);
                    
                    if (!networkNodes.has(user.screen_name)) {
                        networkNodes.set(user.screen_name, {
                            username: user.screen_name,
                            name: user.name,
                            type: 'incoming',
                            mention_frequency: existing + 1,
                            followers_count: user.followers_count,
                            verified: user.verified,
                            influence_score: Math.min(90, (user.followers_count || 0) / 1000)
                        });
                    }
                }
            });
    
            // Process mentions FROM the center user (outgoing connections)
            const outgoingConnections = new Set();
            centerMentionsResult.data?.forEach((tweet: any) => {
                const mentions = tweet.text?.match(/@(\w+)/g) || [];
                mentions.forEach((mention: string) => {
                    const username = mention.substring(1);
                    if (username !== centerUser) {
                        outgoingConnections.add(username);
                        
                        if (!networkNodes.has(username)) {
                            networkNodes.set(username, {
                                username,
                                type: 'outgoing',
                                influence_score: 50
                            });
                        }
                    }
                });
            });
    
            // Calculate network metrics
            const networkMap = {
                center_user: centerUser,
                network_depth: depth,
                total_nodes: networkNodes.size,
                connection_types: connectionTypes,
                network_metrics: {
                    incoming_connections: incomingConnections.size,
                    outgoing_connections: outgoingConnections.size,
                    total_unique_connections: new Set([...incomingConnections.keys(), ...outgoingConnections]).size,
                    network_density: Math.round((incomingConnections.size + outgoingConnections.size) / 2),
                    influence_centrality: Math.min(100, (incomingConnections.size * 2) + outgoingConnections.size)
                },
                top_connected_users: Array.from(networkNodes.values())
                    .filter(node => node.type !== 'center')
                    .sort((a, b) => (b.influence_score || 0) - (a.influence_score || 0))
                    .slice(0, 15)
                    .map(node => ({
                        username: node.username,
                        name: node.name,
                        connection_type: node.type,
                        influence_score: Math.round(node.influence_score || 0),
                        followers: node.followers_count,
                        verified: node.verified
                    })),
                network_insights: {
                    most_active_mentioner: Array.from(incomingConnections.entries())
                        .sort(([,a], [,b]) => b - a)[0]?.[0] || 'None',
                    network_reach_estimate: Math.round(
                        Array.from(networkNodes.values())
                            .reduce((sum, node) => sum + (node.followers_count || 0), 0) / 1000
                    ) + 'K',
                    connection_strength: incomingConnections.size > 20 ? 'Strong' : 
                                       incomingConnections.size > 5 ? 'Moderate' : 'Developing'
                }
            };
    
            return createSocialDataResponse(
                formatAnalytics(networkMap, `Influence Network Map for @${centerUser}`)
            );
        } catch (error) {
            throw new Error(formatSocialDataError(error as Error, 'influence network mapping'));
        }
    };
  • Input schema definition and description for the mapInfluenceNetwork tool, specifying parameters like centerUser, depth, and connectionTypes.
    mapInfluenceNetwork: {
        description: 'Map user influence network and connection patterns',
        inputSchema: {
            type: 'object',
            properties: {
                centerUser: {
                    type: 'string',
                    description: 'Central user to map network around'
                },
                depth: {
                    type: 'number',
                    description: 'Network depth to analyze (default: 2)',
                    minimum: 1,
                    maximum: 3
                },
                connectionTypes: {
                    type: 'array',
                    items: {
                        type: 'string',
                        enum: ['followers', 'following', 'mutual']
                    },
                    description: 'Types of connections to analyze'
                }
            },
            required: ['centerUser']
        }
    },
  • src/tools.ts:736-738 (registration)
    Registers the mapInfluenceNetwork tool by spreading SOCIALDATA_TOOLS into the main TOOLS object used by the MCP server for listTools.
        // SocialData.tools enhanced research and analytics
        ...SOCIALDATA_TOOLS
    }; 
  • src/index.ts:483-486 (registration)
    Dispatches calls to the mapInfluenceNetwork tool handler in the main CallToolRequestSchema handler switch statement.
    case 'mapInfluenceNetwork': {
        const args = request.params.arguments as any;
        response = await handleMapInfluenceNetwork(client, args);
        break;
  • Re-exports the handleMapInfluenceNetwork handler from network.handlers.ts, making it available for import in src/index.ts.
    export * from './network.handlers.js';

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