unfollowUser
Stop following a Twitter user by their username to manage your following list and control your feed content.
Instructions
Unfollow a user by their username
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| username | Yes | The username of the user to unfollow |
Implementation Reference
- src/handlers/user.handlers.ts:86-110 (handler)Core handler function that executes the unfollowUser tool: resolves current user ID, looks up target user by username, calls Twitter API v2.unfollow, returns success/error response.export const handleUnfollowUser: TwitterHandler<UserHandlerArgs> = async ( client: TwitterClient | null, { username }: UserHandlerArgs ): Promise<HandlerResponse> => { if (!client) { return createMissingTwitterApiKeyResponse('unfollowUser'); } try { const userId = await client.v2.me().then((response: any) => response.data.id); const targetUser = await client.v2.userByUsername(username); if (!targetUser.data) { throw new Error(`User not found: ${username}`); } await client.v2.unfollow(userId, targetUser.data.id); return createResponse(`Successfully unfollowed user: ${username}`); } catch (error) { if (error instanceof Error) { throw new Error(formatTwitterError(error, 'unfollowing user')); } throw error; } };
- src/types.ts:73-75 (schema)TypeScript interface defining input arguments for unfollowUser: requires 'username' string.export interface UnfollowUserArgs { username: string; }
- src/tools.ts:263-272 (schema)MCP tool input schema definition: JSON schema object specifying required 'username' parameter for the unfollowUser tool.unfollowUser: { description: 'Unfollow a user by their username', inputSchema: { type: 'object', properties: { username: { type: 'string', description: 'The username of the user to unfollow' } }, required: ['username'], }, },
- src/index.ts:265-268 (registration)Tool dispatch registration in main MCP server: switch case that extracts arguments and calls the handleUnfollowUser function.case 'unfollowUser': { const { username } = request.params.arguments as { username: string }; response = await handleUnfollowUser(client, { username }); break;
- src/types.ts:343-350 (helper)Runtime argument validator: Type guard function that asserts and validates input conforms to UnfollowUserArgs interface.export function assertUnfollowUserArgs(args: unknown): asserts args is UnfollowUserArgs { if (typeof args !== 'object' || args === null) { throw new Error('Invalid arguments: expected object'); } if (!('username' in args) || typeof (args as any).username !== 'string') { throw new Error('Invalid arguments: expected username string'); } }