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;

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