Skip to main content
Glama
crazyrabbitLTC

Twitter MCP Server

getDirectMessageEvents

Retrieve specific direct message events with detailed information including text, sender data, attachments, and conversation metadata from Twitter.

Instructions

Get specific direct message events with detailed information

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
expansionsNoAdditional fields to expand in the response
userFieldsNoUser fields to include when expanding sender information

Implementation Reference

  • Core handler function that implements the getDirectMessageEvents tool by calling Twitter v2 API listDmEvents with appropriate parameters and formatting the response.
    /**
     * Get specific direct message events
     */
    export const handleGetDirectMessageEvents: TwitterHandler<GetDirectMessageEventsArgs> = async (
        client: TwitterClient | null,
        { maxResults = 100, paginationToken, dmEventFields, expansions, userFields }: GetDirectMessageEventsArgs
    ): Promise<HandlerResponse> => {
        if (!client) {
            return createMissingTwitterApiKeyResponse('getDirectMessageEvents');
        }
        try {
            const options: any = {
                max_results: Math.min(maxResults, 100)
            };
    
            if (paginationToken) {
                options.pagination_token = paginationToken;
            }
    
            if (dmEventFields && dmEventFields.length > 0) {
                options['dm_event.fields'] = dmEventFields.join(',');
            } else {
                options['dm_event.fields'] = 'id,text,created_at,sender_id,dm_conversation_id,referenced_tweet,attachments';
            }
    
            if (expansions && expansions.length > 0) {
                options.expansions = expansions.join(',');
            }
    
            if (userFields && userFields.length > 0) {
                options['user.fields'] = userFields.join(',');
            }
    
            const events = await client.v2.listDmEvents(options);
    
            if (!events.data || !Array.isArray(events.data) || events.data.length === 0) {
                return createResponse('No direct message events found.');
            }
    
            const responseData = {
                events: events.data,
                includes: events.includes,
                meta: events.meta
            };
    
            return createResponse(`Retrieved ${events.data.length} direct message events: ${JSON.stringify(responseData, null, 2)}`);
        } catch (error) {
            if (error instanceof Error) {
                throw new Error(formatTwitterError(error, 'getting direct message events'));
            }
            throw error;
        }
    };
  • TypeScript interface defining the input parameters for the getDirectMessageEvents handler.
    export interface GetDirectMessageEventsArgs {
        maxResults?: number;
        paginationToken?: string;
        dmEventFields?: string[];
        expansions?: string[];
        userFields?: string[];
    }
  • src/tools.ts:491-533 (registration)
    MCP tool object registration defining the description and input schema (JSON Schema) for getDirectMessageEvents.
    getDirectMessageEvents: {
        description: 'Get specific direct message events with detailed information',
        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' 
                },
                expansions: { 
                    type: 'array', 
                    items: { 
                        type: 'string',
                        enum: ['sender_id', 'referenced_tweet.id', 'attachments.media_keys']
                    },
                    description: 'Additional fields to expand in the response' 
                },
                userFields: { 
                    type: 'array', 
                    items: { 
                        type: 'string',
                        enum: ['username', 'name', 'profile_image_url', 'verified']
                    },
                    description: 'User fields to include when expanding sender information' 
                }
            },
            required: []
        }
    },
  • src/index.ts:347-356 (registration)
    Server request handler dispatch case that invokes the getDirectMessageEvents handler function with parsed arguments.
    case 'getDirectMessageEvents': {
        const { maxResults, paginationToken, dmEventFields, expansions, userFields } = request.params.arguments as {
            maxResults?: number;
            paginationToken?: string;
            dmEventFields?: string[];
            expansions?: string[];
            userFields?: string[];
        };
        response = await handleGetDirectMessageEvents(client, { maxResults, paginationToken, dmEventFields, expansions, userFields });
        break;
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 'Get' implies a read operation, the description doesn't disclose important behavioral traits: whether authentication is required, rate limits, pagination behavior beyond the paginationToken parameter, what 'detailed information' specifically includes, or how results are structured. For a tool with 5 parameters and no annotation coverage, this represents significant gaps 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.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence that states the core purpose without unnecessary words. It's appropriately sized for a basic tool description, though it could potentially be more front-loaded with critical information. There's no wasted verbiage or redundant phrasing.

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 the tool's complexity (5 parameters, no annotations, no output schema), the description is insufficiently complete. It doesn't explain what constitutes 'specific' events, how results are returned, what the response structure looks like, or how this differs from the sibling 'getDirectMessages' tool. For a data retrieval tool with multiple configuration options and no output schema, the description should provide more context about what the agent can expect.

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%, meaning all parameters are well-documented in the schema itself. The description adds no parameter-specific information beyond what's already in the schema - it doesn't explain relationships between parameters, provide usage examples, or clarify semantics. However, with complete schema coverage, the baseline score of 3 is appropriate as 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.

Purpose3/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description states the tool 'Get specific direct message events with detailed information', which provides a basic verb+resource combination ('get' + 'direct message events'). However, it's vague about what 'specific' means (no filtering criteria mentioned) and doesn't differentiate from the sibling tool 'getDirectMessages' which appears to serve a similar purpose. The description is adequate but lacks specificity and sibling differentiation.

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. There's no mention of when this tool should be used instead of 'getDirectMessages' (the obvious sibling tool), nor any context about prerequisites, appropriate scenarios, or exclusions. The agent receives no usage direction beyond the basic purpose statement.

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