#4553·mcp

cost-explorer-groupby-broken group by and filter parameters

Author: djcorsCreated Aug 28, 2026Updated Sep 28, 2026
Labelsbugneeds-triage

Describe the bug


name: cost-explorer-groupby-broken-2026-08 description: mcp__billing__cost-explorer group_by/filter params broken as of 2026-08-26 — forwards raw JSON string to boto instead of parsed object

mcp__billing__cost-explorer (operation=getCostAndUsage) fails for any group_by or filter parameter, regardless of how the JSON is shaped/escaped (array of dicts, single dict, array of strings, single/double quotes, HTML entities all tried). The tool validates the JSON is well-formed (raises "Invalid JSON format" if not), but then forwards the raw string to boto instead of using the parsed object, producing ParamValidationError: Invalid type for parameter GroupBy/Filter ... type: <class 'str'>, valid types: <class 'list'>/<class 'dict'>.

Workaround: use metric (singular string) instead of metrics (plural, also broken the same way) to get TOTAL cost per day with no grouping. No workaround found for per-SERVICE/LINKED_ACCOUNT/TAG breakdown via this operation while the bug is present.

Why: confirmed during the 2026-08-26 daily run after 10+ format variants failed identically. Retroactively identified the same signature in the 2026-08-21 to 2026-08-23 weekend snapshots (finops-data/cost-history/2026-08-2{1,2,3}.json), which only contain total cost + a single "sampled" service instead of full top-10 breakdown — so this is a recurring, not one-off, MCP regression.

How to apply: [[billing_mcp_scope_bug]] is a different, unrelated issue (missing billing_view_arn). If a future run hits this again, don't waste time re-testing JSON escaping — go straight to: (1) get TOTAL-only via metric singular, (2) rely on mcp__billing__cost-anomaly (GetAnomalies) for service/account-level detail since it doesn't use group_by/filter and is unaffected, (3) declare the limitation in the report per CLAUDE.md instead of blocking the whole run. Re-check periodically whether group_by has started working again before assuming it's still broken.

Update 2026-08-27: still broken, confirmed again (7th consecutive day, 08-21 through 08-27). Same error signature exactly. This is a persistent MCP-server-side regression, not transient — worth escalating to whoever maintains the billing MCP server rather than continuing to just retry each day.

Update 2026-08-28: still broken, confirmed again (8th consecutive day, 08-21 through 08-28). Same Invalid type for parameter GroupBy... type: <class 'str'> signature. Escalation still hasn't happened — flagged again in today's report recommendations.

Root cause pinned down 2026-08-28 (user walked through it with me): the MCP tool's own input schema declares group_by as type string — sending the AWS-correct shape ([{"Type": "DIMENSION", "Key": "SERVICE"}], a list of dicts, confirmed against official boto3 GroupBy param docs) gets rejected by the MCP's Pydantic validation layer before it ever reaches AWS (Input should be a valid string ... input_type=list). Sending it the way the schema demands (a JSON-encoded string) passes that validation but then gets forwarded to boto3.get_cost_and_usage() verbatim, without a json.loads() step — so boto3 rejects it right back (Invalid type for parameter GroupBy ... type: <class 'str'>, valid types: <class 'list'>, <class 'tuple'>). Also tried a bare dict (not list-wrapped) both as object and as string — same two-sided failure. There is no caller-side format that satisfies both layers; this is a server-side deserialization gap in the billing MCP wrapper, not a client formatting mistake. Stop testing new group_by shapes going forward — go straight to the metric (singular)/TOTAL-only workaround and flag for escalation.

Expected Behavior

The getCostAndUsage operation should accept a group_by parameter (and filter, which is affected identically) in the form documented by the underlying AWS Cost Explorer GetCostAndUsage API: a list of {"Type": "DIMENSION"|"TAG"|"COST_CATEGORY", "Key": ""} objects (e.g. [{"Type": "DIMENSION", "Key": "SERVICE"}]), and successfully return grouped cost/usage data broken down by that dimension/tag — matching the AWS CLI's --group-by Type=DIMENSION,Key=SERVICE behavior.

Concretely, the tool should either:

Accept group_by as a native JSON array/object in the MCP tool call (not force it through a string-typed parameter), and pass it directly to boto3.get_cost_and_usage(GroupBy=...), or If the parameter schema requires group_by to be a JSON-encoded string (as the current schema enforces), the server should json.loads() that string internally before forwarding it to boto3 as GroupBy=[...] — i.e., deserialize it back into a list/dict rather than passing the raw string through.

