Skip to main content
Glama
Jem-HR
by Jem-HR

get_templates

Retrieve available WhatsApp message templates to use for business communication, with options to filter by name or limit results.

Instructions

Get list of available WhatsApp templates.

Args: limit: Maximum number of templates to return (default: 100) name: Optional template name filter

Returns: Dictionary with templates list

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
limitNo
nameNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • The main handler implementation of get_templates tool that retrieves WhatsApp templates from the PyWA client, converts them to a simple dictionary format, and returns them with success status and count
    async def get_templates(
        limit: int = 100,
        *,
        name: Optional[str] = None,
    ) -> dict:
        """
        Get list of available WhatsApp templates.
        
        Args:
            limit: Maximum number of templates to return (default: 100)
            name: Optional template name filter
        
        Returns:
            Dictionary with templates list
        """
        try:
            # Note: PyWA's get_templates method signature may vary
            # This is a simplified implementation
            templates = wa_client.get_templates(
                limit=limit,
                name=name,
            )
            
            # Convert templates to simple format
            template_list = []
            for template in templates:
                template_data = {
                    "id": getattr(template, 'id', ''),
                    "name": getattr(template, 'name', ''),
                    "language": getattr(template, 'language', ''),
                    "status": getattr(template, 'status', ''),
                    "category": getattr(template, 'category', ''),
                }
                template_list.append(template_data)
            
            logger.info(f"Retrieved {len(template_list)} templates")
            return {
                "success": True,
                "templates": template_list,
                "count": len(template_list)
            }
        except Exception as e:
            logger.error(f"Failed to get templates: {str(e)}")
            return {"success": False, "error": str(e)}
  • The register_template_tools function that contains both send_template and get_templates tools, decorated with @mcp.tool() for MCP registration
    def register_template_tools(mcp, wa_client: WhatsApp):
        """Register template-related tools."""
        
        @mcp.tool()
        async def send_template(
            to: str,
            name: str,
            language: str = "en",
            params: Optional[List[Dict[str, Any]]] = None,
            *,
            reply_to_message_id: Optional[str] = None,
        ) -> dict:
            """
            Send a WhatsApp template message.
            
            Args:
                to: Phone number or WhatsApp ID
                name: Template name/ID
                language: Template language code (default: en)
                params: Optional template parameters (header, body, button components)
                reply_to_message_id: Message ID to reply to
            
            Returns:
                Dictionary with success status and message ID
            """
            try:
                result = wa_client.send_template(
                    to=to,
                    name=name,
                    language=language,
                    params=params or [],
                    reply_to_message_id=reply_to_message_id,
                )
                
                logger.info(f"Template '{name}' sent to {to}")
                message_id = getattr(result, 'id', str(result)) if result else None
                return {
                    "success": True,
                    "message_id": message_id,
                    "template": name,
                    "to": to,
                }
            except Exception as e:
                logger.error(f"Failed to send template: {str(e)}")
                return {"success": False, "error": str(e)}
        
        
        @mcp.tool()
        async def get_templates(
            limit: int = 100,
            *,
            name: Optional[str] = None,
        ) -> dict:
            """
            Get list of available WhatsApp templates.
            
            Args:
                limit: Maximum number of templates to return (default: 100)
                name: Optional template name filter
            
            Returns:
                Dictionary with templates list
            """
            try:
                # Note: PyWA's get_templates method signature may vary
                # This is a simplified implementation
                templates = wa_client.get_templates(
                    limit=limit,
                    name=name,
                )
                
                # Convert templates to simple format
                template_list = []
                for template in templates:
                    template_data = {
                        "id": getattr(template, 'id', ''),
                        "name": getattr(template, 'name', ''),
                        "language": getattr(template, 'language', ''),
                        "status": getattr(template, 'status', ''),
                        "category": getattr(template, 'category', ''),
                    }
                    template_list.append(template_data)
                
                logger.info(f"Retrieved {len(template_list)} templates")
                return {
                    "success": True,
                    "templates": template_list,
                    "count": len(template_list)
                }
            except Exception as e:
                logger.error(f"Failed to get templates: {str(e)}")
                return {"success": False, "error": str(e)}
  • The register_all_tools function that calls register_template_tools to register the get_templates tool with the MCP server
    def register_all_tools(mcp, wa_client):
        """Register all available tools with the MCP server."""
        register_messaging_tools(mcp, wa_client)
        register_interactive_tools(mcp, wa_client)
        register_template_tools(mcp, wa_client)
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 returns a list, but doesn't mention whether it's paginated, if there are rate limits, authentication requirements, or error conditions. For a read operation with zero annotation coverage, this leaves significant behavioral gaps.

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 efficiently structured with a clear purpose statement followed by separate 'Args' and 'Returns' sections. Every sentence adds value without redundancy, making it easy to parse and understand quickly.

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

Completeness4/5

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

Given the tool's low complexity (2 optional parameters) and the presence of an output schema (implied by 'Returns' statement), the description is reasonably complete. It covers the purpose and parameters adequately, though it could benefit from more behavioral context given the lack of annotations.

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

Parameters4/5

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

With 0% schema description coverage, the description compensates well by explaining both parameters: 'limit' as 'Maximum number of templates to return (default: 100)' and 'name' as 'Optional template name filter.' This adds meaningful context beyond the bare schema, though it doesn't specify format details for the name filter.

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: 'Get list of available WhatsApp templates.' It specifies the verb ('Get') and resource ('WhatsApp templates'), making it immediately understandable. However, it doesn't explicitly distinguish this tool from sibling tools like 'send_template' or 'upload_media', which prevents a perfect score.

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. With sibling tools like 'send_template' that likely use templates, there's no indication of whether this tool should be used for discovery before sending or for other purposes. The absence of any usage context leaves the agent without direction.

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/Jem-HR/pywa-mcp-server'

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