Skip to main content
Glama
crazyrabbitLTC

Twitter MCP Server

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
NameRequiredDescriptionDefault
usernameYesThe username of the user to unfollow

Implementation Reference

  • 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;
        }
    };
  • TypeScript interface defining input arguments for unfollowUser: requires 'username' string.
    export interface UnfollowUserArgs {
        username: string;
    }
  • 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;
  • 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');
        }
    }

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