Skip to main content
Glama

Aggregate Table Statistics

servicenow_aggregate
Read-onlyIdempotent

Calculate COUNT, SUM, AVG, MIN, or MAX on ServiceNow tables, optionally grouped by a field, using server-side aggregation.

Instructions

Calculate COUNT, SUM, AVG, MIN, or MAX on any ServiceNow table — optionally grouped by a field.

Uses the ServiceNow Aggregate API (/api/now/stats) for efficient server-side aggregation without fetching records.

Args:

  • table (string): Table to aggregate (e.g., incident, change_request, cmdb_ci)

  • query (string): Filter query (e.g., 'state!=7', 'priority=1^assignment_group=SYS_ID')

  • count (boolean): Include total record count (default: true)

  • sum_fields (string): Comma-separated numeric fields to sum (e.g., 'resolve_time,business_duration')

  • avg_fields (string): Comma-separated numeric fields to average

  • min_fields (string): Comma-separated fields to find minimum

  • max_fields (string): Comma-separated fields to find maximum

  • group_by (string): Field to group by (e.g., 'state', 'priority', 'assignment_group', 'category')

  • having (string): HAVING clause for grouped results (e.g., 'COUNT>5')

  • response_format: Output format

Examples:

  • Count open incidents by priority → table="incident", query="state!=7", group_by="priority"

  • Average resolve time for P1s → table="incident", query="priority=1^state=7", avg_fields="resolve_time"

  • Total open incidents by group → table="incident", query="state=1^ORstate=2", count=true, group_by="assignment_group"

  • Incidents per day this week → table="incident", query="opened_atRELATIVEGE@week@ago@1", group_by="opened_at"

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
countNoInclude record count
queryNoEncoded ServiceNow query string (e.g., 'state=1^priority=1^assigned_to=javascript:gs.getUserID()'). Leave empty to return all records.
tableYesServiceNow table name (e.g., incident, change_request, sys_user)
havingNoHAVING clause for grouped results (e.g., 'COUNT>5')
group_byNoField to group results by (e.g., 'state', 'priority')
avg_fieldsNoComma-separated numeric fields to average
max_fieldsNoComma-separated fields to find maximum
min_fieldsNoComma-separated fields to find minimum
sum_fieldsNoComma-separated numeric fields to sum
response_formatNoOutput format: 'markdown' (default) for human-readable or 'json' for structured datamarkdown
Behavior4/5

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

Annotations already declare readOnlyHint=true, idempotentHint=true, and destructiveHint=false. The description adds context about the underlying Aggregate API and emphasizes it does 'not fetch records,' explaining server-side efficiency. It doesn't describe output details or error cases, but the annotation coverage reduces the burden.

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: a one-sentence purpose, a brief API note, an arg list, and four illustrative examples. While the arg list duplicates schema property names, the examples earn their place and the overall length is appropriate for a tool with 10 parameters. No wasted sentences.

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

Completeness3/5

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

With 10 parameters and no output schema, the description is fairly complete but leaves the output structure implicit. It mentions response_format for markdown/json but doesn't describe what fields or rows the agent should expect in the response. It also doesn't clarify behavior when multiple aggregate fields are specified or no aggregate fields beyond count, though examples partially mitigate this.

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

Parameters4/5

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

The input schema already covers 100% of parameters with descriptions, so baseline is 3. The description adds value by providing concrete example values for query, group_by, and aggregate fields (e.g., 'state!=7', 'priority=1^assignment_group=SYS_ID'), which clarify acceptable syntax beyond the schema's generic descriptions.

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?

Description opens with 'Calculate COUNT, SUM, AVG, MIN, or MAX on any ServiceNow table — optionally grouped by a field.', clearly stating the specific verb (calculate), resource (ServiceNow tables), and operations. This distinguishes it from sibling tools, none of which offer aggregate statistics.

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 description explains that it uses the Aggregate API 'for efficient server-side aggregation without fetching records,' implying it should be used when aggregate statistics are needed rather than raw record retrieval. It provides four concrete examples showing appropriate scenarios (e.g., counting open incidents by priority). However, it does not explicitly name alternatives like query_records for cases where raw data is needed.

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

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