getFollowing
Fetch and display a list of users a specific Twitter account is following, including optional details like profile info, metrics, and verification status.
Instructions
Get a list of users that a user is following
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| maxResults | No | The maximum number of results to return (default: 100, max: 1000) | |
| userFields | No | Additional user fields to include in the response | |
| username | Yes | The username of the user whose following list to fetch |
Implementation Reference
- src/handlers/user.handlers.ts:152-190 (handler)Core handler function that implements the getFollowing tool logic by fetching the list of users a Twitter user is following via Twitter API v2.following endpoint.export const handleGetFollowing: TwitterHandler<GetFollowingArgs> = async ( client: TwitterClient | null, { username, maxResults, userFields }: GetFollowingArgs ): Promise<HandlerResponse> => { if (!client) { return createMissingTwitterApiKeyResponse('getFollowing'); } try { const user = await client.v2.userByUsername(username); if (!user.data) { throw new Error(`User not found: ${username}`); } const following = await client.v2.following(user.data.id, { max_results: maxResults, 'user.fields': userFields?.join(',') || 'description,profile_image_url,public_metrics,verified' }); if (!following.data || !Array.isArray(following.data) || following.data.length === 0) { return createResponse(`User ${username} is not following anyone`); } const responseData = { following: following.data, meta: following.meta }; return createResponse(`Users followed by ${username}: ${JSON.stringify(responseData, null, 2)}`); } catch (error) { if (error instanceof Error) { if (error.message.includes('403')) { throw new Error(`Get following functionality requires elevated permissions. This endpoint may require Pro tier access ($5,000/month) or special permission approval from X. Current Basic tier ($200/month) has limited access to following data for privacy reasons. Contact X Developer Support or consider upgrading at https://developer.x.com/en/portal/products/pro`); } throw new Error(formatTwitterError(error, 'getting following')); } throw error; } };
- src/tools.ts:297-320 (schema)MCP tool definition including description and input schema validation for getFollowing.getFollowing: { description: 'Get a list of users that a user is following', inputSchema: { type: 'object', properties: { username: { type: 'string', description: 'The username of the user whose following list to fetch' }, maxResults: { type: 'number', description: 'The maximum number of results to return (default: 100, max: 1000)', minimum: 1, maximum: 1000 }, 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: ['username'], }, },
- src/index.ts:275-278 (registration)MCP server request handler registration that routes 'getFollowing' tool calls to the handleGetFollowing function.case 'getFollowing': { const { username, maxResults } = request.params.arguments as { username: string; maxResults?: number }; response = await handleGetFollowing(client, { username, maxResults }); break;
- src/types.ts:83-87 (schema)TypeScript interface defining input arguments for the getFollowing handler.export interface GetFollowingArgs { username: string; maxResults?: number; userFields?: string[]; }
- src/handlers/user.handlers.ts:26-29 (helper)Local interface extension for getFollowing arguments in the user handlers file.interface GetFollowingArgs extends UserHandlerArgs { maxResults?: number; userFields?: string[]; }