getTweetById
Retrieve specific tweet data by its unique ID from the Twitter MCP Server, enabling direct access to tweet details and selected fields for analysis or integration.
Instructions
Get a tweet by its ID
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| tweetFields | No | Fields to include in the tweet object | |
| tweetId | Yes | The ID of the tweet |
Implementation Reference
- src/handlers/tweet.handlers.ts:62-81 (handler)Core handler function that implements the getTweetById tool logic using Twitter API v2 singleTweet method, handles client checks, errors, and formats response.export async function handleGetTweetById( client: TwitterClient | null, { tweetId }: { tweetId: string } ): Promise<HandlerResponse> { if (!client) { return createMissingTwitterApiKeyResponse('Get Tweet by ID'); } try { const tweet = await client.v2.singleTweet(tweetId, { 'tweet.fields': 'created_at,public_metrics,text' }); return createResponse(`Tweet details: ${JSON.stringify(tweet.data, null, 2)}`); } catch (error) { if (error instanceof Error) { throw new Error(formatTwitterError(error, 'getting tweet')); } throw new Error('Failed to get tweet: Unknown error occurred'); } }
- src/tools.ts:142-161 (registration)Tool registration in TOOLS object with description and input schema definition for MCP server.getTweetById: { description: 'Get a tweet by its ID', inputSchema: { type: 'object', properties: { tweetId: { type: 'string', description: 'The ID of the tweet' }, tweetFields: { type: 'array', items: { type: 'string' }, description: 'Fields to include in the tweet object' } }, required: ['tweetId'] } },
- src/index.ts:167-170 (registration)Dispatch logic in CallToolRequestSchema handler that routes getTweetById calls to the tweet handler function.case 'getTweetById': { const { tweetId } = request.params.arguments as { tweetId: string }; response = await handleGetTweetById(client, { tweetId }); break;
- src/types.ts:28-30 (schema)TypeScript interface defining input arguments for getTweetById handler.export interface GetTweetByIdArgs { tweetId: string; }
- src/types.ts:200-207 (schema)Runtime type assertion function for validating getTweetById input arguments.export function assertGetTweetByIdArgs(args: unknown): asserts args is GetTweetByIdArgs { 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'); } }