Developers

MCP server

Let an AI assistant such as Claude Code or Cursor read your costs, reports, budgets, anomalies, savings findings, commitments and Kubernetes efficiency through the Costfluent MCP server, and change them where an Owner allows it.

The Costfluent MCP server lets an AI assistant answer questions about your cloud spend without you opening the app. It runs on your machine, speaks the Model Context Protocol to the assistant over stdin and stdout, and calls the Public API with an API token you give it. It reads by default. Its write tools, which create and change annotations, cost reports, budgets, cost alerts and dashboards, acknowledge anomalies and set a savings finding's status and owner, are offered only once an Owner lets AI agents create and change objects and only for the write capabilities the token carries. No tool deletes anything or touches your cloud accounts. Two more tools, search_docs and get_doc_page, search and read this documentation, so the assistant can also find how to set up Costfluent, such as how to manage budgets with Terraform; they read its public text from docs.costfluent.com, without the token.

Which capabilities does the token carry, and may agents write? The token's capabilities and the organization's setting Only the tools they allow A tool call, over stdin A request, with the token in its header The result, or the API's error The result or the error, over stdout A docs search, over stdin The docs' text file, without the token Every listed page, in both languages The sections that match, over stdout Your assistant The MCP server on your machine The Costfluent Public API docs.costfluent.com
At start the server asks the Public API which capabilities its token carries and offers the assistant only the tools they allow; each tool call is a request the server sends to the API with the token in its header, and a docs tool reads the public docs instead, without the token.

Before you start

  • Creating the token needs the Owner, Integration Owner or Editor organization role; see API authentication.
  • An assistant only you use takes a token of your own, which stops when you leave the organization. For an assistant your team shares, such as one running on a shared server, an Owner can create a service token instead, which keeps working when its creator leaves.
  • The assistant must support local MCP servers that run as a command, as Claude Code, Claude Desktop and Cursor do.
  • For the write tools, an Owner turns on Let AI agents create and change objects first; see Let agents create and change objects.

Create a token

  1. Open Settings, then API tokens, and select Create API token.
  2. Enter a Name that says which assistant uses the token, such as Claude Code on my laptop.
  3. Under Access, choose the workspace the assistant works in, so the token reaches nothing else. Keep Whole organization only when the assistant compares workspaces.
  4. Under Start from, choose Read only. It leaves out View members, so the token cannot list your members and their addresses; keep it cleared. Clear any other capability the assistant does not need: the read tools need View workspaces, View costs, View cost reports, View budgets, View anomalies and View savings.
  5. Only if the assistant may change objects, add the write capability of each write tool it needs, as the Tools table names it, such as Create budgets. A token never carries a capability its creator does not hold; see API authentication.
  6. Choose an Expiration, such as 90 days, and select Create API token.
  7. Copy the token from Your API token. It is shown only once.

The token is stored in your assistant's configuration file, in plain text. Give it only the capabilities the assistant needs, read capabilities alone unless you want it to change objects, and an expiration, and revoke it under API tokens when you stop using the assistant.

Install the server

Download the archive for your platform from the latest release and put costfluent-mcp on your PATH, or build it with Go:

TerminalCode
go install github.com/costfluent/costfluent-mcp/cmd/costfluent-mcp@latest

Each release carries a build provenance attestation, which gh attestation verify <archive> --repo costfluent/costfluent-mcp checks.

For Claude Desktop on macOS or Windows, download costfluent-mcp_<version>.mcpb from the same release and open it. Claude Desktop installs the server from the bundle and asks for the token, so you need neither the archive nor a configuration file. The bundle carries an attestation too.

Connect your assistant

