get_pubnub_presence
Retrieve real-time presence data for PubNub channels or groups to monitor active users, occupancy counts, and subscriber UUIDs. Input channel or group names to receive JSON-formatted presence information.
Instructions
Retrieves real-time presence information for specified PubNub channels and channel groups. Call this tool when you need to monitor active users, occupancy counts, and subscriber UUIDs. Provide channel names and/or channel group names. Returns presence data in JSON format.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| channelGroups | No | List of channel group names (strings) to query presence data for | |
| channels | No | List of channel names (strings) to query presence data for |
Implementation Reference
- index.js:645-657 (handler)The core handler function for the 'get_pubnub_presence' tool. It calls PubNub's hereNow method to retrieve real-time presence information for specified channels and/or channel groups, returning the JSON result or an error.toolHandlers['get_pubnub_presence'] = async ({ channels, channelGroups }) => { try { const result = await pubnub.hereNow({ channels, channelGroups }); return { content: [ { type: 'text', text: JSON.stringify(result, null, 2) } ], }; } catch (err) { return { content: [ { type: 'text', text: `Error fetching presence information: ${err}` } ], isError: true, }; } };
- index.js:660-667 (schema)The schema definition for the 'get_pubnub_presence' tool, including name, description, and Zod-parameter validation for input channels and channelGroups.toolDefinitions['get_pubnub_presence'] = { name: 'get_pubnub_presence', description: 'Retrieves real-time presence information for specified PubNub channels and channel groups. Call this tool when you need to monitor active users, occupancy counts, and subscriber UUIDs. Provide channel names and/or channel group names. Returns presence data in JSON format.', parameters: { channels: z.array(z.string()).default([]).describe('List of channel names (strings) to query presence data for'), channelGroups: z.array(z.string()).default([]).describe('List of channel group names (strings) to query presence data for'), } };
- index.js:1397-1397 (registration)The call to registerAllTools which registers the 'get_pubnub_presence' tool (among others) to the main MCP server, using the handler and schema defined above. The registration logic conditionally includes/excludes tools based on --chat-sdk mode.registerAllTools(server, isChatSdkMode);
- index.js:1363-1394 (registration)The registerAllTools function that iterates over all toolDefinitions and registers each tool on the MCP server instance using serverInstance.tool(), including 'get_pubnub_presence' unless excluded in chat-sdk mode.function registerAllTools(serverInstance, chatSdkMode = false) { // Tools to exclude when in chat SDK mode const chatSdkExcludedTools = [ 'read_pubnub_sdk_docs', 'write_pubnub_app', 'read_pubnub_resources', 'manage_pubnub_account' ]; for (const toolName in toolDefinitions) { if (toolHandlers[toolName]) { // Skip excluded tools when in chat SDK mode if (chatSdkMode && chatSdkExcludedTools.includes(toolName)) { continue; } // Special handling for chat SDK docs tool if (toolName === 'read_pubnub_chat_sdk_docs' && (chatSdkLanguages.length === 0 || chatSdkTopics.length === 0)) { continue; // Skip this tool if chat SDK data isn't loaded } const toolDef = toolDefinitions[toolName]; serverInstance.tool( toolDef.name, toolDef.description, toolDef.parameters, wrapToolHandler(toolHandlers[toolName], toolName) ); } } }