Redact sensitive data¶
Crash dumps can contain secrets, tokens, or personal data. When your MCP client sends tool output to a cloud model, you may need to scrub that text first. A filter script does this in the server, before anything leaves the machine.
Write a filter script¶
A filter is a small Python file with a process_input and/or process_output function. Each
receives the text and a context, and returns the replacement text (or None to leave it
unchanged):
redact.py
import re
EMAIL = re.compile(r"[\w.+-]+@[\w-]+\.[\w.-]+")
def process_output(text, context):
return EMAIL.sub("[redacted-email]", text)
process_outputrewrites the text returned by tools (the part the model sees).process_inputrewrites string-valued tool arguments before the tool runs.
Wire it into your client¶
Add --filter-script to the server arguments, pointing at your script:
"args": ["--from", "git+https://github.com/svnscha/mcp-windbg", "mcp-windbg",
"--filter-script", "C:\\filters\\redact.py"]
Now every tool result is run through process_output before it reaches the client.
What the filter can and cannot see¶
- It sees tool text only: string arguments (
process_input) andTextContentoutput (process_output). It never sees the raw MCP protocol envelope, which keeps the surface small. - The
contextgiveshook,tool_name,transport, andcall_id;process_inputalso getsargument_path(such as$.command) andprocess_outputgetscontent_index. Usecall_idto correlate a call's input and output. - It runs in-process with the server, so treat it as trusted code. A hook that raises is reported as a tool error rather than crashing the server.
Related¶
- Filter script hooks - the full hook contract and a worked input + output example.