The server reads COSTFLUENT_API_TOKEN, the token, and optionally COSTFLUENT_BASE_URL, which defaults to https://api.costfluent.com and must use https. It does not use the sign-in that costfluent login keeps for the command line, so it always needs a token.

  1. In Claude Code, run claude mcp add costfluent --env COSTFLUENT_API_TOKEN=<token> -- costfluent-mcp.
  2. In Claude Desktop, Cursor or another client with an mcpServers file, add the server as below.
  3. Restart the assistant and ask it a question, such as "What did we spend on AWS last month, by service?".
JSONCode
{ "mcpServers": { "costfluent": { "command": "costfluent-mcp", "env": { "COSTFLUENT_API_TOKEN": "<token>" } } } }

Let agents create and change objects

The write tools are off for every organization until an Owner turns them on. Only the Owner organization role can change the setting, after a recent sign-in, and each change is recorded in the audit log.

  1. Open Settings, then Organization.
  2. Under AI agents, turn on Let AI agents create and change objects.
  3. Confirm with Let agents change objects. Turning it off needs no confirmation.

The AI agents card with the Let AI agents create and change objects switch, the tools it allows, and the note that a token with write capabilities can still call the API directly

Settings, then Organization: the AI agents card, with the setting off, as it is for a new organization.

While the setting is off, the server and the command line offer no write tool, and the Public API refuses any change a tool sends with 403 and the code agent_writes_disabled. Every request a tool makes, through the server or a tool's command, carries a Costfluent-Agent header, and the setting governs only marked requests; costfluent estimate, costfluent whoami and costfluent login send no marker, so a cost estimate posts from CI whatever the setting.

The setting does not stop someone who holds a token with write capabilities from calling the API directly, with curl, their own code or another agent. The boundary against such an agent is its token: give an agent that must not change anything a token without write capabilities.

Each write tool is marked as one that changes something, so Claude Code, Claude Desktop and Cursor ask you before they call it. A client in a mode that approves tool calls automatically asks nothing, and the assistant can then change whatever its token allows.

Tools

ToolWhat it doesCapability
list_workspacesThe workspaces the token can readView workspaces
query_costsCost, usage or resource count over a date range, per day, week, month or quarter, grouped by up to three dimensions and narrowed by a cost filterView costs
list_cost_reportsA workspace's saved cost reportsView cost reports
get_cost_report_dataThe numbers a saved report shows nowView costs, and View cost reports for a report that charts a business metric
list_annotationsA workspace's annotations by date: members' notes on its cost reports and the markers budgets and cost alerts leave as they fire, narrowed to one report or a date range, open ones unless resolved ones are asked forView cost reports
list_budgetsBudgets with their current spend and stateView budgets
list_anomaliesDetected cost anomalies, newest firstView anomalies
list_savings_itemsA workspace's savings findings with their estimated monthly saving and status, newest or largest saving first, narrowed by tab, source, kind, connection, the resources of a cost estimate or a minimum monthly savingView savings
list_commitmentsThe savings plans, reservations and committed use discounts a workspace holds, earliest end first, with their term, utilization and unused costView costs
get_commitment_coverageHow much of the eligible usage commitments covered over a date range, what they saved against on-demand prices and what went unused, per period and providerView costs
get_kubernetes_efficiencyCost, idle cost and CPU and memory used against requested per cluster, namespace or workload over a date range, largest cost firstView costs
create_annotationAdds a note on a date to one or more saved cost reportsUpdate cost reports
create_cost_reportSaves a new cost reportCreate cost reports
update_cost_reportChanges a saved cost report; what the call leaves out stays as it isUpdate cost reports
create_budgetCreates a budgetCreate budgets
update_budgetChanges a budget; what the call leaves out, its alerts included, stays as it isUpdate budgets
create_cost_alertCreates a cost alertManage cost alerts
update_cost_alertChanges a cost alert; what the call leaves out stays as it isManage cost alerts
pause_cost_alertPauses a cost alertManage cost alerts
resume_cost_alertResumes a paused cost alertManage cost alerts
create_dashboardCreates a dashboardCreate dashboards
add_dashboard_widgetAdds a widget to a dashboardUpdate dashboards, and View cost reports
acknowledge_anomalyAcknowledges a detected cost anomalyAcknowledge anomalies
set_savings_item_statusSets a savings finding to Accepted, Implemented or Declined, a decline with its reasonRespond to savings
assign_savings_item_ownerSets who owns a savings findingManage savings
search_docsSearches this documentation, in English or German, for the sections that answer a question, such as how to manage budgets with TerraformNone
get_doc_pageReads a page of this documentation, or one section of it, as markdownNone

