Skip to main content
Glama

get_pubnub_messages

Retrieve historical messages from PubNub channels with start/end timetokens and count limits. Fetches message content and metadata in JSON format, supporting pagination for efficient data access.

Instructions

Fetches historical messages from one or more PubNub channels. Call this tool whenever you need to access past message history. Provide a list of channel names. Returns message content and metadata in JSON format. Supports pagination with start/end timetokens and count limit.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
channelsYesList of one or more PubNub channel names (strings) to retrieve historical messages from
countNoNumber of historical messages to return per channel (default: 100 for single channel, 25 for multiple channels)
endNoTimetoken delimiting the end of time slice (inclusive) to pull messages from
startNoTimetoken delimiting the start of time slice (exclusive) to pull messages from

Implementation Reference

  • The handler function that implements the core logic of the 'get_pubnub_messages' tool. It uses the PubNub SDK's fetchMessages method to retrieve historical messages from the specified channels, with optional support for timetoken-based pagination (start, end) and count limit.
    toolHandlers['get_pubnub_messages'] = async ({ channels, start, end, count }) => { try { const params = { channels }; // Add optional pagination parameters if (start !== undefined) params.start = start; if (end !== undefined) params.end = end; if (count !== undefined) params.count = count; const result = await pubnub.fetchMessages(params); return { content: [ { type: 'text', text: JSON.stringify(result, null, 2) }, ], }; } catch (err) { return { content: [ { type: 'text', text: `Error fetching messages: ${err}` } ], isError: true, }; } };
  • The schema definition for the 'get_pubnub_messages' tool, including name, description, and Zod-validated input parameters schema.
    toolDefinitions['get_pubnub_messages'] = { name: 'get_pubnub_messages', description: 'Fetches historical messages from one or more PubNub channels. Call this tool whenever you need to access past message history. Provide a list of channel names. Returns message content and metadata in JSON format. Supports pagination with start/end timetokens and count limit.', parameters: { channels: z.array(z.string()).min(1).describe('List of one or more PubNub channel names (strings) to retrieve historical messages from'), start: z.string().optional().describe('Timetoken delimiting the start of time slice (exclusive) to pull messages from'), end: z.string().optional().describe('Timetoken delimiting the end of time slice (inclusive) to pull messages from'), count: z.number().optional().describe('Number of historical messages to return per channel (default: 100 for single channel, 25 for multiple channels)'), } };
  • index.js:1397-1397 (registration)
    Call to registerAllTools which registers the 'get_pubnub_messages' tool (along with others) on the main MCP server instance. In chat-sdk mode, it is included as it is not in the excluded list.
    registerAllTools(server, isChatSdkMode);
  • index.js:1593-1594 (registration)
    Registration of tools (including 'get_pubnub_messages') on per-session MCP servers for HTTP transport mode.
    registerAllTools(sessionServer, isChatSdkMode);
  • PubNub client instance configuration used by the 'get_pubnub_messages' handler and other PubNub-related tools.
    const pubnub = new PubNub({ publishKey: process.env.PUBNUB_PUBLISH_KEY || 'demo', subscribeKey: process.env.PUBNUB_SUBSCRIBE_KEY || 'demo', userId: 'pubnub_mcp', });

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