Skip to main content
Glama
crazyrabbitLTC

Twitter MCP Server

postTweetWithMedia

Post tweets with attached media files to Twitter, including images or videos with accessibility text, through the MCP server.

Instructions

Post a tweet with media attachment to Twitter

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
textYesThe text of the tweet
mediaPathYesLocal file path to the media to upload
mediaTypeYesMIME type of the media file
altTextNoAlternative text for the media (accessibility)

Implementation Reference

  • The core handler function that implements the postTweetWithMedia tool logic: checks for client, uploads media, optionally sets alt text, posts the tweet with media using Twitter API v1/v2, and returns success or formatted error.
    export async function handlePostTweetWithMedia(
        client: TwitterClient | null,
        { text, mediaPath, mediaType, altText }: MediaTweetHandlerArgs
    ): Promise<HandlerResponse> {
        if (!client) {
            return createMissingTwitterApiKeyResponse('Post Tweet with Media');
        }
    
        try {
            // Upload media
            const mediaId = await client.v1.uploadMedia(mediaPath, { type: mediaType });
            
            // Set alt text if provided
            if (altText) {
                await client.v1.createMediaMetadata(mediaId, { alt_text: { text: altText } });
            }
    
            // Post tweet with media
            const tweet = await client.v2.tweet(text, { media: { media_ids: [mediaId] } });
            return createResponse(`Successfully posted tweet with media: ${tweet.data.id}`);
        } catch (error) {
            if (error instanceof Error) {
                throw new Error(formatTwitterError(error, 'posting tweet with media'));
            }
            throw new Error('Failed to post tweet with media: Unknown error occurred');
        }
    }
  • Defines the MCP tool 'postTweetWithMedia' including its description and input schema (JSON schema) used for validation and tool listing.
    postTweetWithMedia: {
        description: 'Post a tweet with media attachment to Twitter',
        inputSchema: {
            type: 'object',
            properties: {
                text: { type: 'string', description: 'The text of the tweet' },
                mediaPath: { type: 'string', description: 'Local file path to the media to upload' },
                mediaType: { 
                    type: 'string', 
                    enum: ['image/jpeg', 'image/png', 'image/gif', 'video/mp4'],
                    description: 'MIME type of the media file'
                },
                altText: { 
                    type: 'string', 
                    description: 'Alternative text for the media (accessibility)'
                }
            },
            required: ['text', 'mediaPath', 'mediaType'],
        },
    },
  • src/index.ts:157-165 (registration)
    In the MCP CallToolRequest handler switch statement, registers and dispatches 'postTweetWithMedia' tool calls to the handlePostTweetWithMedia function.
    case 'postTweetWithMedia': {
        const { text, mediaPath, mediaType, altText } = request.params.arguments as { 
            text: string;
            mediaPath: string;
            mediaType: string;
            altText?: string;
        };
        response = await handlePostTweetWithMedia(client, { text, mediaPath, mediaType, altText });
        break;
  • TypeScript interface defining the input arguments for postTweetWithMedia, used for type safety in handlers.
    export interface PostTweetWithMediaArgs {
        text: string;
        mediaPath: string;
        mediaType: 'image/jpeg' | 'image/png' | 'image/gif' | 'video/mp4';
        altText?: string;
    }
Behavior2/5

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

With no annotations provided, the description carries full burden for behavioral disclosure. While 'Post a tweet' implies a write/mutation operation, the description doesn't mention authentication requirements, rate limits, character limits for text, media size restrictions, or what happens on success/failure. For a mutation tool with zero annotation coverage, this is a significant gap in behavioral 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 with zero wasted words. It's appropriately sized for a straightforward tool and front-loads the core functionality immediately. Every word earns its place in this concise formulation.

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?

For a mutation tool with no annotations and no output schema, the description is incomplete. It doesn't explain what happens after posting (e.g., returns tweet ID, success status), doesn't mention authentication requirements, and doesn't address constraints like media size limits or text character limits. Given the complexity of posting media to Twitter, this leaves significant gaps for an AI agent.

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%, so the schema already documents all four parameters thoroughly. The description adds no additional parameter semantics beyond what's in the schema (text, mediaPath, mediaType, altText). Baseline score of 3 is appropriate when the schema does the heavy lifting for parameter documentation.

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 clearly states the action ('Post a tweet with media attachment') and target resource ('to Twitter'), providing specific verb+resource combination. However, it doesn't distinguish this tool from its sibling 'postTweet' (which presumably posts tweets without media), missing explicit differentiation that would earn a perfect score.

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 'postTweet' (for text-only tweets) or 'createMediaMessage' (for media in direct messages). There's no mention of prerequisites, constraints, or appropriate contexts for this specific media-posting functionality.

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