Skip to main content
Glama
crazyrabbitLTC

Twitter MCP Server

getListMembers

Retrieve members from a Twitter list by specifying the list ID, with options to limit results and include additional user details.

Instructions

Get members of a Twitter list

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
listIdYesThe ID of the list
maxResultsNoThe maximum number of results to return (default: 100, max: 100)
userFieldsNoAdditional user fields to include in the response

Implementation Reference

  • The main handler function that executes the getListMembers tool logic: validates client, prepares options, calls TwitterClient.getListMembers, formats and returns the response.
    export async function handleGetListMembers(
        client: TwitterClient | null,
        args: GetListMembersArgs
    ): Promise<HandlerResponse> {
        if (!client) {
            return createMissingTwitterApiKeyResponse('getListMembers');
        }
        try {
            const options = {
                max_results: args.maxResults,
                pageLimit: args.pageLimit,
                'user.fields': args.userFields
            };
    
            const members = await client.getListMembers(args.listId, options);
    
            if (!members.data || !Array.isArray(members.data) || members.data.length === 0) {
                return createResponse(`No members found for list ${args.listId}`);
            }
    
            const memberCount = members.meta?.result_count || members.data.length;
            let responseText = `Found ${memberCount} members in list ${args.listId}:\n\n`;
    
            members.data.forEach((member) => {
                responseText += `- ${member.name} (@${member.username})\n`;
            });
    
            if (members.meta?.total_retrieved === args.maxResults) {
                responseText += '\nNote: Maximum requested results reached. There might be more members available.';
            }
    
            return createResponse(responseText);
        } catch (error) {
            if (error instanceof Error) {
                throw new Error(formatTwitterError(error, 'getting list members'));
            }
            throw new Error('Failed to get list members: Unknown error occurred');
        }
    } 
  • src/index.ts:299-306 (registration)
    Registration and dispatch of the getListMembers tool in the MCP server's CallToolRequestSchema handler.
    case 'getListMembers': {
        const { listId, maxResults, userFields } = request.params.arguments as {
            listId: string;
            maxResults?: number;
            userFields?: string[];
        };
        response = await handleGetListMembers(client, { listId, maxResults, userFields });
        break;
  • MCP tool schema definition for getListMembers, including description and inputSchema.
    getListMembers: {
        description: 'Get members of a Twitter list',
        inputSchema: {
            type: 'object',
            properties: {
                listId: { type: 'string', description: 'The ID of the list' },
                maxResults: { 
                    type: 'number', 
                    description: 'The maximum number of results to return (default: 100, max: 100)',
                    minimum: 1,
                    maximum: 100
                },
                userFields: { 
                    type: 'array', 
                    items: { 
                        type: 'string',
                        enum: ['description', 'profile_image_url', 'public_metrics', 'verified', 'location', 'url']
                    },
                    description: 'Additional user fields to include in the response'
                },
            },
            required: ['listId'],
        },
    },
  • TwitterClient helper method that implements paginated fetching of list members using twitter-api-v2.
    async getListMembers(listId: string, options: any): Promise<PaginatedResponse<UserV2>> {
        const paginationOptions: PaginationOptions = {
            maxResults: options.max_results,
            pageLimit: options.pageLimit
        };
    
        const allMembers: UserV2[] = [];
        const iterator = this.paginateResults<UserV2, UserListMembersV2Paginator>(
            'getListMembers',
            () => this.v2.listMembers(listId, {
                ...options,
                max_results: Math.min(options.max_results || MAX_RESULTS_PER_PAGE, MAX_RESULTS_PER_PAGE)
            }),
            paginationOptions
        );
    
        for await (const members of iterator) {
            allMembers.push(...members);
            if (paginationOptions.maxResults && allMembers.length >= paginationOptions.maxResults) {
                allMembers.length = paginationOptions.maxResults;
                break;
            }
        }
    
        return {
            data: allMembers,
            meta: {
                result_count: allMembers.length,
                total_retrieved: allMembers.length
            }
        };
    }

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