Record arguments and results safely
By default the middleware records sizes, not contents. When you need the
arguments and results themselves, for debugging or for replaying a failure,
switch to full mode. Secrets are removed before anything reaches a sink.
Choose a mode
Section titled “Choose a mode”| Mode | Records |
|---|---|
off | Nothing; calls pass straight through |
meta (default) | Tool, timing, outcome, identity, argument and result sizes |
full | Also the arguments and result, redacted |
Set it in code:
from fastmcp import FastMCPfrom fastmcp_feedback.instrumentation import MemorySink, instrument
app = FastMCP("My Server")sink = MemorySink()mw = instrument(app, [sink], mode="full")or with the environment, which is read when the middleware is created and
applies when mode is not passed:
FEEDBACK_INSTRUMENTATION_MODE=full uv run server.pyKeep some tools at meta
Section titled “Keep some tools at meta”Tools whose arguments are sensitive by nature (code to run, credentials to
create) can stay at meta while the rest of the server records in full:
mw = instrument(app, [sink], mode="full", meta_only_tools={"run_code", "create_token"})What redaction removes
Section titled “What redaction removes”Redaction applies to arguments, results, error messages, identity and enricher output, and event attributes. It works two ways:
- By key, at any depth: a dict value is replaced with
[REDACTED]when its key, lowercased with-turned into_, is one oftoken,password,authorization,cookie,secret,client_secret,api_key,private_keyand similar, or ends in_token,_secret,_password,_api_key,_apikeyor_private_key. - By value, anywhere in text: JWTs,
Bearer ...,sk-...API keys, GitHub, Slack, AWS, PyPI andbmcp_tokens, andpassword=...,token: ...style pairs in error text.
The full lists are in the redaction reference.
import asyncio
from fastmcp import Client
@app.tooldef deploy(service: str, github_token: str) -> dict: return {"service": service, "log": "pushed with Bearer abcdef0123456789"}
async def main(): async with Client(app) as client: await client.call_tool("deploy", {"service": "api", "github_token": "ghp_x"}) await mw.flush() call = sink.calls[-1] print(call.args) # {'service': 'api', 'github_token': '[REDACTED]'} print(call.result) # {'service': 'api', 'log': 'pushed with [REDACTED]'}
asyncio.run(main())Sizes (args_size, result_size) are measured before redaction.
Payload size limit
Section titled “Payload size limit”A result can run to megabytes. max_payload_bytes (64 KiB by default) bounds
what a row stores: the arguments and result in full mode, and every event’s
attrs. A larger value is stored as a
truncation marker holding its size
and the start of its JSON text. The preview is cut after redaction, so it
cannot end halfway through a secret that redaction would have caught.
@app.tooldef series(n: int) -> dict: return {"points": [[i, i * 0.5] for i in range(n)]}
async def show_marker(): async with Client(app) as client: await client.call_tool("series", {"n": 50_000}) await mw.flush() stored = sink.calls[-1].result print(stored["_truncated"], stored["size"], stored["preview"][:30]) # True 866741 {"points": [[0, 0.0], [1, 0.5]
asyncio.run(show_marker())The limit reuses the size already measured for args_size and
result_size, so it adds no encoding; building the preview encodes only the
start of the value. Pass max_payload_bytes=None to store everything, or a
smaller number for a tighter bound. Tools that always return large results
are better kept at meta with meta_only_tools, which skips their
redaction work too.
Add your own rules
Section titled “Add your own rules”Pass a Redactor with extra keys and regular expressions. They are added to
the defaults, not substituted for them:
from fastmcp_feedback.instrumentation import Redactor, instrument
app = FastMCP("Licensed Server")mw = instrument( app, mode="full", redactor=Redactor(extra_keys=["license"], extra_patterns=[r"acme_[A-Za-z0-9]{32}"]),)To replace a default list, pass keys= or patterns= instead. The same
redactor is used for embedded text when you add an
embedding sink.