Skip to main content
Glama
crazyrabbitLTC

Twitter MCP Server

getAuthenticatedUser

Retrieve the authenticated user's profile information, including ID, username, name, description, and other specified fields, directly from the Twitter MCP Server without requiring username or ID input.

Instructions

Get the authenticated user's own profile information without needing to specify username or ID

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
userFieldsNoAdditional user fields to include (e.g., ["id", "username", "name", "description", "public_metrics", "verified", "profile_image_url", "created_at"])

Implementation Reference

  • The core handler function that implements the getAuthenticatedUser tool logic, fetching the authenticated user's profile via Twitter API v2.me() endpoint with error handling and field customization.
    export const handleGetAuthenticatedUser: TwitterHandler<GetAuthenticatedUserArgs> = async ( client: TwitterClient | null, { userFields }: GetAuthenticatedUserArgs ): Promise<HandlerResponse> => { if (!client) { return createMissingTwitterApiKeyResponse('getAuthenticatedUser'); } try { const me = await client.v2.me({ 'user.fields': (userFields as TTweetv2UserField[]) || ['id', 'username', 'name', 'description', 'public_metrics', 'verified', 'profile_image_url', 'created_at'] as TTweetv2UserField[] }); if (!me.data) { throw new Error('Unable to retrieve authenticated user information'); } return createResponse(`Authenticated user info: ${JSON.stringify(me.data, null, 2)}`); } catch (error) { if (error instanceof Error) { if (error.message.includes('401')) { throw new Error(`Authentication failed. Please check your API credentials and tokens. This endpoint requires valid OAuth 1.0a User Context or OAuth 2.0 Authorization Code with PKCE authentication.`); } if (error.message.includes('429')) { throw new Error(`Rate limit exceeded. Please wait before making another request.`); } throw new Error(formatTwitterError(error, 'getting authenticated user')); } throw error; } };
  • MCP tool registration schema defining the inputSchema, description, and parameters for getAuthenticatedUser.
    getAuthenticatedUser: { description: 'Get the authenticated user\'s own profile information without needing to specify username or ID', inputSchema: { type: 'object', properties: { userFields: { type: 'array', items: { type: 'string' }, description: 'Additional user fields to include (e.g., ["id", "username", "name", "description", "public_metrics", "verified", "profile_image_url", "created_at"])' } }, required: [] } },
  • TypeScript interface defining the input arguments (userFields) for the getAuthenticatedUser handler.
    export interface GetAuthenticatedUserArgs { userFields?: TTweetv2UserField[]; }
  • src/index.ts:217-220 (registration)
    Dispatch logic in the main MCP server request handler that routes 'getAuthenticatedUser' tool calls to the handler function.
    case 'getAuthenticatedUser': { const { userFields } = request.params.arguments as { userFields?: TTweetv2UserField[] }; response = await handleGetAuthenticatedUser(client, { userFields }); break;
  • src/index.ts:38-39 (registration)
    Import statement registering the handler function for use in the tool dispatch.
    handleGetAuthenticatedUser } from './handlers/user.handlers.js';

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