Skip to main content
Glama

Query PubNub Insights

insights

Query PubNub Insights to retrieve aggregated analytics scoped to an account, app, or keyset. Get read-only metrics such as unique channels, users, messages, and top rankings.

Instructions

Queries PubNub Insights — read-only aggregated analytics scoped to an account, app, or keyset.

  **Entity scoping:** Every query requires an entityType ('account', 'app', or 'keyset') and
  an entityId. For 'account' and 'app', the entityId is the numeric ID. For 'keyset', the
  entityId is the subscribe key (sub-c-...).

  Two endpoints, picked automatically by metric name:
  - /v2/insights        → aggregated metrics (unique_channels, unique_users, messages, etc.)
  - /v2/insights/top    → ranked metrics (top_20_channels, top_20_users, top_10_message_types, etc.)

  TOOL SELECTION GUIDE — Insights Claude Behavior:

  1. Group-aware: Insights metrics are organized into 5 functional groups — Channels, Users,
     Messages, User Behavior, Devices. When a user asks an analytic question, pick the right
     group first and then the specific metric. See the how-to guides:
     how_to(slug="how-to-get-insights-api-access"), channels, users, messages,
     user-behavior-and-devices, filters.

  2. Period rules (enforced at runtime):
     - Duration metrics (avg_user_duration, unique_users_by_duration_timeframe,
       top_*_channels_with_user_duration) → period=hourly ONLY.
     - Top-N metrics (top_20_*, top_1000_*) → hourly or daily ONLY (no weekly/monthly).
     - Country metrics → hourly or daily ONLY.
     - new_vs_recurring_users → daily / weekly / monthly only (NOT hourly).
     - All other metrics → all four periods supported.

  3. Top metrics REQUIRE category. Without it, the call errors. Valid categories:
     by_messages, by_chats, by_subscribers, by_users_with_messages,
     by_users_with_chats, by_subscribed_channels, all.

  4. Top-metric filtering uses `filters` (JSON), not `filter`. Use `filters` on
     top_20_* / top_1000_* for thresholds (count_messages gt), allowlists (channel_name
     in), and prefixes (uuid startsWith). Use `filter` only on channel_patterns.

  5. UTC timestamps. fromDate and toDate are YYYY-MM-DD in UTC. Always frame the response
     with the date range and timezone so the user has unambiguous context.

  6. Top-N counts CANNOT be summed across periods. If the user asks for "top channels this
     week" and you query with period=daily, return one ranking per day, not a weekly sum.

  7. Default to period=daily for most queries. It supports the widest set of metrics and
     gives a clean trend view. Use hourly only when intra-day granularity is needed or for
     duration metrics.

  8. Account must be on Insights Premium. Free plan has no API access. Pro existing
     customers may need to upgrade from Standard to Premium. If a 403 comes back, surface
     this as the likely cause.

  9. The tool does not write or store anything. Insights is strictly read-only.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
entityTypeYesThe type of entity to fetch metrics for: 'account', 'app', or 'keyset'. Use 'keyset' with a subscribe key as entityId for keyset-scoped queries.
entityIdYesThe ID of the entity. For entityType='account': numeric account ID. For 'app': numeric app ID. For 'keyset': the subscribe key (sub-c-...).
metricYesInsights metric to query. Top metrics (top_20_*, top_1000_*) route to /v2/insights/top automatically and require the `category` parameter. Duration metrics (avg_user_duration, unique_users_by_duration_timeframe, top_*_channels_with_user_duration) only support period=hourly. new_vs_recurring_users does NOT support period=hourly. See Period Restrictions table in the how-to guide for the full matrix.
periodYesTime grain. Default to `daily` for most queries. Use `hourly` for intra-day or duration metrics. `weekly` and `monthly` are not supported by top-N metrics, country breakdowns, or some other categories.
fromDateYesStart date (inclusive) in YYYY-MM-DD format, UTC.
toDateYesEnd date (inclusive) in YYYY-MM-DD format, UTC.
categoryNoRequired ONLY for top metrics (top_20_*, top_1000_*). Picks the ranking dimension. by_subscribers, by_users_with_messages, by_users_with_chats apply to channel rankings only. by_subscribed_channels applies to user rankings only. Use `all` for combined results.
filterNoFilter expression for metric=channel_patterns only (`startsWith:group.` or `eq:lobby`). Do not use for top metrics — use `filters` instead.
filtersNoJSON object for top metrics on /v2/insights/top. Top-level key must match `metric` (e.g. top_1000_channels). Value is an array of {field, operator, value} conditions combined with AND. Operators: eq, neq, gt, lt, gte, lte, in, nin, startsWith. See how_to(slug="how-to-query-insights-filters").
orderByNoSort field and direction (e.g. `count_messages:desc`). Optional — most metrics default to a sensible ordering.
limitNoNumber of results to return. Optional — top metrics already cap at 20 or 1000 by name.
Behavior5/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description fully covers behavioral traits: read-only operation, period restrictions, UTC timestamps, inability to sum top-N counts across periods, account plan requirements, and filtering nuances. This exceeds disclosure expectations.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is well-structured with a clear opening, bullet points, and a numbered guide. It is slightly verbose for the amount of detail, but every sentence adds value. The front-loading of core purpose is effective.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness5/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given 11 parameters, no output schema, and no annotations, the description covers all critical aspects: entity scoping, endpoint selection, period constraints, parameter relationships, error handling (403), and operational caveats. It is fully sufficient for correct tool invocation.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters5/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Although schema coverage is 100%, the description adds substantial context: entity scoping rules, endpoint routing by metric type, period applicability matrix, category requirement for top metrics, filter vs filters distinction, and default behaviors. This significantly enriches the schema.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states 'Queries PubNub Insights — read-only aggregated analytics scoped to an account, app, or keyset.' This specifies the verb (query), resource (PubNub Insights), and distinguishes it from sibling tools like get_usage_metrics.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The 'TOOL SELECTION GUIDE' provides detailed when-to-use instructions for metrics, periods, and parameters. However, it does not explicitly compare this tool to alternative sibling tools for similar queries, leaving some ambiguity for AI agent selection.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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