Skip to main content
Glama

WaPulse WhatsApp MCP Server

by Quegenx
createInstance.ts•2.07 kB
import { z } from "zod"; import { makeApiRequest } from "../../utils/helpers.js"; import { McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js'; import type { CreateInstanceRequest, CreateInstanceResponse } from "../../types/api.js"; export const createInstanceSchema = z.object({ token: z.string().min(1, "Token is required"), }); export async function handleCreateInstance( args: z.infer<typeof createInstanceSchema>, context?: { log?: (level: string, message: string, meta?: any) => void } ): Promise<{ content: Array<{ type: string; text: string }> }> { const { token } = args; const { log } = context || {}; try { if (log) { log("info", "Creating new WhatsApp instance", { token: token.substring(0, 8) + "..." }); } const requestBody: CreateInstanceRequest = { token }; const response = await makeApiRequest('/api/addInstance', requestBody) as CreateInstanceResponse; if (log) { log("info", "Instance created successfully", { instanceID: response.instance?.instanceID, message: response.message }); } const instanceInfo = response.instance ? ` šŸ†” Instance ID: ${response.instance.instanceID} šŸ“Š Instance Details: ${JSON.stringify(response.instance, null, 2)}` : ''; return { content: [{ type: "text", text: `āœ… WhatsApp Instance Created Successfully! šŸ’¬ Message: ${response.message}${instanceInfo} šŸ”§ Next Steps: 1. Use 'get_qr_code' to get the QR code for WhatsApp Web connection 2. Scan the QR code with your WhatsApp mobile app 3. Use 'start_instance' to begin sending/receiving messages šŸ“‹ Full Response: ${JSON.stringify(response, null, 2)}` }] }; } catch (error) { if (log) { log("error", "Failed to create instance", { error: (error as Error).message, token: token.substring(0, 8) + "..." }); } if (error instanceof McpError) { throw error; } throw new McpError(ErrorCode.InternalError, `Failed to create WhatsApp instance: ${(error as Error).message}`); } }

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/Quegenx/wapulse-mcp'

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