Skip to main content
Glama
crazyrabbitLTC

Twitter MCP Server

unblockUser

Remove a block on a Twitter user account using their user ID or username to restore their ability to view your profile and interact with your content.

Instructions

Unblock a previously blocked user account

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
userIdNoThe ID of the user to unblock
usernameNoThe username of the user to unblock (alternative to userId)

Implementation Reference

  • Core implementation of the unblockUser tool handler. Resolves user ID from username if needed, retrieves authenticated user ID, calls Twitter v2 unblock API, and returns success response or formatted error.
    /**
     * Unblock a previously blocked user account
     */
    export const handleUnblockUser: TwitterHandler<UnblockUserArgs> = async (
        client: TwitterClient | null,
        { userId, username }: UnblockUserArgs
    ): Promise<HandlerResponse> => {
        if (!client) {
            return createMissingTwitterApiKeyResponse('unblockUser');
        }
        
        try {
            if (!userId && !username) {
                throw new Error('Either userId or username must be provided');
            }
    
            let targetUserId = userId;
    
            // If username provided, get the user ID first
            if (username && !userId) {
                const userResponse = await client.v2.userByUsername(username);
                if (!userResponse.data) {
                    throw new Error(`User with username '${username}' not found`);
                }
                targetUserId = userResponse.data.id;
            }
    
            // Get authenticated user's ID
            const me = await client.v2.me();
            const myUserId = me.data.id;
    
            // Unblock the user
            const result = await client.v2.unblock(myUserId, targetUserId!);
    
            return createResponse(`Successfully unblocked user ${username || targetUserId}. Response: ${JSON.stringify(result, null, 2)}`);
        } catch (error) {
            if (error instanceof Error) {
                throw new Error(formatTwitterError(error, 'unblocking user'));
            }
            throw error;
        }
    };
  • TypeScript interface defining the input arguments for the unblockUser handler (userId or username).
    export interface UnblockUserArgs {
        userId?: string;
        username?: string;
    }
  • MCP tool schema definition for unblockUser, including description and inputSchema for validation.
    unblockUser: {
        description: 'Unblock a previously blocked user account',
        inputSchema: {
            type: 'object',
            properties: {
                userId: { 
                    type: 'string', 
                    description: 'The ID of the user to unblock' 
                },
                username: { 
                    type: 'string', 
                    description: 'The username of the user to unblock (alternative to userId)' 
                }
            },
            required: []
        }
    },
  • src/index.ts:392-395 (registration)
    Registration and dispatching of the unblockUser tool in the main MCP server request handler switch statement.
    case 'unblockUser': {
        const { userId, username } = request.params.arguments as { userId?: string; username?: string };
        response = await handleUnblockUser(client, { userId, username });
        break;
  • src/index.ts:60-66 (registration)
    Import of the handleUnblockUser function in the main index file.
        handleBlockUser,
        handleUnblockUser,
        handleGetBlockedUsers,
        handleMuteUser,
        handleUnmuteUser,
        handleGetMutedUsers
    } from './handlers/moderation.handlers.js';

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