Skip to main content
Glama
crazyrabbitLTC

Twitter MCP Server

sendDirectMessage

Send private messages to Twitter users with text and optional media attachments for direct communication.

Instructions

Send a direct message to a specified user

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
recipientIdYesThe ID of the user to send the message to
textYesThe text content of the direct message
mediaIdNoOptional media ID for attaching media to the message
attachmentsNoOptional array of media IDs to attach to the message

Implementation Reference

  • The handler function that implements the core logic for the 'sendDirectMessage' tool, using Twitter API v1 to send direct messages with optional media.
    export const handleSendDirectMessage: TwitterHandler<SendDirectMessageArgs> = async (
        client: TwitterClient | null,
        { recipientId, text, mediaId }: SendDirectMessageArgs
    ): Promise<HandlerResponse> => {
        if (!client) {
            return createMissingTwitterApiKeyResponse('sendDirectMessage');
        }
        try {
            const dmParams: any = {
                recipient_id: recipientId,
                text
            };
    
            // Add media if provided
            if (mediaId) {
                dmParams.media_id = mediaId;
            }
    
            const result = await client.v1.sendDm(dmParams);
    
            return createResponse(`Direct message 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 direct message: User ${recipientId} not found or cannot receive messages.`);
                }
                throw new Error(formatTwitterError(error, 'sending direct message'));
            }
            throw error;
        }
    };
  • MCP tool schema definition for 'sendDirectMessage', including description and input schema validation.
    sendDirectMessage: {
        description: 'Send a direct message to a specified user',
        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: 'Optional media ID for attaching media to the message' 
                },
                attachments: { 
                    type: 'array', 
                    items: { type: 'string' },
                    description: 'Optional array of media IDs to attach to the message' 
                }
            },
            required: ['recipientId', 'text']
        }
    },
  • TypeScript interface defining the input arguments for the sendDirectMessage handler.
    export interface SendDirectMessageArgs {
        recipientId: string;
        text: string;
        mediaId?: string;
        attachments?: string[];
    }
  • src/index.ts:328-336 (registration)
    Dispatch registration in the CallToolRequestHandler switch statement that calls the sendDirectMessage handler.
    case 'sendDirectMessage': {
        const { recipientId, text, mediaId, attachments } = request.params.arguments as {
            recipientId: string;
            text: string;
            mediaId?: string;
            attachments?: string[];
        };
        response = await handleSendDirectMessage(client, { recipientId, text, mediaId, attachments });
        break;
Behavior2/5

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

No annotations are provided, so the description carries full burden. It states the tool sends a message but lacks critical behavioral details: whether this requires specific permissions, if it's rate-limited, what happens on failure, or if messages are reversible. For a mutation 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 with zero waste—it directly states the tool's purpose without redundancy. It's appropriately sized and front-loaded, making it easy for an agent 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?

For a mutation tool with no annotations and no output schema, the description is incomplete. It lacks behavioral context (e.g., side effects, error handling), usage guidelines, and details on return values. While the schema covers parameters well, the overall context for safe and effective tool invocation is insufficient.

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 all parameters well-documented in the schema itself. The description adds no additional parameter semantics beyond implying 'recipientId' and 'text' are required (matching the schema). Baseline 3 is appropriate as the schema does the heavy lifting, but the description doesn't compensate with extra context like format examples or constraints.

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 target ('to a specified user'), providing a specific verb+resource combination. However, it doesn't differentiate from sibling tools like 'createMediaMessage' or 'postTweet' that might also involve messaging, leaving room for ambiguity in tool selection.

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?

No guidance is provided on when to use this tool versus alternatives. The description doesn't mention prerequisites (e.g., authentication), exclusions, or compare it to similar tools like 'createMediaMessage' or 'postTweet', leaving the agent to infer usage context from the tool 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