Skip to content

Commit 7e9474c

Browse files
author
wenfeng.wf
committed
filter bill data.
1 parent 3d349c4 commit 7e9474c

File tree

1 file changed

+27
-2
lines changed
  • src/alibabacloud_rds_openapi_mcp_server

1 file changed

+27
-2
lines changed

src/alibabacloud_rds_openapi_mcp_server/server.py

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -920,13 +920,15 @@ async def describe_db_instance_parameters(
920920
@mcp.tool()
921921
async def describe_bills(
922922
billing_cycles: list[str],
923-
db_instance_id: str = None
923+
db_instance_id: str = None,
924+
is_billing_item: bool = False
924925
) -> dict[str, Any]:
925926
"""
926927
Query the consumption summary of all product instances or billing items for a user within a specific billing period.
927928
Args:
928929
billing_cycles: bill cycle YYYY-MM, e.g. 2020-03
929930
db_instance_id: DB instance id (e.g., "rm-xxx")
931+
is_billing_item: Whether to pull data according to the billing item dimension.
930932
Returns:
931933
str: billing information.
932934
"""
@@ -942,6 +944,7 @@ async def describe_bills(
942944
describe_instance_bill_request = bss_open_api_20171214_models.DescribeInstanceBillRequest(
943945
billing_cycle=billing_cycle,
944946
product_code='rds',
947+
is_billing_item=is_billing_item,
945948
next_token=next_token
946949
)
947950
if db_instance_id:
@@ -953,7 +956,29 @@ async def describe_bills(
953956
next_token = response.body.data.next_token
954957
has_next_token = next_token is not None and next_token.strip() != ""
955958
items.extend(response.body.data.items)
956-
res[billing_cycle] = compress_json_array([item.to_map() for item in items])
959+
item_filters = []
960+
for item in items:
961+
if db_instance_id is None or db_instance_id in item.instance_id.split(";"):
962+
item_filters.append(
963+
{
964+
"Item": item.item,
965+
"AfterDiscountAmount": item.after_discount_amount,
966+
"InstanceID": item.instance_id,
967+
"BillingDate": item.billing_date,
968+
"InvoiceDiscount": item.invoice_discount,
969+
"SubscriptionType": item.subscription_type,
970+
"PretaxGrossAmount": item.pretax_gross_amount,
971+
"Currency": item.currency,
972+
"CommodityCode": item.commodity_code,
973+
"CostUnit": item.cost_unit,
974+
"NickName": item.nick_name,
975+
"PretaxAmount": item.pretax_amount,
976+
"BillingItem": item.billing_item,
977+
"BillingItemPriceUnit": item.list_price_unit,
978+
"BillingItemUsage": item.usage,
979+
}
980+
)
981+
res[billing_cycle] = compress_json_array(item_filters)
957982
return res
958983
except Exception as e:
959984
raise e

0 commit comments

Comments
 (0)