# OpenCost (K8s Cost) MCP

> OpenCost (K8s Cost) connects your AI client directly to your Kubernetes billing data. Query cost allocations for specific workloads, check costs tied to physical assets like Nodes or Disks, and reconcile complex cloud provider bills (AWS CUR, Azure Export, GCP). It gives you natural language visibility into exactly where your cluster spending goes.

## Overview
- **Category:** cloud-infrastructure
- **Price:** Free
- **Tags:** kubernetes, cost-optimization, cloud-billing, infrastructure-monitoring, resource-allocation, finops

## Description

OpenCost lets you talk to your infrastructure budget. Instead of diving through confusing dashboards and merging multiple billing spreadsheets, you just ask your AI agent questions about your Kubernetes costs in plain English. You can find out which specific namespace or controller is chewing up the most resources, or see how much compute power on a physical Node cost this month. It pulls together data from core cloud provider bills—like AWS CUR or Azure exports—and cross-references it with internal workload allocations. This means you don't just get a total number; you get visibility into exactly why that number is what it is, helping your team maintain budget discipline while developing and running services. When you connect this MCP via the Vinkius catalog, your agent gains access to all these cost metrics in one place.

## Tools

### get_allocation
Queries the cost and resource usage allocated to specific Kubernetes workloads.

### get_assets
Retrieves detailed backing cost information for individual infrastructure assets.

### get_cloud_cost
Pulls raw cloud spending data directly from official provider billing reports (AWS, Azure, GCP).

### get_custom_cost_timeseries
Provides time-series samples of costs for third-party services like Datadog or MongoDB Atlas.

### get_custom_cost_total
Generates a total summary calculation for third-party service expenses over a defined period.

### set_log_level
Changes the internal logging verbosity of the OpenCost system at runtime.

## Prompt Examples

**Prompt:** 
```
Show me the cost allocation for all namespaces over the last 7 days.
```

**Response:** 
```
I've retrieved the allocation data for the last 7 days. The 'production' namespace accounts for 65% of the spend ($420.50), followed by 'staging' at 20% ($130.00). Would you like to see the breakdown by controller kind?
```

**Prompt:** 
```
What are the backing asset costs for our nodes today?
```

**Response:** 
```
Querying asset data... For today, your cluster nodes have incurred a cost of $45.20. This includes compute costs for 12 m5.large instances and associated EBS volumes. No load balancer costs were detected in this window.
```

**Prompt:** 
```
Get the total summary for third-party service costs for the current month.
```

**Response:** 
```
The total custom costs for this month sum up to $1,250.00. The largest contributors are Datadog ($800.00) and MongoDB Atlas ($450.00). Would you like to see the daily timeseries for these services?
```

## Capabilities

### Determine workload spending
Query costs based on Kubernetes workloads across clusters, nodes, and namespaces.

### Inspect physical resource costs
Retrieve cost data associated with underlying infrastructure assets like disks or load balancers.

### Reconcile cloud billing reports
Match internal Kubernetes spending against official bills from major cloud providers (AWS, Azure, GCP).

### Track third-party service expenses
Get time-series data and summaries for external tools like Datadog or MongoDB Atlas.

### Filter costs by metadata
Aggregate spending by labels, annotations, or defined service levels to pinpoint budget usage.

## Use Cases

### Why did our staging environment suddenly spike in cost?
The Engineering Manager asks the agent to run `get_allocation` for the last quarter. The agent responds, detailing that a new logging controller deployed to the 'staging' namespace accounted for 40% of the unexpected increase, allowing them to immediately scale it back.

### We need to compare our internal metrics against the official AWS bill.
The FinOps Analyst uses `get_cloud_cost` to retrieve the latest AWS CUR data. The agent then compares this raw provider data with the resource totals pulled via `get_allocation`, instantly flagging a 15% mismatch in EBS volume costs that needs review.

### How much did our development team spend on monitoring tools last month?
The DevOps Engineer prompts the agent to get a total summary using `get_custom_cost_total` for Datadog and MongoDB Atlas. The result provides a clear, single figure showing the full cost of observability across all projects.

### I need to know the compute cost for our primary nodes right now.
The user asks about backing assets today. The agent uses `get_assets` and reports that the 12 m5.large cluster nodes are incurring $45.20 in compute costs, including associated EBS volumes.

## Benefits

- Identify spending culprits: Instead of manually checking ten namespaces, you can ask the agent to check allocation for all clusters and pinpoint exactly which controllers or pods are driving up costs using `get_allocation`.
- Connect the dots: You don't have to merge separate AWS CUR files with your internal reports. The MCP lets you use `get_cloud_cost` to pull provider data and compare it directly against K8s usage metrics in one query.
- Track hardware costs: Need to know what underlying infrastructure is costing? Use `get_assets` to retrieve cost data for physical components like Nodes or Disks, giving a full picture of your spend.
- Monitor external tools: Beyond the cloud provider, you can track third-party services. Use `get_custom_cost_timeseries` and `get_custom_cost_total` to summarize costs from Datadog or MongoDB Atlas over time.
- Pinpoint leakage: The MCP allows aggregation by labels and annotations. This lets your agent filter out the noise and tell you precisely where a specific project's budget is going.

## How It Works

The bottom line is you get an immediate, accurate report on infrastructure costs without ever leaving your chat window or IDE.

1. Subscribe to this MCP and enter your OpenCost API Base URL.
2. Your AI client connects the cost data source to your agent's context.
3. You ask a natural language question, and the system returns precise spending figures linked to specific resources.

## Frequently Asked Questions

**How does OpenCost (K8s Cost) MCP handle multiple cloud providers?**
The MCP uses the `get_cloud_cost` tool to connect directly to various provider billing reports, including AWS CUR, Azure Export, and GCP Billing data. This means you can reconcile costs across different clouds from one place.

**Can OpenCost (K8s Cost) MCP tell me which service is the most expensive?**
Yes. You can use `get_allocation` to query costs and resources allocated to specific namespaces, pods, or controllers to pinpoint your biggest spending areas.

**What if I need cost data for services like Datadog?**
The MCP supports this via third-party tools. You use `get_custom_cost_timeseries` and `get_custom_cost_total` to track external service expenses over time or get a summary total.

**Is OpenCost (K8s Cost) MCP only for AWS?**
No. It is designed to be cloud-agnostic, pulling data from multiple sources including Azure and GCP in addition to AWS billing reports.

**How do I check the cost of a physical node using OpenCost (K8s Cost) MCP?**
Use the `get_assets` tool. This retrieves backing cost data broken down by individual assets, giving you visibility into nodes, disks, and load balancers.