getUserInfo
Retrieve Twitter user details by providing a username to access profile information through the Twitter MCP Server.
Instructions
Get information about a Twitter user
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| username | Yes | The username of the user |
Implementation Reference
- src/handlers/user.handlers.ts:31-58 (handler)The core handler function that implements the getUserInfo tool. It fetches user information from Twitter API v2 using the provided username, handles errors, and returns formatted user data.
export const handleGetUserInfo: TwitterHandler<GetUserInfoArgs> = async ( client: TwitterClient | null, { username, fields }: GetUserInfoArgs ): Promise<HandlerResponse> => { if (!client) { return createMissingTwitterApiKeyResponse('getUserInfo'); } try { const user = await client.v2.userByUsername( username, { 'user.fields': fields || ['description', 'public_metrics', 'profile_image_url', 'verified'] as TTweetv2UserField[] } ); if (!user.data) { throw new Error(`User not found: ${username}`); } return createResponse(`User info: ${JSON.stringify(user.data, null, 2)}`); } catch (error) { if (error instanceof Error) { throw new Error(formatTwitterError(error, 'getting user info')); } throw error; } }; - src/tools.ts:162-171 (schema)The MCP tool schema definition for getUserInfo, including description and input schema requiring a 'username' string.
getUserInfo: { description: 'Get information about a Twitter user', inputSchema: { type: 'object', properties: { username: { type: 'string', description: 'The username of the user' }, }, required: ['username'], }, }, - src/index.ts:212-215 (registration)The registration and dispatch logic in the main MCP server request handler switch statement that routes 'getUserInfo' calls to the handler function.
case 'getUserInfo': { const { username } = request.params.arguments as { username: string }; response = await handleGetUserInfo(client, { username }); break; - src/types/handlers.ts:28-30 (schema)TypeScript interface defining the arguments for the getUserInfo handler, specifying the required 'username' parameter.
export interface GetUserInfoArgs { username: string; } - src/handlers/user.handlers.ts:12-14 (helper)Local interface in the handler file extending base args with optional Twitter user fields.
interface GetUserInfoArgs extends UserHandlerArgs { fields?: TTweetv2UserField[]; }