Skip to main content
Glama
crazyrabbitLTC

Twitter MCP Server

getDirectMessages

Retrieve direct message conversations from Twitter with configurable fields and pagination for accessing private message history.

Instructions

Retrieve direct message conversations

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
maxResultsNoMaximum number of results to return (default: 100, max: 100)
paginationTokenNoPagination token for retrieving next page of results
dmEventFieldsNoFields to include in the DM event objects

Implementation Reference

  • The main handler function that implements the getDirectMessages tool. It checks for Twitter client, constructs API options for listing DM events, calls the Twitter v2 API, and formats the response.
    export const handleGetDirectMessages: TwitterHandler<GetDirectMessagesArgs> = async (
        client: TwitterClient | null,
        { maxResults = 100, paginationToken, dmEventFields }: GetDirectMessagesArgs
    ): Promise<HandlerResponse> => {
        if (!client) {
            return createMissingTwitterApiKeyResponse('getDirectMessages');
        }
        try {
            const options: any = {
                max_results: Math.min(maxResults, 100) // API limit is 100
            };
    
            if (paginationToken) {
                options.pagination_token = paginationToken;
            }
    
            if (dmEventFields && dmEventFields.length > 0) {
                options['dm_event.fields'] = dmEventFields.join(',');
            } else {
                // Default fields for better response
                options['dm_event.fields'] = 'id,text,created_at,sender_id,dm_conversation_id,referenced_tweet,attachments';
            }
    
            // Using v2 API for DM conversations
            const conversations = await client.v2.listDmEvents(options);
    
            if (!conversations.data || !Array.isArray(conversations.data) || conversations.data.length === 0) {
                return createResponse('No direct message conversations found.');
            }
    
            const responseData = {
                conversations: conversations.data,
                meta: conversations.meta
            };
    
            return createResponse(`Retrieved ${conversations.data.length} direct message events: ${JSON.stringify(responseData, null, 2)}`);
        } catch (error) {
            if (error instanceof Error) {
                throw new Error(formatTwitterError(error, 'getting direct messages'));
            }
            throw error;
        }
    };
  • MCP tool definition including name 'getDirectMessages', description, and inputSchema for validation.
    getDirectMessages: {
        description: 'Retrieve direct message conversations',
        inputSchema: {
            type: 'object',
            properties: {
                maxResults: { 
                    type: 'number', 
                    description: 'Maximum number of results to return (default: 100, max: 100)',
                    minimum: 1,
                    maximum: 100
                },
                paginationToken: { 
                    type: 'string', 
                    description: 'Pagination token for retrieving next page of results' 
                },
                dmEventFields: { 
                    type: 'array', 
                    items: { 
                        type: 'string',
                        enum: ['id', 'text', 'created_at', 'sender_id', 'dm_conversation_id', 'referenced_tweet', 'attachments']
                    },
                    description: 'Fields to include in the DM event objects' 
                }
            },
            required: []
        }
    },
  • TypeScript interface defining the input arguments for the getDirectMessages handler.
    export interface GetDirectMessagesArgs {
        maxResults?: number;
        paginationToken?: string;
        dmEventFields?: string[];
    }
  • src/index.ts:338-345 (registration)
    Registration and dispatching of the getDirectMessages tool in the main server request handler switch statement.
    case 'getDirectMessages': {
        const { maxResults, paginationToken, dmEventFields } = request.params.arguments as {
            maxResults?: number;
            paginationToken?: string;
            dmEventFields?: string[];
        };
        response = await handleGetDirectMessages(client, { maxResults, paginationToken, dmEventFields });
        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 'Retrieve' which implies a read-only operation, but doesn't disclose any behavioral traits like pagination behavior (implied by paginationToken parameter), rate limits, authentication requirements, or what 'conversations' means structurally. The description adds minimal value beyond the basic action.

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 states exactly what the tool does with zero wasted words. It's appropriately sized for a simple retrieval tool and front-loads the core purpose immediately. Every word earns its place.

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 3 parameters, the description is incomplete. It doesn't explain what 'conversations' means in the return value, how pagination works, or any behavioral constraints. For a tool that retrieves conversations with pagination and field selection capabilities, more context is needed 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?

Schema description coverage is 100%, so the schema already fully documents all three parameters with their types, constraints, and descriptions. The description adds no additional parameter semantics beyond what's in the schema. According to scoring rules, when schema coverage is high (>80%), the baseline is 3 even with no parameter info in the description.

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 verb ('Retrieve') and resource ('direct message conversations'), making the purpose immediately understandable. It distinguishes this from other messaging tools like 'sendDirectMessage' or 'getDirectMessageEvents' by focusing on conversations rather than individual events or sending. However, it doesn't explicitly differentiate from all siblings beyond the obvious messaging category.

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 'getDirectMessageEvents' or 'sendDirectMessage'. There's no mention of prerequisites, context, or exclusions. The agent must infer usage from the tool name alone, which is insufficient given multiple messaging-related tools in the sibling list.

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