getUserInfo
Retrieve detailed information about a Twitter user by providing their username. Supports data extraction for user profiles on 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)Core handler function that fetches Twitter user information using the Twitter API v2 client.v2.userByUsername endpoint, handles errors and missing credentials.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)MCP tool schema definition with input validation requiring 'username' parameter.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)Registration and dispatch of the getUserInfo tool in the MCP server's CallToolRequestHandler switch statement.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 getUserInfo handler.export interface GetUserInfoArgs { username: string; }