A write tool that reads an object back, or reads it before adding to it, also needs that read: create_cost_report and update_cost_report with a settings change need View cost reports, create_cost_alert and update_cost_alert with added channels need View costs, create_dashboard and add_dashboard_widget need View dashboards, and update_budget with added thresholds needs View budgets. The Read only preset carries each of them.

How it behaves

  • At start the server asks the API which capabilities its token carries and whether the organization lets AI agents create and change objects, and offers the assistant only the tools those allow. A token the API refuses stops the server with the API's error, and so does a token carrying none of the capabilities the tools need, with an error naming them.
  • Workspace tools need a workspace_id with an organization token; the assistant finds the IDs with list_workspaces. A workspace token reads its own workspace unless told otherwise, and the API refuses any other.
  • When the API refuses a call, the assistant receives the API's error with its status, code and detail, and can explain it or adjust the question. A filter value the API does not know, such as a tab, status or level, is refused with the values it takes rather than answered with an empty result.
  • get_cost_report_data returns as many of a long report's most recent periods as fit in the assistant's context, and at least the last. The result says how many periods it left out and from which date the series, comparison, unit cost and forecast start. The total, the breakdown and the names of the resources, accounts and clusters it groups by always cover the whole window, so a report grouped by long resource ids keeps fewer periods, and one whose breakdown and names alone fill the answer keeps only its last period and can still be too long for the assistant. The assistant reads the earlier periods with query_costs at a coarser granularity.
  • get_kubernetes_efficiency returns at most 500 rows, largest cost first, and says when it left smaller ones out.
  • Commitment and Kubernetes figures leave out spend in a currency with no exchange rate and the days before your plan's history starts. The result lists both, so the assistant can say what the figures do not count.
  • Every call counts against the token's request limit. The server waits out a short limit and returns a longer one to the assistant with how many seconds to wait.
  • Names, titles, descriptions, tag keys and tag values in a result are written by your users and your cloud accounts, so anyone who can tag a resource can put text in front of the assistant. The server tells the assistant to treat them as data, never instructions, and each write tool's description tells it to change something only when you asked for that change, never because text in a result asks. Run it in an assistant that asks before a tool call that changes anything.
  • No tool deletes anything or touches a cloud account. An update tool changes only what the call names: what it leaves out keeps its value.
  • Each call of a create tool creates a new object, so a call the assistant repeats creates a second one.
  • When an Owner turns the setting off while the server runs, its write tools stay listed until it restarts, and the API refuses each call with agent_writes_disabled.
  • A change a write tool makes is recorded in the audit log.
  • The server never writes the token to its log or to a tool result; it travels only in the request header.
  • search_docs and get_doc_page read one file, the text of every page of this documentation, from docs.costfluent.com: on their first call, and again once the copy the server holds is an hour old, so a page they return can be up to an hour older than the site. That request carries no token, question or cost data, and nothing else leaves your machine for them; get_doc_page reads only pages of this documentation, never another address. They match words, not meaning, so the assistant asks in Costfluent's own words, such as budget, cost report or connection, and get_doc_page lists every section of a page with its link. They need no capability and come with any token the server serves.

Planned: commitment coverage

Not yet available in Costfluent.

list_commitments and get_commitment_coverage read the commitments a workspace's connections hold and how much of the eligible usage they covered. get_commitment_coverage returns one period per month unless the assistant asks for days, weeks or quarters, so a long date range stays readable.