Skip to main content
Glama
hbd

MCP Chat

by hbd

leave_chat

Exit a chat room in the MCP Chat server by providing room and client identifiers to disconnect from group conversations.

Instructions

Leave the current chat room.

Args: room_id: The ID of the chat room to leave client_id: Your client identifier (from enter_queue)

Returns: Success status

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
room_idYes
client_idYes

Implementation Reference

  • Implementation of the 'leave_chat' tool handler. This async function handles the logic for a user leaving a chat room: validates user and room, closes the room using RoomManager, logs the action, and notifies the partner via message queue and notification if applicable. Registered via @mcp.tool() decorator.
    @mcp.tool()
    async def leave_chat(room_id: str, client_id: str) -> Dict[str, Any]:
        """Leave the current chat room.
    
        Args:
            room_id: The ID of the chat room to leave
            client_id: Your client identifier (from enter_queue)
    
        Returns:
            Success status
        """
        # Use the provided client_id
        connection_id = client_id
    
        # Get user
        user = connections.get(connection_id)
        if not user:
            return {"success": False, "error": "User not found"}
    
        # Get room
        room = await room_manager.get_room(room_id)
        if not room:
            return {"success": False, "error": "Room not found"}
    
        # Verify user is in the room
        if not room.has_user(user.user_id):
            return {"success": False, "error": "You are not in this room"}
    
        # Get partner before closing room
        partner = room.get_partner(user.user_id)
    
        # Close the room
        await room_manager.close_room(room_id)
    
        # Log
        logger.info(f"User {user.name} left room {room_id}")
    
        # Notify partner if they exist
        if partner:
            # Send disconnection message to waiting queue
            if room_id in message_queues and partner.user_id in message_queues[room_id]:
                disconnect_msg = {
                    "content": "[System] Your chat partner has left the conversation.",
                    "sender_name": "System",
                    "sender_id": "system",
                    "timestamp": datetime.now().isoformat(),
                    "message_id": str(uuid.uuid4()),
                    "system": True,
                    "disconnect": True,
                }
                try:
                    message_queues[room_id][partner.user_id].put_nowait(disconnect_msg)
                except (asyncio.QueueFull, RuntimeError) as e:
                    # Queue might be full or closed
                    logger.debug(f"Could not send disconnect notification: {e}")
    
            # Also send regular notification
            await send_notification(
                partner.connection_id,
                "partner.disconnected",
                {"room_id": room_id, "reason": "left"},
            )
    
        return {"success": True, "message": "Successfully left the chat"}
Behavior2/5

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

With no annotations provided, the description carries full burden but offers minimal behavioral insight. It states the action but doesn't disclose what 'leaving' means (e.g., removes client from room, stops receiving messages, may be irreversible). No information on permissions, rate limits, or error conditions is included.

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

Conciseness4/5

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

The description is appropriately sized with a clear main sentence followed by structured parameter and return explanations. It's front-loaded with the core purpose, though the 'Args' and 'Returns' sections could be integrated more smoothly into natural language.

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

Completeness2/5

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

Given no annotations, no output schema, and a mutation tool (leaving implies state change), the description is incomplete. It lacks details on return values beyond 'Success status', error handling, side effects, and how this interacts with sibling tools in the chat system context.

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 0%, so the description must compensate. It explains 'room_id' as 'The ID of the chat room to leave' and 'client_id' as 'Your client identifier (from enter_queue)', adding meaningful context beyond the schema's bare titles. However, it doesn't detail format requirements or constraints for these IDs.

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

Purpose4/5

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

The description clearly states the action ('Leave') and resource ('current chat room'), making the purpose immediately understandable. It distinguishes from siblings like 'join_room' by specifying the opposite action. However, it doesn't explicitly mention what 'leaving' entails operationally.

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

Usage Guidelines2/5

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

The description provides no guidance on when to use this tool versus alternatives. It doesn't mention prerequisites (e.g., must be in the room first), consequences of leaving, or when to choose this over other tools like 'send_message' or 'wait_for_message'.

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/hbd/mcp-chat'

If you have feedback or need assistance with the MCP directory API, please join our Discord server