Skip to main content
Glama
crazyrabbitLTC

Twitter MCP Server

getRetweets

Retrieve a list of retweets for a specific tweet, including custom user details like profile metrics and verification status, using the Twitter MCP Server.

Instructions

Get a list of retweets of a tweet

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
maxResultsNoThe maximum number of results to return (default: 100, max: 100)
tweetIdYesThe ID of the tweet to get retweets for
userFieldsNoAdditional user fields to include in the response

Implementation Reference

  • Main handler function implementing the getRetweets tool logic using Twitter API v2's tweetRetweetedBy method to fetch users who retweeted a specific tweet.
    export const handleGetRetweets: TwitterHandler<GetRetweetsArgs> = async ( client: TwitterClient | null, { tweetId, maxResults = 100, userFields }: GetRetweetsArgs ): Promise<HandlerResponse> => { if (!client) { return createMissingTwitterApiKeyResponse('getRetweets'); } try { const retweets = await client.v2.tweetRetweetedBy(tweetId, { max_results: maxResults, 'user.fields': userFields?.join(',') || 'description,profile_image_url,public_metrics,verified' }); if (!retweets.data || !Array.isArray(retweets.data) || retweets.data.length === 0) { return createResponse(`No retweets found for tweet: ${tweetId}`); } const responseData = { retweetedBy: retweets.data, meta: retweets.meta }; return createResponse(`Users who retweeted: ${JSON.stringify(responseData, null, 2)}`); } catch (error) { if (error instanceof Error) { throw new Error(formatTwitterError(error, 'getting retweets')); } throw error; } };
  • src/tools.ts:229-252 (registration)
    MCP tool registration defining the getRetweets tool's description and input schema.
    getRetweets: { description: 'Get a list of retweets of a tweet', inputSchema: { type: 'object', properties: { tweetId: { type: 'string', description: 'The ID of the tweet to get retweets for' }, 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'] }, description: 'Additional user fields to include in the response' }, }, required: ['tweetId'], }, },
  • TypeScript interface defining the input arguments for getRetweets.
    export interface GetRetweetsArgs { tweetId: string; maxResults?: number; userFields?: string[]; }
  • src/index.ts:202-205 (registration)
    Tool dispatch in the main server request handler switch statement.
    case 'getRetweets': { const { tweetId, maxResults } = request.params.arguments as { tweetId: string; maxResults?: number }; response = await handleGetRetweets(client, { tweetId, maxResults }); break;
  • Runtime assertion helper function to validate getRetweets arguments.
    export function assertGetRetweetsArgs(args: unknown): asserts args is GetRetweetsArgs { if (typeof args !== 'object' || args === null) { throw new Error('Invalid arguments: expected object'); } if (!('tweetId' in args) || typeof (args as any).tweetId !== 'string') { throw new Error('Invalid arguments: expected tweetId string'); } if ('maxResults' in args) { const maxResults = (args as any).maxResults; if (typeof maxResults !== 'number' || maxResults < 1 || maxResults > 100) { throw new Error('Invalid arguments: maxResults must be a number between 1 and 100'); } } if ('userFields' in args) { if (!Array.isArray((args as any).userFields)) { throw new Error('Invalid arguments: expected userFields to be an array'); } for (const field of (args as any).userFields) { if (typeof field !== 'string') { throw new Error('Invalid arguments: expected userFields to be an array of strings'); } } } }

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