Skip to main content
Glama
crazyrabbitLTC

Twitter MCP Server

getTweetById

Retrieve specific tweets using their unique ID to access content, metadata, and user information from Twitter's platform.

Instructions

Get a tweet by its ID

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
tweetIdYesThe ID of the tweet
tweetFieldsNoFields to include in the tweet object

Implementation Reference

  • The main handler function that implements the getTweetById tool logic. It uses the TwitterClient to fetch a single tweet by ID via the v2 API, including fields like created_at, public_metrics, and text. Handles missing client and errors appropriately.
    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/index.ts:167-170 (registration)
    Registration and dispatch point in the MCP server request handler. Matches the tool name and calls the handleGetTweetById function with parsed arguments.
    case 'getTweetById': { const { tweetId } = request.params.arguments as { tweetId: string }; response = await handleGetTweetById(client, { tweetId }); break;
  • Tool schema definition used for listing tools and input validation. Defines the input schema with required tweetId string and optional tweetFields array.
    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'] } },
  • TypeScript interface defining the arguments for getTweetById.
    export interface GetTweetByIdArgs { tweetId: string; }
  • Runtime assertion function to validate getTweetById 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'); } }

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