get_session_cost
Returns token totals and USD cost estimates for the current session. All costs are estimates; verify with your LLM provider's billing dashboard.
無需輸入參數。

io.github.dbsectrainer由 GitHub 帳號 dbsectrainer 發布v1.0.1更新於 Nov 4, 2026
Real-time cost awareness for MCP agent workflows
發布方自己的服務:370.ai — AI Gateway: 100+ Chat Models, Image & Speech Generation
本機 MCP 伺服器,用來統計代理工作階段的 token 用量與估算美元成本、發出預算警示並建議更省錢的模型路由。
Desktop only,透過 STDIO。 STDIO 服務會啟動本機處理程序,因此需要 SourceWeft 桌面主機。
參照 儲存庫 中的啟動說明。
npm mcp-cost-tracker-router package
Local-first cost awareness for MCP agent workflows. Token counts are calculated offline using js-tiktoken — no proxy, no API round-trip, no spend data leaving your machine. When costs climb, routing suggestions point you to cheaper models before the invoice arrives.
Tool reference | Configuration | Contributing | Troubleshooting
Most cost-tracking tools work by routing all your API traffic through their server and measuring tokens server-side. That means your prompts and responses transit a third-party service, and you're dependent on their uptime.
If your prompts contain sensitive information or you can't route traffic through a third party, this is the right tool. If you need a managed dashboard with team sharing, a proxy-based service may suit you better.
mcp-cost-tracker-router stores tool call metadata (token counts, model names, timestamps) locally in SQLite. It does not store prompt or response content. Cost calculations are estimates based on a local pricing table and may not exactly match your provider's invoice.
Add the following config to your MCP client:
To set a session budget alert:
Amp · Claude Code · Cline · Cursor · VS Code · Windsurf · Zed
Enter the following in your MCP client to verify everything is working:
Your client should return a token and USD cost summary for the current session.
get_session_cost — Returns token totals and USD cost estimates for the current session. Read-only.get_tool_costs — Returns per-tool cost breakdown for the session, sorted by cost descending. Read-only.reset_session — Start a new cost-tracking session. Previous session data is retained in history.record_usage — Record token usage for a tool call. Takes tool_name, model (optional), input_tokens, and output_tokens. Emits a budget warning notification if 80% of threshold is reached.set_budget_alert — Set a budget threshold in USD (threshold_usd). Warns at 80% and 100% of the threshold. Use with --enforce-budget to block calls beyond the limit.suggest_model_routing — Heuristic model recommendation by task type. Takes task_description and optional constraints.max_cost_usd. Returns recommended model with reasoning and estimated cost.check_routing_policy — Check whether a model is allowed for a given task type under the routing policy. Takes task_type and model.get_spend_history — Query historical spend aggregated by period (day/week/month). Returns breakdown by model and tool. Read-only.estimate_workflow_cost — Pre-run cost estimation for a multi-step workflow. Takes a steps array with tool_name, estimated_input_tokens, estimated_output_tokens, and optional model. Read-only.export_spend_report — Generate a single-file HTML spend report with session breakdown, historical spend, model cost comparison, and budget status. Read-only.export_budget_audit — Export the audit log of budget enforcement decisions. Accepts optional from_date, to_date, and format (json/csv). Read-only.set_project — Create or update a project with an optional budget_usd. Takes project_name.tag_session — Tag the current session with a project_name for cost allocation.get_project_costs — Get cost report for a project. Takes project_name and optional since (ISO date). Read-only.export_chargeback — Generate a chargeback report for internal billing. Takes from_date, to_date, optional group_by (project/session), and optional format (json/csv). Read-only.--budget-alertSession spend threshold in USD. A warning is returned when session costs reach 80% and again at 100% of this threshold.
Type: number
--db / --db-pathPath to the SQLite database file used to store cost history.
Type: string
Default: ~/.mcp/costs.db
--pricing-tablePath to a JSON file containing custom model pricing ($/1K tokens). Merged with the built-in table; missing models fall back to defaults.
Type: string
--default-modelModel name to attribute costs to when no model can be inferred from context.
Type: string
Default: claude-sonnet-4-6
--enforce-budgetBlock tool calls that would cause the session to exceed the budget alert threshold. Requires --budget-alert to be set.
Type: boolean
Default: false
--http-portStart in HTTP mode using Streamable HTTP transport instead of stdio. Useful for sharing a single cost-tracking instance across a team.
Type: number
Default: disabled (uses stdio)
Pass flags via the args property in your JSON config:
Built-in pricing table (USD per 1K tokens):
Override individual model prices with --pricing-table. All costs are estimates.
Before publishing a new version, verify the server with MCP Inspector to confirm all tools are exposed correctly and the protocol handshake succeeds.
Interactive UI (opens browser):
CLI mode (scripted / CI-friendly):
Run before publishing to catch regressions in tool registration and runtime startup.
Update src/pricing.ts when new models are released. All cost calculation changes must include unit tests with known token counts and expected USD values. Routing suggestions live in src/tools/routing.ts.
This plugin is available on:
Search for mcp-cost-tracker-router.
來源:README.md,提交 7a8f731
Returns token totals and USD cost estimates for the current session. All costs are estimates; verify with your LLM provider's billing dashboard.
無需輸入參數。
Returns per-tool cost breakdown for the current session, sorted by cost descending. Useful for identifying the most expensive operations. All costs are estimates.
無需輸入參數。
Set a budget threshold in USD. A warning is emitted when session costs reach 80% or 100% of this threshold. Use with --enforce-budget to block calls beyond the limit.
threshold_usd必填Start a new cost-tracking session. Previous session data is retained in history and accessible via get_spend_history.
無需輸入參數。
Query historical spend aggregated by time period (day/week/month). Returns breakdown by model and tool across all sessions. All costs are estimates.
periodRecord token usage for a tool call. Logs LLM API cost estimates into the tracker. Emits a budget warning (notifications/message) if 80% of threshold is reached. Pricing table versions are tracked in CHANGELOG.md.
modeltool_name必填input_tokens必填output_tokens必填Heuristic model recommendation by task type. Analyzes the task description and returns a recommended model with reasoning and estimated cost per 1K tokens. Optionally factors in cost constraints.
constraintstask_description必填Pre-run cost estimation for a multi-step workflow. Provide a list of tool steps with estimated token counts and models to get total and per-step cost estimates. Output is clearly labeled as ESTIMATE.
steps必填Generate a single-file HTML spend report with session cost breakdown, historical spend by period, model cost comparison chart (CSS bars), and budget status. No external CDN dependencies.
無需輸入參數。
Export audit log of budget enforcement decisions. Optionally filter by date range and format as JSON or CSV.
formatto_datefrom_dateCreate or update a project with an optional budget in USD.
budget_usdproject_name必填Get cost report for a project, optionally filtered by a since date.
sinceproject_name必填Tag the current session with a project name for cost allocation.
project_name必填Generate a chargeback report for internal team billing, grouped by project or session.
formatto_date必填group_byfrom_date必填Check whether a model is allowed for a given task type under the routing policy.
model必填task_type必填已滿足適用檢查項的 90%
該評分衡量此收錄條目的完整程度,依據註冊中心條目、端點與公開來源計算得出。它不是對伺服器本身的評價,也不表示伺服器安全或目前可用:可連通性是帶日期的檢查結果,評分也不包含安裝量或使用者評價。
請在註冊中心條目中宣告憑證請求標頭,或保持端點能夠回應探測,以便判定其認證方式。
ai.router官方發布者
遠端 AI 閘道 MCP 伺服器,讓助理用一組 370.ai API 金鑰呼叫 100 多個聊天模型、生成圖片並將文字轉成語音。

