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
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file cpex_ica_metering_exporter-0.1.0.tar.gz.
File metadata
- Download URL: cpex_ica_metering_exporter-0.1.0.tar.gz
- Upload date:
- Size: 12.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
82d4b0d62d3a7dd456390dca6008ae7c6b4bf64d09d5c9aad66f961813a2a6b9
|
|
| MD5 |
c8ae7488883a0583435f0076f834a931
|
|
| BLAKE2b-256 |
484ae72af457e22f874bce5cc164d1b93ead2d73be3a284d1f3f0bd5b37750a0
|
Provenance
The following attestation bundles were made for cpex_ica_metering_exporter-0.1.0.tar.gz:
Publisher:
release-python-package.yaml on IBM/cpex-plugins
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
cpex_ica_metering_exporter-0.1.0.tar.gz -
Subject digest:
82d4b0d62d3a7dd456390dca6008ae7c6b4bf64d09d5c9aad66f961813a2a6b9 - Sigstore transparency entry: 2605104672
- Sigstore integration time:
-
Permalink:
IBM/cpex-plugins@e48dc2092f1ca2dfb539c3ca69ab4622f4c23e7e -
Branch / Tag:
refs/tags/ica-metering-exporter-v0.1.0 - Owner: https://github.com/IBM
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release-python-package.yaml@e48dc2092f1ca2dfb539c3ca69ab4622f4c23e7e -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file cpex_ica_metering_exporter-0.1.0-py3-none-any.whl.
File metadata
- Download URL: cpex_ica_metering_exporter-0.1.0-py3-none-any.whl
- Upload date:
- Size: 9.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
970019fa4a4568615e29505d4e7a5a45a05699a3097ec84037099442162e7b80
|
|
| MD5 |
c80328badae3f44468d7f6eb4e895684
|
|
| BLAKE2b-256 |
71e04ef8db3c9d7f37c753c81d200dc2eda15f08d40ebc839e8a188c5985d107
|
Provenance
The following attestation bundles were made for cpex_ica_metering_exporter-0.1.0-py3-none-any.whl:
Publisher:
release-python-package.yaml on IBM/cpex-plugins
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
cpex_ica_metering_exporter-0.1.0-py3-none-any.whl -
Subject digest:
970019fa4a4568615e29505d4e7a5a45a05699a3097ec84037099442162e7b80 - Sigstore transparency entry: 2605105034
- Sigstore integration time:
-
Permalink:
IBM/cpex-plugins@e48dc2092f1ca2dfb539c3ca69ab4622f4c23e7e -
Branch / Tag:
refs/tags/ica-metering-exporter-v0.1.0 - Owner: https://github.com/IBM
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release-python-package.yaml@e48dc2092f1ca2dfb539c3ca69ab4622f4c23e7e -
Trigger Event:
workflow_dispatch
-
Statement type: