ai-credits-mcp
MCP server that exposes AI credit usage data from OpenMeter to the TAIS AI chat service, automatically scoped to the calling tenant and restricted to admin users.
README
ai-credits-mcp
MCP server that exposes AI credit usage data from OpenMeter to the TAIS AI chat service. Queries are automatically scoped to the calling tenant and restricted to admin users.
Tools
All tools require the caller to be in the Administrators group. Each tool returns a markdown table (for the LLM to summarise) and a [Download Excel](url) link pointing to a temporary .xlsx file served at /download/<token>. The link expires after 10 minutes. They are automatically scoped to the calling user's tenant — no tenant parameter is exposed.
If the request exceeds 50 rows in the text preview, the table is truncated with a note to see the Excel file for the full dataset.
get_credit_usage_by_tenant
Returns total credits consumed by the tenant as a single aggregated number.
| Parameter | Type | Required | Description |
|---|---|---|---|
from_date |
string | No | ISO 8601 start, e.g. "2026-01-01T00:00:00Z" |
to_date |
string | No | ISO 8601 end (defaults to now) |
Output columns: tenant, credits
Example prompts:
- "How many AI credits has my tenant used?"
- "What's our total credit spend this month?"
get_credit_usage_summary
Returns credits broken down by user, module, product, and skill — useful for identifying who or what is consuming the most credits.
| Parameter | Type | Required | Description |
|---|---|---|---|
from_date |
string | No | ISO 8601 start |
to_date |
string | No | ISO 8601 end (defaults to now) |
Output columns: user, module, product, tenant, skill, credits
Example prompts:
- "Show me credit usage broken down by user."
- "Which product or skill is using the most credits?"
- "Give me a credit usage summary for Q1 2026."
get_credit_events
Returns individual raw credit events — the lowest level of detail, one row per event.
| Parameter | Type | Required | Description |
|---|---|---|---|
from_date |
string | No | ISO 8601 start |
to_date |
string | No | ISO 8601 end (defaults to now) |
Output columns: time, user, module, product, tenant, credits
Example prompts:
- "Show me all credit events from last week."
- "What happened on January 15th in terms of AI usage?"
How the AI decides which tool to call
When you ask about credit usage in the AI chat, the model picks the appropriate tool automatically:
- Totals / "how much overall" →
get_credit_usage_by_tenant - Breakdowns by user / module / skill →
get_credit_usage_summary - Individual events / audit trail →
get_credit_events
If no date range is specified, the last 7 days are used by default. To change the range, phrase your question naturally: "...for January 2026" or "...since last month" — the model will translate this to ISO 8601 parameters.
Security
| Invariant | Enforcement |
|---|---|
| Admin-only access | X-User-UserRole checked on every call; accepted values: admin, Administrators |
| Tenant-scoped | X-Tenant-Name header used as filter; callers cannot override it |
| Tenant header absent | Returns an error — no data is exposed |
OPENMETER_API_KEY never exposed |
Only used inside query_credits._get(); never returned to callers |
The TAIS chatbot-agent-service forwards both headers automatically on every MCP connection.
Running locally
Prerequisites: Python 3.11+, uv
cd ai-credits-mcp
uv sync # install dependencies
cp .env.example .env # add your OPENMETER_API_KEY
uv run main.py
# Server starts at http://localhost:8765
Health check:
curl http://localhost:8765/health
# {"status": "ok"}
AI chat integration
Use the registration script to register the tool and wire it to a TAIS session:
bash scripts/register.sh
The script reads TAIS_JWT from .env, decodes the tenant and user automatically, registers the tool against the local TAIS API, and PATCHes the session. If TAIS_SESSION_ID is not set in .env it will prompt you interactively.
Note: registered tools expire after ~1 hour. Re-run the script when the tool stops responding.
To wire to a session manually:
PATCH http://localhost:5001/api/v2/sessions-service/{sessionId}
Authorization: Bearer <token>
Content-Type: application/json
{"toolIds": ["<tool-id-from-registration>"]}
Environment variables
| Variable | Required | Description |
|---|---|---|
OPENMETER_API_KEY |
Yes | OpenMeter API key |
MCP_PORT |
No | Port to listen on (default: 8765) |
TAIS_JWT |
No | JWT for scripts/register.sh — not used by the server at runtime |
TAIS_SESSION_ID |
No | Session to wire the tool to; script prompts if absent |
TENANT_OVERRIDE |
No | Dev only — overrides X-Tenant-Name header |
ROLE_OVERRIDE |
No | Dev only — overrides X-User-UserRole header |
Project structure
ai-credits-mcp/
├── server.py # FastMCP server, tools, middleware, download endpoint
├── main.py # uvicorn entry point
├── scripts/
│ └── register.sh # registers tool with TAIS and wires it to a session
├── pyproject.toml # dependencies (mcp, uvicorn, openpyxl, python-dotenv)
└── .env.example # environment variable template
server.py imports query_credits from the sibling ai-credit-usage/ directory, which handles all OpenMeter API calls.
Aspire registration
Registered in apphost.cs as:
var aiCreditsMcp = builder.AddPythonApp("ai-credits-mcp", "/Users/a.demers/dev/ai-credits-mcp", "main.py")
.WithUv()
.WithEnvironment("PYTHONPATH", ".")
.WithHttpEndpoint(port: 8765, env: "MCP_PORT", isProxied: false)
.WithHttpHealthCheck("/health")
.WithEnvironment("OPENMETER_API_KEY", Environment.GetEnvironmentVariable("OPENMETER_API_KEY") ?? "");
Add OPENMETER_API_KEY=<your-key> to the workspace-root .env file.
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。