@@ -920,13 +920,15 @@ async def describe_db_instance_parameters(
920
920
@mcp .tool ()
921
921
async def describe_bills (
922
922
billing_cycles : list [str ],
923
- db_instance_id : str = None
923
+ db_instance_id : str = None ,
924
+ is_billing_item : bool = False
924
925
) -> dict [str , Any ]:
925
926
"""
926
927
Query the consumption summary of all product instances or billing items for a user within a specific billing period.
927
928
Args:
928
929
billing_cycles: bill cycle YYYY-MM, e.g. 2020-03
929
930
db_instance_id: DB instance id (e.g., "rm-xxx")
931
+ is_billing_item: Whether to pull data according to the billing item dimension.
930
932
Returns:
931
933
str: billing information.
932
934
"""
@@ -942,6 +944,7 @@ async def describe_bills(
942
944
describe_instance_bill_request = bss_open_api_20171214_models .DescribeInstanceBillRequest (
943
945
billing_cycle = billing_cycle ,
944
946
product_code = 'rds' ,
947
+ is_billing_item = is_billing_item ,
945
948
next_token = next_token
946
949
)
947
950
if db_instance_id :
@@ -953,7 +956,29 @@ async def describe_bills(
953
956
next_token = response .body .data .next_token
954
957
has_next_token = next_token is not None and next_token .strip () != ""
955
958
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 )
957
982
return res
958
983
except Exception as e :
959
984
raise e
0 commit comments