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');
        }
    }
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries the full burden. It states 'Get a tweet by its ID', implying a read-only operation, but doesn't disclose behavioral traits like rate limits, authentication needs, error handling (e.g., for invalid IDs), or response format. For a tool with zero annotation coverage, this is a significant gap in transparency.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence: 'Get a tweet by its ID'. It's front-loaded with the core action and resource, with zero wasted words. This is appropriately sized for a straightforward tool, making it easy to parse quickly.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given no annotations, no output schema, and a simple input schema, the description is incomplete. It doesn't cover behavioral aspects like rate limits or auth, response format, or usage context. For a tool in a complex server with many siblings, more guidance is needed to ensure correct invocation, making it inadequate overall.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, with clear descriptions for tweetId and tweetFields. The description adds no parameter semantics beyond what the schema provides, such as examples of tweetFields values or ID format. With high schema coverage, the baseline is 3, as the description doesn't compensate but also doesn't detract.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description 'Get a tweet by its ID' clearly states the action (get) and resource (tweet), specifying it's by ID. It distinguishes from siblings like getTweetsByIds (plural) and getConversation (by context), but doesn't explicitly contrast them. The purpose is specific and unambiguous, though it could be more precise about differentiation.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives like getTweetsByIds (for multiple IDs), getConversation (for thread context), or searchTweets (for broader queries). It lacks context about prerequisites, such as needing a valid tweet ID, or exclusions, leaving the agent to infer usage from the name alone.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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