由 GitHub 帳號 jutsuhq 發布
本機 MCP 伺服器,用你自己的 API 金鑰透過 40 多家供應商生成圖片與影片,支援比價與可搜尋的本機素材庫。

由 GitHub 帳號 JonasHeinickeBio 發布
連接自架 pyBikeRouter API 的 MCP 伺服器,可規劃以 OSM 為基礎的單車路線,並附上天氣、景點與 GeoJSON/GPX 匯出。

由 GitHub 帳號 Elnaril 發布
本機 MCP 伺服器,用來解碼與編碼 Uniswap Universal Router 的 V2、V3、V4 呼叫資料,僅供讀取,不簽章也不送出交易。

由 GitHub 帳號 camerxnduff 發布
唯讀 MCP 伺服器,可搜尋經探測的 x402 按次付費端點登錄檔,並為助理路由到評分最高的端點。
{ "mcpServers": { "cost-tracker": { "command": "npx", "args": ["-y", "mcp-cost-tracker-router@latest"] } }}{ "mcpServers": { "cost-tracker": { "command": "npx", "args": ["-y", "mcp-cost-tracker-router@latest", "--budget-alert=5.00"] } }}How much has this session cost so far?{ "mcpServers": { "cost-tracker": { "command": "npx", "args": [ "-y", "mcp-cost-tracker-router@latest", "--budget-alert=2.00", "--enforce-budget" ] } }}npm run build && npm run inspect# List all toolsnpx @modelcontextprotocol/inspector --cli node dist/index.js --method tools/list
# List resources and promptsnpx @modelcontextprotocol/inspector --cli node dist/index.js --method resources/listnpx @modelcontextprotocol/inspector --cli node dist/index.js --method prompts/list
# Call a read-only toolnpx @modelcontextprotocol/inspector --cli node dist/index.js \ --method tools/call --tool-name get_session_cost
# Call record_usage with argumentsnpx @modelcontextprotocol/inspector --cli node dist/index.js \ --method tools/call --tool-name record_usage \ --tool-arg tool_name=my_tool --tool-arg input_tokens=500 --tool-arg output_tokens=200npm install && npm test