Skip to main content
Glama
msaelices

WhatsApp MCP Server

by msaelices

open_session

Initiate a new WhatsApp session using the WhatsApp MCP Server to enable interaction with the WhatsApp Business API, facilitating message sending and group management.

Instructions

Open a new WhatsApp session.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • The primary MCP tool handler for 'open_session', decorated with @mcp.tool() for registration, handles the tool execution by delegating to auth_manager.
    @mcp.tool()
    async def open_session(ctx: Context) -> str:
        """Open a new WhatsApp session."""
        try:
            # Open a new session
            success, message_text = await auth.auth_manager.open_session()
            if success:
                return f"Success: {message_text}"
            else:
                return f"Error: {message_text}"
        except Exception as e:
            logger.error(f"Error opening session: {e}")
            return f"Error: {str(e)}"
  • The core implementation logic for opening a WhatsApp session in the AuthManager class, initializes WhatsAppClient and manages session state.
    async def open_session(self) -> Tuple[bool, str]:
        """Open a new session."""
        if self.session:
            return False, "Session already exists"
    
        client = WhatsAppClient()
        success = await client.initialize()
    
        if success:
            self.session = client
            return True, "Session created successfully"
    
        return False, "Failed to create session"
  • Pydantic input schema model defined for the open_session tool (empty as tool takes no parameters).
    class CreateSessionModel(BaseModel):
        """Input schema for open_session tool."""
    
        pass
  • The @mcp.tool() decorator registers the open_session function as an MCP tool.
    @mcp.tool()
Install Server

Other Tools

Related 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/msaelices/whatsapp-mcp-server'

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