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;
    }
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries the full burden. It mentions the effect ('prevent them from following you or viewing your tweets') but lacks details on permissions required, whether the action is reversible, rate limits, or what the response looks like. This is a significant gap for a mutation tool.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence that front-loads the purpose ('Block a user account') and adds necessary context ('to prevent them from following you or viewing your tweets'). There is no wasted wording.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's complexity (a mutation with no annotations and no output schema), the description is minimal but functional. It explains what the tool does but lacks details on behavioral aspects like error handling or return values, which are important for an agent to use it correctly.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so the schema already documents both parameters ('userId' and 'username'). The description does not add any meaning beyond what the schema provides, such as clarifying if both parameters can be used together or which takes precedence.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the action ('block') and resource ('user account'), specifying the purpose to 'prevent them from following you or viewing your tweets'. This distinguishes it from sibling tools like 'muteUser' (which hides content) and 'unblockUser' (which reverses the action).

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines3/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description implies usage when you want to prevent a user from interacting with your account, but it does not explicitly state when to use this tool versus alternatives like 'muteUser' or 'unblockUser', nor does it mention prerequisites such as authentication or user identification.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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