unfollowUser
Remove a user from your following list on Twitter by specifying their username. Use this tool to manage your account's connections and streamline your feed.
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 implementation of the unfollowUser tool handler. Retrieves authenticated user ID, resolves target user by username, and executes Twitter v2 unfollow API call.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/tools.ts:263-272 (schema)MCP tool schema definition for unfollowUser, specifying input requirements (username) and description.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)Registration and dispatch logic in the main MCP server request handler for routing unfollowUser tool calls to the handler function.case 'unfollowUser': { const { username } = request.params.arguments as { username: string }; response = await handleUnfollowUser(client, { username }); break;
- src/types.ts:73-75 (schema)TypeScript interface defining the input arguments for unfollowUser tool.export interface UnfollowUserArgs { username: string; }
- src/types.ts:343-350 (schema)Runtime type assertion function validating unfollowUser input arguments.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'); } }