ICA Metering Exporter
Pure-Python CPEX plugin that exports MCP tool pre/post invocation metering to the ICA core-services endpoint. Ported from IBM/mcp-context-forge PR #5696.
Features
- Records tool latency, result status, token counts, gateway identity, and transport.
- Resolves model attribution through a deterministic seven-level cascade.
- Attributes app, MCP client user agent, assistant, agent, and digital-IBMer context from inbound HTTP extensions.
- Authenticates with an HS256 service JWT, falling back to a static metering token.
- Awaits each export sequentially and treats export failures as best effort so tool execution continues.
- Is disabled by default.
Configuration
| Key | Meaning |
|---|---|
enabled |
Enables client creation and export. Defaults to false. |
metering_url |
ICA metering endpoint URL. |
metering_token |
Static fallback token sent as X-MCP-Metering-Token. |
jwt_secret |
HS256 secret used to issue a one-day service JWT. Takes precedence over the static token. |
gateways[].id |
Gateway identifier for a per-gateway model fallback. |
gateways[].default_model |
Model fallback for the matching gateway identifier. |
global_default_model |
Last configured model fallback. |
include_model_source |
Adds the selected model-source label to the ICA payload. |
plugins:
- name: ica_metering_exporter
kind: cpex_ica_metering_exporter.plugin.IcaMeteringExporterPlugin
hooks: [tool_pre_invoke, tool_post_invoke]
mode: sequential
priority: 200
capabilities: [read_headers]
config:
enabled: false
metering_url: "https://metering.example.invalid/events"
Supply tokens and JWT secrets through deployment environment/configuration secret injection; never commit them.
Inbound headers and capability
Caller attribution reads only extensions.http.headers, using case-insensitive names. It never reads payload headers and never invents app or persona values when attribution headers are absent. Unit tests pass Extensions directly and therefore intentionally bypass gateway capability filtering.
Gateway registration must grant read_headers to this plugin. CPEX guards HttpExtension; without the capability the gateway strips inbound headers and attribution remains empty.
Recognized identity headers include X-OpenWebUI-Model-Id, X-App-Id, X-MCP-Client-Name, X-MCP-Client-Version, X-Forwarded-User-Agent, User-Agent, and the nine persona headers used by ICA/Open WebUI.
Model precedence
The first available source wins:
X-OpenWebUI-Model-Idcaptured during pre-invoke- session
global_context.metadata.model_name MCP_DEFAULT_MODEL- tool-call
meta_data.model - configured gateway
default_model - configured
global_default_model - unknown (
None)
OpenTelemetry metadata
When extensions.request.trace_id is non-empty, post-invoke returns:
result.metadata["ica_metering_exporter"] = {
"export_status": "sent",
"latency_ms": 12,
"model_source": "transport_header",
"stage": "tool_post_invoke",
}
The trace ID is an input gate only and is never emitted. Metadata contains aggregated operational fields only—never tokens, headers, payloads, app IDs, user agents, persona data, arguments, or output.
Registration mode
The export is awaited and best effort. Register the plugin in the framework's default SEQUENTIAL mode. FIRE_AND_FORGET discards hook return values and would therefore discard the returned OpenTelemetry metadata.
Development
make sync
make check-all
make test
make build
Metadata
Release files for cpex-ica-metering-exporter 0.1.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| cpex_ica_metering_exporter-0.1.2.tar.gz | 12.2 kB | With provenance | Details for cpex_ica_metering_exporter-0.1.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| cpex_ica_metering_exporter-0.1.2-py3-none-any.whl | Python 3 | none | any | Details for cpex_ica_metering_exporter-0.1.2-py3-none-any.whl |
Total release size: 21.4 kB
Release files / cpex_ica_metering_exporter-0.1.2.tar.gz
| Download URL | cpex_ica_metering_exporter-0.1.2.tar.gz |
|---|---|
| Size | 12.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
471a5832569c3b9905cdd63a454f8dd9680c59a612559c270e69fe3a60b22e9d
|
|
BLAKE2b-256 checksum How to use checksums |
12b95486834878e3745d2cfc9738001ebeb45e827577e28462ad1fd3712ef315
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 22, 2026.
Transparency logRelease files / cpex_ica_metering_exporter-0.1.2-py3-none-any.whl
| Download URL | cpex_ica_metering_exporter-0.1.2-py3-none-any.whl |
|---|---|
| Size | 9.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
df31b308f9562059582e0e98e37eddd9ae9f070afaeb193b1a1b415345342e21
|
|
BLAKE2b-256 checksum How to use checksums |
975b97e5e893c94e1e8358d5da527a02234d837eb26c9c51805ca18da8fd4c6e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 22, 2026.
Transparency logSecurity for cpex-ica-metering-exporter 0.1.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
All 2 files in this release have been uploaded with provenance metadata.
Attestation for cpex_ica_metering_exporter-0.1.2.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 22, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.