mcpledger (Python)
Records every tool call your Python MCP server handles and sends it to an mcpledger collector: who called, which tool, the arguments, the result status, how long it took. Personal data is masked inside your server before anything is sent.
Works with the official mcp package, version 1 (FastMCP, low-level Server) and version 2 (MCPServer,
low-level Server).
Install
pip install mcpledger # or: uv add mcpledger
Use it
from mcp.server.mcpserver import MCPServer # mcp 1.x: from mcp.server.fastmcp import FastMCP
import os
from mcpledger import instrument
server = MCPServer("payments-ops", version="1.0.0")
trail = instrument(
server,
api_key=os.environ["MCPLEDGER_KEY"],
endpoint="https://your-collector.example.com",
identify=lambda ctx: current_user_id(), # optional: the end user behind the call, from your auth
)
# register tools as usual, before or after instrument()
Options: identify(ctx) gets the request context and may be async. redact_keys adds argument names to mask
(strings or regex patterns). flush_interval (seconds, default 2) and max_batch (default 50) control sending.
on_error receives send failures. disable_redaction=True is for local testing only.
trail.flush() and trail.close(timeout=5) are async; flush_sync() and close_sync() exist for sync code. close sends
what is queued for at most timeout seconds and counts the rest as dropped. Queued events
are also sent when the process exits. trail.dropped counts events that could not be delivered.
One sender per collector
Every instrument() call with the same api_key and endpoint in a process shares one sender: one queue and
one background thread. A server built per request (stateless HTTP) therefore still sends in batches.
flush() sends the shared queue, and dropped counts for every server on it. close() flushes, and only the
last Trail on a sender stops it. The sending options (flush_interval, max_batch, max_queue, on_error)
come from the first instrument() call for that destination; later calls do not change them. At normal
interpreter exit the queue is flushed for at most 2 seconds. On SIGTERM it is flushed the same way, then the signal does what it
did before: your own handler runs, the default action ends the process, or an ignored signal stays ignored. The
hook is installed from the main thread only. A framework that installs its own SIGTERM handler later (uvicorn,
for one) replaces it, and its graceful shutdown then ends in a normal exit, which atexit covers. On Windows a
SIGTERM from another process ends the process without running any handler, so call close() yourself where
you can.
What gets masked
Values under secret-looking keys (password, token, api key, authorization, cookie, session id, private key,
OTP, PIN, CVV) become [redacted]. Inside any string, emails become [email], card numbers that pass the Luhn
check become [card] and IBANs become [iban]. Error text is masked the same way.
Sessions
Each event carries the transport session id when there is one (streamable HTTP). Without one, each connection
gets its own conn-... id. On the stateless MCP protocol (2026-07-28, mcp 2.x) every request is its own
connection, so a stdio or in-process server uses one id for the whole process, and an HTTP server sends no
session id.
Errors
The SDK never raises into your server. Sending runs on a background thread; when the collector is down, a batch
is tried three times with backoff and then dropped. A 4xx answer other than 429 is not retried. Events the collector
rejects (listed in its answer) count as dropped and go to on_error. Arguments over 32 KB are replaced by a size note.
Values masked by key are also masked where they reappear in error text, such as a validation error quoting the input.
On mcp 2.x, MCPServer tells the client only "Error executing tool " when a tool raises. The event keeps
the real cause too, masked like all error text.
Develop
uv venv --python 3.12 .venv
uv pip install --python .venv/Scripts/python.exe -e ".[dev]"
.venv/Scripts/python.exe -m pytest
Against a running collector: python scripts/e2e.py http://localhost:8788 <api key>.
Metadata
Release files for mcpledger 0.1.0
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 |
|---|---|---|---|---|
| mcpledger-0.1.0.tar.gz | 18.5 kB | With provenance | Details for mcpledger-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| mcpledger-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for mcpledger-0.1.0-py3-none-any.whl |
Total release size: 33.1 kB
Release files / mcpledger-0.1.0.tar.gz
| Download URL | mcpledger-0.1.0.tar.gz |
|---|---|
| Size | 18.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
f2e75cb14b1a00c04d9642b36fd0e5c900e3e506cb7cd574837bae1be67ba290
|
|
BLAKE2b-256 checksum How to use checksums |
b7ec7e33719238a8dcd1d64eecdfe2df665681c28c88619847aa39bcdf0bc809
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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 Dec 1, 2026.
Transparency logRelease files / mcpledger-0.1.0-py3-none-any.whl
| Download URL | mcpledger-0.1.0-py3-none-any.whl |
|---|---|
| Size | 14.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
63b47f48dec45129fc22c72376f9b20c2756c140382301e0517a863dd1cf4406
|
|
BLAKE2b-256 checksum How to use checksums |
fd421b81fc5ea295c340b4d163ddf987a6be7442858d650f77290eea98dd30e8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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 Dec 1, 2026.
Transparency logSecurity for mcpledger 0.1.0
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
Both files in this release have been uploaded with provenance metadata.
Attestation for mcpledger-0.1.0.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 Dec 1, 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.