Skip to main content
Glama
Benniu

emqx-mcp-server

by Benniu

list_mqtt_clients

Retrieve a list of all MQTT clients currently connected to your EMQX cluster for monitoring and management purposes.

Instructions

List MQTT clients connected to your EMQX Cluster

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
requestYes

Implementation Reference

  • Registration of the 'list_mqtt_clients' tool using the @mcp.tool decorator inside register_tools method
    @mcp.tool(name="list_mqtt_clients", 
              description="List MQTT clients connected to your EMQX Cluster")
    async def list_clients(request):
  • The tool handler function that parses MCP request parameters and calls the EMQX client to list MQTT clients
    """Handle list clients request
    
    Args:
        request: MCP request containing filter parameters
            - page: Page number (default: 1)
            - limit: Results per page, max 10000 (default: 10)
            - node: Node name
            - clientid: Client ID
            - username: Username
            - ip_address: Client IP address
            - conn_state: Connection state
            - clean_start: Clean start flag
            - proto_ver: Protocol version
            - like_clientid: Fuzzy search by client ID pattern
            - like_username: Fuzzy search by username pattern
            - like_ip_address: Fuzzy search by IP address pattern
    
    Returns:
        MCPResponse: Response object with list of clients
    """
    self.logger.info("Handling list clients request")
    
    # Extract optional parameters from the request with defaults
    params = {
        "page": request.get("page", 1),
        "limit": request.get("limit", 100)
    }
    
    # Optional parameters to include if present
    optional_params = [
        "node", "clientid", "username", "ip_address", "conn_state", 
        "clean_start", "proto_ver", "like_clientid", "like_username", 
        "like_ip_address"
    ]
    
    for param in optional_params:
        if param in request:
            params[param] = request.get(param)
    
    # Get list of clients from EMQX
    result = await self.emqx_client.list_clients(params)
    
    self.logger.info("Client list retrieved successfully")
    return result 
  • Helper method in EMQXClient class that performs the actual HTTP GET request to the EMQX /clients API endpoint to retrieve the list of MQTT clients
    async def list_clients(self, params=None):
        """
        Get a list of connected MQTT clients.
    
        Uses the EMQX HTTP API to retrieve information about connected clients.
        
        Args:
            params (dict, optional): Query parameters to filter results:
                - page: Page number (default: 1)
                - limit: Results per page, max 10000 (default: 10)
                - clientid: Client ID
                - username: Username
                - ip_address: Client IP address
                - conn_state: Connection state
                - clean_start: Clean start flag
                - proto_ver: Protocol version
                - like_clientid: Fuzzy search by client ID pattern
                - like_username: Fuzzy search by username pattern
                - like_ip_address: Fuzzy search by IP address pattern
    
        Returns:
            dict: Response from the EMQX API containing client data or error information
        """
        url = f"{self.api_url}/clients"
    
        # Default params if none provided
        if params is None:
            params = {"page": 1, "limit": 10}
    
        self.logger.info("Retrieving list of MQTT clients")
    
        async with httpx.AsyncClient() as client:
            try:
                response = await client.get(
                    url,
                    headers=self._get_auth_header(),
                    params=params,
                    timeout=30
                )
                response.raise_for_status()
                return self._handle_response(response)
            except Exception as e:
                self.logger.error(f"Error retrieving clients: {str(e)}")
                return {"error": str(e)}
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 of behavioral disclosure. It states the tool lists clients but doesn't describe how it behaves—e.g., whether it returns all clients or paginated results, if it requires authentication, what the output format is, or any rate limits. This leaves significant gaps for an agent to understand the tool's operation.

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, clear sentence that efficiently conveys the core purpose without unnecessary words. It's front-loaded with the main action and resource, making it easy to parse, though its brevity contributes to gaps in other dimensions.

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 the tool's complexity (a listing operation with one undocumented parameter), lack of annotations, and no output schema, the description is incomplete. It doesn't cover parameter usage, behavioral details, or output expectations, making it insufficient for an agent to effectively invoke the tool without additional context.

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

Parameters1/5

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

The input schema has one parameter ('request') with 0% description coverage, and the tool description provides no information about parameters. It doesn't explain what 'request' should contain (e.g., filtering criteria, pagination options) or its format, leaving the parameter entirely undocumented and unusable without external knowledge.

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 tool's purpose with a specific verb ('List') and resource ('MQTT clients connected to your EMQX Cluster'), making it immediately understandable. However, it doesn't explicitly differentiate from sibling tools like 'get_mqtt_client' (which likely retrieves a single client) or mention the scope of listing (e.g., all clients vs. filtered).

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 when to prefer 'list_mqtt_clients' over 'get_mqtt_client' (e.g., for bulk retrieval vs. single client details) or 'kick_mqtt_client' (for management actions). There's also no context on prerequisites or limitations.

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/Benniu/emqx-mcp-server'

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