How LiteLLM tracks MCP tool costs per team and key
MCP tool calls routed through a shared LiteLLM gateway create spend that model invoices never show. A model provider bills for tokens, but a call to a search, ticketing or data server through the gateway may cost nothing at the provider level even though the organization pays for the upstream service, the infrastructure behind it or the internal team that runs it. If you need chargeback, team budgets or FinOps reporting that covers agent activity, you have to attach a cost to each tool call inside the gateway. LiteLLM supports two ways to do this. The first is configuration: a default_cost_per_query value per MCP server and a tool_name_to_cost_per_query mapping for individual tools. The second is a custom post-MCP hook, which lets you calculate a cost dynamically for each call. Choose the static approach when every call to a tool carries the same charge. Choose the hook when the charge depends on the arguments, the result or the caller.
Before you rely on either method, confirm the exact configuration keys, hook signature and the place where MCP cost lands in spend records against the version you will run, since this area of the product changes between releases. Check the LiteLLM MCP cost tracking documentation for the current syntax. Then test with one server and one tool. Make a call with a known virtual key, then confirm the cost is recorded against that key and team, and that the total appears alongside model spend in the same reporting view you plan to use for budgets. Also confirm how tool costs interact with per-key budgets, because a tool call that exhausts a budget should be blocked in the same way as a model call that does.
Plan who sets the rates. A static rate in the gateway configuration is a platform decision that the platform team must maintain, so it needs an owner, a change process and a record of when each value changed. A hook puts pricing logic in code that your engineers must test, version and review like any other production change. Agree with finance which number is authoritative, whether it is the rate on your internal price list, the upstream service's invoice or an allocation formula, and document it before teams begin to receive chargeback reports. Otherwise the same tool call can show different costs in the gateway, in the invoice and in the team's own accounting.
Choosing between default, per-tool and dynamic MCP costs
LiteLLM gives you three ways to price an MCP tool call: a default per server, a fixed price per tool, or a custom hook that calculates the charge at call time. Each suits a different pricing rule, and most gateways end up using two of them together, so the combination rules matter as much as the models themselves.
Default cost per query per server
Set default_cost_per_query on an MCP server in the gateway config to charge one flat amount for every call to that server. It suits servers where all tools cost about the same to run, such as a single internal lookup service. It cannot tell a cheap read from an expensive write, so a server with mixed tools will be overcharged for the cheap ones and undercharged for the rest. Check which tools the server exposes before you rely on one number.
Per-tool cost per query
Use tool_name_to_cost_per_query to set a price for individual tools by name. It suits servers where a few tools dominate the cost, for example a search tool priced above a metadata lookup. It cannot vary the price by input, caller or result size. Tool names must match what the server actually registers, so confirm them after every server upgrade, because a renamed tool silently falls back to other pricing.
Custom post-MCP hook for dynamic pricing
A custom post-MCP hook calculates the charge after each call, so it can use the tool name, the team or key, the arguments or the response. It suits chargeback rules that depend on usage, such as billing by records returned. It also adds code your team must own, test and keep working across LiteLLM upgrades. Ask who will maintain the hook and how its output will be reconciled with the spend records.
How server and tool costs combine
When a server has a default and a specific tool also has a price, decide which one wins before you publish the config. Test the combination with one call to a priced tool and one call to an unpriced tool, then compare the spend records against your expected values. Document the rule in your chargeback notes so finance and platform teams read the same numbers.
Where tool spend shows up next to model spend
Tool charges and model token charges should land in the same spend views so a team sees its full AI cost in one place. Confirm that MCP charges appear against the same key and team as model calls in your installed version. A gap here usually means charges are split across reports, which makes budgets and chargeback disagree.
Gaps to check before you price
Cost models only price calls the gateway sees. Calls that reach an MCP server directly, or retries that the gateway counts twice, can distort totals. Before you set prices, run a sample of real workloads through a test key, compare the charged amounts with the upstream usage you expect, and record any difference as a known variance.
Configuration options and when each fits
This table compares the three ways to price MCP tool calls in LiteLLM: a flat default per server, a per-tool price map, and a custom post-MCP hook. Read each row to see how much setup each method takes, how closely it matches real cost, and what breaks when tools change. The main takeaway is that the simplest method is usually right until tools differ meaningfully in cost or the price depends on the call itself.
| Option | Setup effort | Accuracy and maintenance | Simplest correct choice when |
|---|---|---|---|
| default_cost_per_query (per server) | Low: one value per server under the server's config entry | Every tool on the server is charged the same amount. Little upkeep, but tools with very different costs are over or under billed | All tools on a server cost roughly the same, or you only need a rough chargeback figure per server |
| tool_name_to_cost_per_query (per tool) | Moderate: a map from each tool name to its price, written into config | More accurate across tools on one server. Each new, renamed or removed tool needs a config change, or it falls back to the default | A server has a few tools with clearly different prices, and the tool list changes rarely |
| Custom post-MCP hook | High: a callback that computes cost from the call and result, deployed and tested with the gateway | Can price by arguments, result size or upstream usage. Needs code review and tests, and must be updated when upstream pricing or response shape changes | Cost depends on the request or response, such as result size or a metered upstream API, and finance needs call-level accuracy |
| Reporting it feeds | Spend appears per server and key using the flat rate | Spend appears per tool, so teams see which tools drive cost. Confirm how tool names appear in your spend reports | Spend must reconcile with an upstream invoice or support per-call chargeback |
| Effect on model spend views | Tool spend is recorded alongside model spend in the same key and team reporting | Same reporting path as the other options, with more granular line items as accuracy increases | You want one view of model and tool spend per team without building a separate tool ledger |
Setting up MCP cost tracking step by step
This sequence takes MCP servers that already sit behind the LiteLLM gateway and turns each tool call into a priced, attributable record tied to a team key, so tool spend appears alongside model spend.
Confirm servers are registered and reachable through the gateway
Before any pricing is added, confirm each MCP server is registered in LiteLLM and that a test client using a team key reaches its tools through the gateway endpoint, not directly. A caller that bypasses the gateway produces no LiteLLM spend record, so this is the first check. Ask the platform owner to list the registered servers and their server names, because the cost config keys off those exact names. The step is done when a tool call from the test key succeeds and appears in the request logs with the server and tool name.
Add default and per-tool costs to the config
In the proxy configuration, set a default cost per query for each MCP server, using default_cost_per_query, and add tool_name_to_cost_per_query entries for tools that need their own price. The server-level default covers tools you have not priced individually, while per-tool entries override it. Confirm the exact key names and value units against the LiteLLM MCP cost documentation for your release line before editing production config. The step is done when the proxy restarts cleanly and a configured tool shows the per-tool cost, while an unlisted tool on the same server falls back to the default.
Write and test a post-MCP hook for dynamic pricing
Only do this step if the price of a tool call depends on something known at call time, such as tool arguments, result size or the caller's contract tier. LiteLLM supports a custom post-MCP hook that calculates the cost dynamically. The engineer who owns the pricing rules writes the hook, then tests it in a non-production proxy with sample calls covering normal, edge and failed cases, confirming the computed value for each. Ask finance or the budget owner to approve the pricing logic in writing. The step is done when the test cases return the expected cost and the hook is reviewed and versioned with the rest of the config.
Issue test calls from a team key
Create or select a virtual key that belongs to a test team, with a budget the owner has approved, and use it to make a small, known set of MCP tool calls. Include at least one call to a priced tool, one to a tool using the default cost and one that you expect to fail, so you can see how failures are recorded. Record the number and names of calls you made so you can compare them with the logs. The step is done when every test call is accounted for in the logs with the expected server and tool name, and the failed call is handled as your policy requires.
Check spend against the key and team
Open the spend views for the test key and its team and confirm that the MCP charges from your test calls appear there, at the amounts your configuration and hook predicted. Compare the totals with the calculated expectation for each test call, and check that the MCP charges are separated from or clearly labeled against model charges so reports can distinguish them. If totals differ, check the config key names, the server name match and whether the hook returned a value before debugging further. The step is done when the expected total matches the observed total for the test set and the team's budget reflects the tool spend.
Confirm tool spend appears beside model spend in reports
Run a report or export that covers a day of mixed activity, with both model calls and MCP calls from the same team, and confirm the two spend types can be seen together by key and team. Ask the finance or FinOps owner to review whether the categories match how they plan to charge back. Keep the test configuration and pricing decisions recorded so later price changes can be traced. The step is done when the owner has signed off that tool spend and model spend roll up to the same team view and the chargeback categories are agreed.
How an MCP tool call becomes a spend record
The diagram starts with a caller presenting a virtual key to the LiteLLM proxy, which forwards the tool call to the MCP server and returns the result. The cost step runs on the proxy after the call: it applies default_cost_per_query or tool_name_to_cost_per_query from config, or the output of a custom post-MCP hook for dynamic pricing. The calculated amount is written to PostgreSQL against the key and its team, so tool spend sits in the same records as model spend. Before you rely on the totals, check on a test call that the config or hook produces the figure you expect.
Cost is calculated at the proxy after the MCP call and stored in PostgreSQL against the key and team.
Seeing MCP tool spend next to model spend
Tool spend and model spend land in the same gateway, so one set of keys, teams and budgets can cover both. When an MCP tool call is charged through the cost settings described above, it is recorded against the key and team that made the call, alongside the token spend from the model request that triggered it. That shared record is what lets a budget cap or a team report include tool calls and model calls together, instead of splitting them across two spreadsheets. Before finance relies on that combined view, confirm in your own LiteLLM version which spend views, exports and budget checks include MCP tool costs, because reporting surfaces change between releases and the current release line should be checked against the LiteLLM releases page before you design the reports.
Totals are only as good as attribution. Check that calls made through shared service accounts or machine keys are charged to the team that owns the workload, not to a generic key, and test this with a known set of calls from each team before go-live. Confirm also how a call that fails partway through is recorded, and whether a custom post-call hook that calculates dynamic prices writes its result to the same spend record. A hook that returns an unexpected value can skew a total without any error being raised, so review a sample of hook output against the rate table you agreed with the business owner.
Reconcile tool spend to invoices wherever the tool has its own bill. A search API, a hosted database or a third-party MCP service may charge per call, per record or per tier, and the gateway's estimate will differ from that invoice if the per-query rate in config does not match the vendor's actual billing unit. Plan a monthly comparison of call counts from gateway logs against vendor usage reports, and record any gap with its cause. Ask your DeployOpen contact or your own platform team to confirm where the gateway stores these records and how long they are kept, since that retention decision also determines how far back finance can reconcile.
Security and operational risks in tool cost tracking
Cost tracking for MCP tools touches code that runs inside the gateway, the pricing you configure, and the database that holds spend. The cards below cover one control each, so you can review them as separate items before the cost settings go live.
Review hook code as gateway code
A custom post-MCP hook runs inside the LiteLLM proxy, so it has the same access to request data, configuration and secrets as the gateway itself. Treat it as production code: require review, version it in Git, and deploy it through the same pipeline as the gateway configuration. Check what the hook reads, what it logs and whether it makes outbound network calls. Illustrative example: a hook that logs full tool arguments to debug output would copy customer data into log storage.
MCP cost docsKeep internal rates out of shared config
Per-tool prices and dynamic pricing formulas often reveal negotiated vendor rates or internal chargeback markups. Decide who can read the proxy configuration and the hook source, and keep rate tables in a secret manager or a restricted repository where your access policy applies. Confirm which admin roles can view configuration through the admin UI and API before you add pricing values there.
Pin tool names before pricing them
Cost settings map to tool names. If an upstream MCP server renames a tool or LiteLLM prefixes it differently after a registration change, calls may fall outside the configured price and spend totals drift without an error. Record the tool names each cost entry covers, and compare the registered tool list against the pricing table after every server update. Include a check in your change process for this comparison.
Plan for Postgres as the spend record
Virtual key spend depends on a PostgreSQL database, so an outage or misconfigured connection affects budget enforcement and spend reporting, not only the database itself. Confirm that the database is backed up and that you know which budget checks fail when it is unavailable. Monitor the database alongside the gateway so spend data is not silently missing.
Virtual keys docsReconcile tool spend with each run
Tool charges are estimates computed from your configured prices, not invoices from the upstream server. Compare the totals LiteLLM records for each server and key with your own usage records on a fixed schedule. Any gap points to a missing price, a renamed tool or a hook that returned an unexpected value.
Questions buyers ask about MCP cost tracking in LiteLLM
What drives the effort to set up MCP tool costs in LiteLLM?
The main driver is how many MCP servers and tools you register and how many different prices they need. LiteLLM can apply a flat default cost per query to each server, set a cost per individual tool, or run a custom post-MCP hook when the price depends on arguments, caller or results. A single server with one flat rate is a small configuration task. Dozens of servers with tool-level and dynamic pricing need a pricing model, a review of each tool's behavior and tests that confirm the right charge lands on the right team or key. Effort also rises if the spend must reconcile with provider bills or chargeback reports.
Can our own team set up MCP tool cost tracking without a partner?
Yes, if your team already runs LiteLLM and has someone comfortable editing the proxy configuration. The static part, default_cost_per_query per server and tool_name_to_cost_per_query per tool, is configuration, not code. A custom post-MCP hook is code that runs inside the gateway, so it needs a developer who can write, test and deploy it safely. Teams usually struggle with agreeing on the pricing rules, verifying that spend appears under the correct keys and teams, and keeping the configuration current as tools change. A partner is most useful when those decisions and tests are the bottleneck.
How long does MCP cost tracking setup take?
There is no fixed figure, because duration depends on the number of servers and tools, how many pricing rules you need and whether dynamic hooks are required. A short list of servers with flat per-query prices can be configured quickly and verified in a test environment. A large catalog with per-tool prices, team-level attribution and reconciliation to spend reports takes longer because each rule needs an owner, a test and sign-off. Ask any provider for a written scope that lists the servers, tools and pricing rules covered, and the test steps that will confirm the results before production.
What do we need to provide before cost tracking work starts?
Prepare three inputs. First, a tool inventory: every MCP server registered in LiteLLM, its tools, and which teams or keys call them. Second, pricing rules: the agreed cost per query for each server, any per-tool exceptions, and whether any price depends on arguments, caller or result size. Third, a test environment that runs LiteLLM with the same configuration as production, with non-production copies of the MCP servers or safe stand-ins, so you can make test calls and check the spend records without charging real budgets. Finance or FinOps owners should confirm how the figures will be used before go-live.
What does ongoing upkeep look like when MCP tools change?
Upkeep is recurring work. When a server adds, renames or removes a tool, its cost entries in the configuration must change too, or calls may be charged at the wrong rate or not tracked. When a dynamic post-MCP hook exists, a change in tool arguments or response shape can break its logic, so it needs regression tests before each change ships. Assign an owner for the pricing table, add a review step to your change process for new MCP servers, and rerun a set of test calls after each LiteLLM upgrade. Ask any partner whether upkeep is included in the fixed scope or sold as a retainer.
Will MCP tool spend show up next to model spend in LiteLLM?
LiteLLM tracks MCP costs from its configuration, so the cost of MCP tool calls can be attributed to the server and tool that were called. Confirm in your own environment how those entries appear in the spend views and exports you use, and whether they are grouped with model spend by key, team or user. Test one call from each team in a non-production setup, then compare the recorded spend with what you expected before you rely on it for chargeback or budgets.
Do MCP cost settings change what a caller is allowed to do?
Cost settings record and price tool calls. They do not, on their own, decide who may call a tool. Access is controlled separately, through key, team and organization permissions on each MCP server and tool. Plan both together: a tool that is priced but open to every key will create spend nobody approved, and a restricted tool with no cost entry will be used without attribution. Confirm both the permission model and the pricing rules in your test environment before go-live, and ask your provider to cover both in the written scope.
Official LiteLLM documentation on MCP cost tracking
Start with the LiteLLM MCP cost tracking documentation for the exact config keys and hook behavior. The two settings you will use most are default_cost_per_query on an MCP server and tool_name_to_cost_per_query for per-tool prices, while the custom post-MCP hook covers calculations that depend on the request or the response. Read the hook section before you write any pricing logic, and confirm in the current docs which fields the hook receives and whether it runs on every call or only on some transports. Pin your LiteLLM version when you test these settings, because the hook interface is the part most likely to change between releases.
Cost attribution is only as good as the identity attached to each call. MCP charges land on the key, team and user that made the request, so the virtual keys documentation is the reference for how per-key and per-team budgets are set up, and the routing documentation explains how requests are distributed across backends and retried. Check that every client, including developer tools and service accounts, calls the gateway with a key that belongs to a team, and confirm that a tool call made through an agent still records the key that initiated it. Unattributed or shared keys will produce spend that finance cannot allocate.
How DeployOpen scopes and delivers MCP cost tracking
DeployOpen starts by mapping which MCP servers, teams and keys need tool-level charges, then configures LiteLLM to record those costs next to model spend. Each engagement is fixed-scope, with the cost model, tests and handover agreed in writing before work begins.
How we scope
- Inventory every MCP server registered in your LiteLLM proxy and the teams and keys that call it
- Agree which charge model applies to each server: a default cost per query or per-tool costs
- Define where dynamic pricing is needed and document the inputs a custom post-call hook may read
- Confirm the spend reports and budgets that finance and team leads will use to review tool charges
How we build
- Write the config entries for default_cost_per_query and tool_name_to_cost_per_query per server
- Build and test any custom post-MCP hook for dynamic calculations in a non-production instance first
- Verify tool calls appear in spend logs with the expected team and key attribution
- Reconcile tool spend against model spend so both appear together in the same reporting view
How we hand over
- Deliver the cost configuration as versioned files with a record of every price assumption
- Document the hook logic, its inputs, failure behavior and how to change a price safely
- Provide a runbook for adding a new MCP server or tool to the cost model
- Walk your platform and finance owners through the reports and the handover checklist
How we support
- Ongoing support, upgrades and continuous testing are available as a retainer after handover
- Review cost configuration again when you add servers, change tool pricing or upgrade LiteLLM
- Confirm with your own environment and the LiteLLM documentation which release line you run before planning changes
- Ask any quote to state what is one-time build work and what recurs under a retainer