Currently neither path works: sending a native list/dict is rejected by the tool's own Pydantic input validation (which demands group_by be typed string), and sending a JSON-encoded string (satisfying that validation) is forwarded unparsed to boto3, which then rejects it because GroupBy must be list/tuple, not str. There is no input format that succeeds — the deserialization step between the input schema and the boto3 call is simply missing.

Current Behavior

Any getCostAndUsage call that includes group_by or filter fails, regardless of how the value is formatted — there is no input shape that succeeds:

If group_by/filter is sent as a native JSON array/object (the shape AWS's own GetCostAndUsage API expects), the tool's own input schema rejects it before the request ever reaches AWS, because the schema types group_by/filter as string:

1 validation error for call[cost_explorer]
  group_by
    Input should be a valid string [type=string_type, input_value=[{'Type': 'DIMENSION', 'Key': 'SERVICE'}], input_type=list]

If group_by/filter is instead sent as a JSON-encoded string (satisfying that schema), it passes input validation but is then forwarded to boto3.get_cost_and_usage() verbatim — with no json.loads() step to convert it back into a list/dict first. boto3 then rejects it: ParamValidationError: Invalid type for parameter GroupBy, value: [{"Type": "DIMENSION", "Key": "SERVICE"}], type: <class 'str'>, valid types: <class 'list'>, <class 'tuple'>

The metrics parameter (plural) fails identically; only the singular metric works, and only when group_by/filter are omitted entirely — in which case the call succeeds but returns only the ungrouped TOTAL, with no breakdown by service, linked account, or tag.

Net effect: it's currently impossible to get any dimensional/tag breakdown out of getCostAndUsage via this tool. This has been reproduced daily for 8 consecutive days (2026-08-21 through 2026-08-28) across independent sessions, so it is a persistent regression, not a transient/flaky failure.

Reproduction Steps

Call the cost-explorer MCP tool with operation getCostAndUsage and group_by passed as a native JSON array (the shape documented for the underlying AWS API): json { "operation": "getCostAndUsage", "start_date": "2026-08-27", "end_date": "2026-08-28", "granularity": "DAILY", "metric": "UnblendedCost", "group_by": [{"Type": "DIMENSION", "Key": "SERVICE"}] }

→ Fails input validation before reaching AWS:

1 validation error for call[cost_explorer] group_by Input should be a valid string [type=string_type, input_value=[{'Type': 'DIMENSION', 'Key': 'SERVICE'}], input_type=list] Re-send group_by as a JSON-encoded string instead, per what the schema error in step 1 demands: json { "operation": "getCostAndUsage", "start_date": "2026-08-27", "end_date": "2026-08-28", "granularity": "DAILY", "metric": "UnblendedCost", "group_by": "[{"Type": "DIMENSION", "Key": "SERVICE"}]" }

→ Passes input validation this time, but fails when forwarded to boto3:

ParamValidationError: Invalid type for parameter GroupBy, value: [{"Type": "DIMENSION", "Key": "SERVICE"}], type: <class 'str'>, valid types: <class 'list'>, <class 'tuple'> Variants tried, all fail the same way (step 1's error if sent as object/array, step 2's error if sent as string): Bare dict instead of list: {"Type": "DIMENSION", "Key": "SERVICE"} Multiple group-by entries: [{"Type": "DIMENSION", "Key": "SERVICE"}, {"Type": "TAG", "Key": "Environment"}] AWS CLI shorthand syntax: Type=DIMENSION,Key=SERVICE → rejected outright as invalid JSON filter parameter — same failure signature as group_by metrics (plural) — same failure signature; only the singular metric parameter works Only working call omits group_by/filter entirely and uses singular metric: json { "operation": "getCostAndUsage", "start_date": "2026-08-27", "end_date": "2026-08-28", "granularity": "DAILY", "metric": "UnblendedCost" }

→ Succeeds, but returns only the unaggregated TOTAL, with no breakdown by service/account/tag.

Environment: observed daily, 8 consecutive days as of 2026-08-28 (since 2026-08-21), across separate sessions/calls — not transient.

Possible Solution

No response

Additional Information/Context

No response

OS

Windows

Server

billing-cost-management-mcp-server

Server Version

awslabs.billing-cost-management-mcp-server@latest

Region experiencing the issue

us-east-1

Other information

No response

Service quota

  • I have reviewed the service quotas for this construct