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
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/whatsapp_mcp/server.py:43-56 (handler)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)}"
- src/whatsapp_mcp/modules/auth.py:58-70 (handler)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"
- src/whatsapp_mcp/models.py:9-12 (schema)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
- src/whatsapp_mcp/server.py:43-43 (registration)The @mcp.tool() decorator registers the open_session function as an MCP tool.@mcp.tool()