Skip to main content
Glama
crazyrabbitLTC

Twitter MCP Server

blockUser

Block a Twitter user to prevent them from following you or viewing your tweets. Use this tool to restrict unwanted interactions by specifying either the user ID or username.

Instructions

Block a user account to prevent them from following you or viewing your tweets

Input Schema

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

Implementation Reference

  • The main handler function that implements the blockUser tool logic, using Twitter API v2 to block a user by ID or username.
    export const handleBlockUser: TwitterHandler<BlockUserArgs> = async ( client: TwitterClient | null, { userId, username }: BlockUserArgs ): Promise<HandlerResponse> => { if (!client) { return createMissingTwitterApiKeyResponse('blockUser'); } 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; // Block the user const result = await client.v2.block(myUserId, targetUserId!); return createResponse(`Successfully blocked user ${username || targetUserId}. Response: ${JSON.stringify(result, null, 2)}`); } catch (error) { if (error instanceof Error) { throw new Error(formatTwitterError(error, 'blocking user')); } throw error; } };
  • MCP tool schema definition for blockUser, including input schema with userId or username.
    blockUser: { description: 'Block a user account to prevent them from following you or viewing your tweets', inputSchema: { type: 'object', properties: { userId: { type: 'string', description: 'The ID of the user to block' }, username: { type: 'string', description: 'The username of the user to block (alternative to userId)' } }, required: [] } },
  • src/index.ts:387-390 (registration)
    Registration and dispatch logic in the main server request handler for the blockUser tool.
    case 'blockUser': { const { userId, username } = request.params.arguments as { userId?: string; username?: string }; response = await handleBlockUser(client, { userId, username }); break;
  • TypeScript interface defining the input arguments for the blockUser handler.
    export interface BlockUserArgs { userId?: string; 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