Skip to main content
Glama
crazyrabbitLTC

Twitter MCP Server

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
NameRequiredDescriptionDefault
tweetFieldsNoFields to include in the tweet object
tweetIdYesThe ID of the tweet

Implementation Reference

  • 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;
  • TypeScript interface defining input arguments for getTweetById handler.
    export interface GetTweetByIdArgs { tweetId: string; }
  • 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'); } }

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