Skip to main content
Glama

publish_pubnub_message

Send data to a specified PubNub channel by providing the channel name and message payload. Returns a timetoken confirming successful message publication.

Instructions

Publishes a message to a specified PubNub channel. Call this tool whenever you need to send data through PubNub. Provide the channel name and message payload. Returns a timetoken confirming successful publication.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
channelYesName of the PubNub channel (string) to publish the message to
messageYesMessage payload as a string

Implementation Reference

  • The handler function that executes the 'publish_pubnub_message' tool logic. It uses the PubNub SDK to publish a message to the specified channel and returns the timetoken on success or an error message.
    toolHandlers['publish_pubnub_message'] = async ({ channel, message }) => { try { const result = await pubnub.publish({ channel, message, }); return { content: [ { type: 'text', text: `Message published successfully. Timetoken: ${result.timetoken}`, }, ], }; } catch (err) { return { content: [ { type: 'text', text: `Error publishing message: ${err}`, }, ], isError: true, }; } };
  • The tool definition including name, description, and Zod schema for input parameters (channel and message).
    toolDefinitions['publish_pubnub_message'] = { name: 'publish_pubnub_message', description: 'Publishes a message to a specified PubNub channel. Call this tool whenever you need to send data through PubNub. Provide the channel name and message payload. Returns a timetoken confirming successful publication.', parameters: { channel: z.string().describe('Name of the PubNub channel (string) to publish the message to'), message: z.string().describe('Message payload as a string'), } };
  • index.js:1363-1394 (registration)
    The registerAllTools function that registers the 'publish_pubnub_message' tool (along with others) by calling server.tool() with the definition and wrapped handler. Called for main server and HTTP sessions.
    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) ); } } }

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/pubnub/pubnub-mcp-server'

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