Skip to main content
Glama
crazyrabbitLTC

Twitter MCP Server

createMediaMessage

Send direct messages with media attachments on Twitter by specifying recipient ID, text content, and media ID.

Instructions

Send a direct message with media attachments

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
recipientIdYesThe ID of the user to send the message to
textYesThe text content of the direct message
mediaIdYesThe media ID of the uploaded media to attach
mediaTypeNoMIME type of the media file
altTextNoAlternative text for the media (accessibility)

Implementation Reference

  • The main handler function that executes the createMediaMessage tool. It sends a direct message with media using Twitter API v1.sendDm, handles errors like missing client, user/media not found, size limits, and unsupported types.
    export const handleCreateMediaMessage: TwitterHandler<CreateMediaMessageArgs> = async (
        client: TwitterClient | null,
        { recipientId, text, mediaId, altText }: CreateMediaMessageArgs
    ): Promise<HandlerResponse> => {
        if (!client) {
            return createMissingTwitterApiKeyResponse('createMediaMessage');
        }
        try {
            // Using v1 API for sending DMs with media
            const dmParams: any = {
                recipient_id: recipientId,
                text,
                media_id: mediaId
            };
    
            const result = await client.v1.sendDm(dmParams);
    
            return createResponse(`Direct message with media sent successfully to user ${recipientId}. Response: ${JSON.stringify(result, null, 2)}`);
        } catch (error) {
            if (error instanceof Error) {
                if (error.message.includes('404')) {
                    throw new Error(`Failed to send media message: User ${recipientId} not found or media ${mediaId} not found.`);
                } else if (error.message.includes('413')) {
                    throw new Error(`Failed to send media message: Media file too large. Check Twitter's media size limits.`);
                } else if (error.message.includes('415')) {
                    throw new Error(`Failed to send media message: Unsupported media type. Check Twitter's supported media formats.`);
                }
                throw new Error(formatTwitterError(error, 'sending media message'));
            }
            throw error;
        }
    }; 
  • TypeScript interface defining the input parameters for the createMediaMessage handler.
    export interface CreateMediaMessageArgs {
        recipientId: string;
        text: string;
        mediaId: string;
        mediaType?: string;
        altText?: string;
    }
  • Input schema definition for the createMediaMessage tool used for MCP validation.
    createMediaMessage: {
        description: 'Send a direct message with media attachments',
        inputSchema: {
            type: 'object',
            properties: {
                recipientId: { 
                    type: 'string', 
                    description: 'The ID of the user to send the message to' 
                },
                text: { 
                    type: 'string', 
                    description: 'The text content of the direct message' 
                },
                mediaId: { 
                    type: 'string', 
                    description: 'The media ID of the uploaded media to attach' 
                },
                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: ['recipientId', 'text', 'mediaId']
        }
    },
  • src/index.ts:376-385 (registration)
    Tool registration in the MCP server's CallToolRequestSchema handler switch statement, dispatching to the specific handler function.
    case 'createMediaMessage': {
        const { recipientId, text, mediaId, mediaType, altText } = request.params.arguments as {
            recipientId: string;
            text: string;
            mediaId: string;
            mediaType?: string;
            altText?: string;
        };
        response = await handleCreateMediaMessage(client, { recipientId, text, mediaId, mediaType, altText });
        break;
  • src/tools.ts:582-611 (registration)
    Tool definition and registration in the TOOLS object used by the MCP server for listing and validating tools.
    createMediaMessage: {
        description: 'Send a direct message with media attachments',
        inputSchema: {
            type: 'object',
            properties: {
                recipientId: { 
                    type: 'string', 
                    description: 'The ID of the user to send the message to' 
                },
                text: { 
                    type: 'string', 
                    description: 'The text content of the direct message' 
                },
                mediaId: { 
                    type: 'string', 
                    description: 'The media ID of the uploaded media to attach' 
                },
                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: ['recipientId', 'text', 'mediaId']
        }
    },
Behavior2/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure. While 'Send' implies a write operation, it doesn't specify whether this requires specific permissions, whether media attachments are limited in size or type beyond the enum, what happens if the recipient doesn't exist, or what the response looks like. For a mutation tool with zero annotation coverage, this leaves significant behavioral gaps.

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 that gets straight to the point with zero wasted words. It's appropriately sized for a tool with good schema documentation and follows the principle of front-loading the most important information.

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

Completeness3/5

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

For a media-sending tool with 5 parameters and no output schema, the description is minimally adequate but has clear gaps. The schema handles parameter documentation well, but without annotations or output schema, the description should ideally cover more behavioral aspects like error conditions, response format, or usage constraints. It's complete enough to understand what the tool does but not how to use it effectively.

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?

The schema description coverage is 100%, so the schema already documents all 5 parameters thoroughly. The description adds no additional parameter information beyond what's in the schema - it doesn't explain relationships between parameters (e.g., that mediaId must correspond to previously uploaded media) or provide usage examples. With complete schema coverage, the baseline of 3 is appropriate.

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 ('Send a direct message') and resource ('with media attachments'), making the purpose immediately understandable. However, it doesn't differentiate from sibling tools like 'sendDirectMessage' (which presumably sends text-only messages) or 'postTweetWithMedia' (which posts to a public timeline rather than sending direct messages).

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 about when to use this tool versus alternatives. It doesn't mention when to choose this over 'sendDirectMessage' (for text-only messages) or 'postTweetWithMedia' (for public posts with media), nor does it specify prerequisites like needing to upload media first or mention any usage constraints.

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