loading…
Search for a command to run...
loading…
Local-first CLI and MCP server for redacting sensitive text before sharing logs, configs, and errors with AI tools.
Local-first CLI and MCP server for redacting sensitive text before sharing logs, configs, and errors with AI tools.
中文 | English
本地优先的 CLI 和 MCP Server,用于在把日志、配置、报错等文本分享给 AI 工具之前,先自动脱敏敏感信息。
mcp-redact 只做一件事:在你把内容粘贴给 Claude Code、Cursor 或其他 AI 工具之前,先把 secret 和敏感数据脱敏。
开发者经常会把日志、.env 文件、请求头、报错堆栈、配置片段直接贴给 AI 工具。这些内容里很可能包含 API Key、Bearer Token、Cookie、邮箱地址等敏感值。
mcp-redact 的设计目标是让这件事更安全:
[REDACTED_EMAIL]Authorization: Bearer abcdefghijklmnop123456
[email protected]
callback=https://example.com/callback?token=secret123&lang=en
Cookie: session=abcdef123456; theme=dark
Authorization: Bearer [REDACTED_AUTHORIZATION_HEADER]
user_email=[REDACTED_EMAIL]
callback=https://example.com/callback?token=[REDACTED_SENSITIVE_URL]&lang=en
Cookie: session=[REDACTED_COOKIE_HEADER]; theme=dark
环境要求:
安装依赖:
pnpm install
使用示例文件运行:
pnpm dev -- --file ./examples/sample.log
通过 stdin 管道输入:
pnpm dev -- < ./examples/sample.log
仓库内提供了可用于本地测试和演示的样例文件:
examples/sample.logexamples/sample.envexamples/sample.jsonexamples/sample.yamlexamples/mcp-redact.config.json所有样例值均为伪造数据。
pnpm dev -- < ./examples/sample.log
pnpm dev -- --file ./examples/sample.log
pnpm dev -- --file ./examples/sample.env
pnpm dev -- --file ./examples/sample.env --output ./sanitized.env
pnpm dev -- --file ./examples/sample.log --format json
示例输出:
{
"redactedText": "Authorization: Bearer [REDACTED_AUTHORIZATION_HEADER]\nuser_email=[REDACTED_EMAIL]\ncallback=https://example.com/callback?token=[REDACTED_SENSITIVE_URL]&lang=en\nCookie: session=[REDACTED_COOKIE_HEADER]; theme=dark\n",
"summary": {
"totalMatches": 4,
"byType": {
"authorization_header": 1,
"email": 1,
"sensitive_url": 1,
"cookie_header": 1
}
}
}
pnpm dev -- --file ./examples/sample.log --summary-only
示例输出:
Total matches: 4
By type:
- authorization_header: 1
- cookie_header: 1
- email: 1
- sensitive_url: 1
只启用 personal 规则:
pnpm dev -- --file ./examples/sample.log --only personal
运行时禁用某个规则组:
pnpm dev -- --file ./examples/sample.log --disable http
pnpm dev -- --file ./examples/sample.log --config ./examples/mcp-redact.config.json
示例配置只启用 personal 和 custom 组,禁用内置 email detector,并新增一条 internal-ticket 自定义规则。由于 sample.log 里没有匹配的 ticket 且 email 脱敏被关闭,因此这个示例下文件内容不会发生变化。
开发模式:
pnpm mcp:dev
构建后运行:
pnpm build
pnpm mcp:start
redact_text输入:
{
"text": "Authorization: Bearer abcdefghijklmnop123456",
"groups": ["http"],
"configPath": "./examples/mcp-redact.config.json"
}
redact_file输入:
{
"filePath": "./examples/sample.log",
"groups": ["http"],
"configPath": "./examples/mcp-redact.config.json"
}
两个工具都会返回同样的结构:
{
"redactedText": "...",
"summary": {
"totalMatches": 4,
"byType": {
"authorization_header": 1,
"email": 1
}
}
}
根据你的环境选择对应的 server 命令:
pnpm mcp:devpnpm mcp:start如果你的 MCP 客户端要求填写命令和参数,请指向本地项目并通过 stdio 启动服务。当前服务暴露两个工具:redact_text 和 redact_file。
默认配置文件名:
mcp-redact.config.json
如果没有显式传入配置路径,mcp-redact 会尝试从当前工作目录读取这个默认文件。若默认文件不存在,程序会继续正常执行;如果你显式传入了一个不存在的配置路径,则命令会报错。
示例配置:
{
"enabledGroups": ["personal", "custom"],
"disabledDetectors": ["email"],
"customRules": [
{
"name": "internal-ticket",
"pattern": "TICKET-[0-9]{6}",
"placeholder": "[REDACTED_TICKET]"
}
]
}
enabledGroups:限制只启用列出的内置或自定义规则组disabledDetectors:按名称禁用 detector,例如 email 或 github-tokencustomRules:添加本地正则规则,并复用与内置规则相同的处理流水线secretspassword=、token=、secret=、api_key= 这类键值形式 secretpersonalhttptoken=常用命令:
pnpm install
pnpm test
pnpm lint
pnpm typecheck
pnpm build
pnpm mcp:dev
Local-first CLI and MCP server for redacting sensitive text before sharing logs, configs, and errors with AI tools.
mcp-redact helps you do one thing before pasting text into Claude Code, Cursor, or other AI tools: redact secrets and sensitive data first.
Developers often paste logs, .env files, request headers, stack traces, and config snippets into AI tools. Those snippets can contain API keys, bearer tokens, cookies, emails, and other sensitive values.
mcp-redact is built to make that flow safer:
[REDACTED_EMAIL]Authorization: Bearer abcdefghijklmnop123456
[email protected]
callback=https://example.com/callback?token=secret123&lang=en
Cookie: session=abcdef123456; theme=dark
Authorization: Bearer [REDACTED_AUTHORIZATION_HEADER]
user_email=[REDACTED_EMAIL]
callback=https://example.com/callback?token=[REDACTED_SENSITIVE_URL]&lang=en
Cookie: session=[REDACTED_COOKIE_HEADER]; theme=dark
Requirements:
Install dependencies:
pnpm install
Run on a sample file:
pnpm dev -- --file ./examples/sample.log
Pipe text through stdin:
pnpm dev -- < ./examples/sample.log
This repository includes sample inputs you can use for local testing and demos:
examples/sample.logexamples/sample.envexamples/sample.jsonexamples/sample.yamlexamples/mcp-redact.config.jsonAll sample values are fake.
pnpm dev -- < ./examples/sample.log
pnpm dev -- --file ./examples/sample.log
pnpm dev -- --file ./examples/sample.env
pnpm dev -- --file ./examples/sample.env --output ./sanitized.env
pnpm dev -- --file ./examples/sample.log --format json
Example output:
{
"redactedText": "Authorization: Bearer [REDACTED_AUTHORIZATION_HEADER]\nuser_email=[REDACTED_EMAIL]\ncallback=https://example.com/callback?token=[REDACTED_SENSITIVE_URL]&lang=en\nCookie: session=[REDACTED_COOKIE_HEADER]; theme=dark\n",
"summary": {
"totalMatches": 4,
"byType": {
"authorization_header": 1,
"email": 1,
"sensitive_url": 1,
"cookie_header": 1
}
}
}
pnpm dev -- --file ./examples/sample.log --summary-only
Example output:
Total matches: 4
By type:
- authorization_header: 1
- cookie_header: 1
- email: 1
- sensitive_url: 1
Only run personal detectors:
pnpm dev -- --file ./examples/sample.log --only personal
Disable one group at runtime:
pnpm dev -- --file ./examples/sample.log --disable http
pnpm dev -- --file ./examples/sample.log --config ./examples/mcp-redact.config.json
The example config enables only personal and custom groups, disables the built-in email detector, and adds a custom internal-ticket rule. With that config, sample.log is left unchanged because it does not contain any custom ticket value and email redaction is disabled.
Development mode:
pnpm mcp:dev
Build and run:
pnpm build
pnpm mcp:start
redact_textInput:
{
"text": "Authorization: Bearer abcdefghijklmnop123456",
"groups": ["http"],
"configPath": "./examples/mcp-redact.config.json"
}
redact_fileInput:
{
"filePath": "./examples/sample.log",
"groups": ["http"],
"configPath": "./examples/mcp-redact.config.json"
}
Both tools return the same structured shape:
{
"redactedText": "...",
"summary": {
"totalMatches": 4,
"byType": {
"authorization_header": 1,
"email": 1
}
}
}
Use the server command that fits your environment:
pnpm mcp:devpnpm mcp:startIf your MCP client expects a command plus arguments, point it at the local project and run the server over stdio. The server exposes two tools: redact_text and redact_file.
Default config file name:
mcp-redact.config.json
If no explicit config path is provided, mcp-redact will try to read that file from the current working directory. If the default file is missing, execution continues normally. If you explicitly pass a missing config path, the command fails.
Example config:
{
"enabledGroups": ["personal", "custom"],
"disabledDetectors": ["email"],
"customRules": [
{
"name": "internal-ticket",
"pattern": "TICKET-[0-9]{6}",
"placeholder": "[REDACTED_TICKET]"
}
]
}
enabledGroups: restricts built-in and custom detectors to the listed groupsdisabledDetectors: disables detectors by name, such as email or github-tokencustomRules: adds local regex-based detectors that use the same pipeline as built-in rulessecretspassword=, token=, secret=, api_key=personalhttptoken=Common commands:
pnpm install
pnpm test
pnpm lint
pnpm typecheck
pnpm build
pnpm mcp:dev
Add this to claude_desktop_config.json and restart Claude Desktop.
{
"mcpServers": {
"mcp-redact": {
"command": "npx",
"args": []
}
}
}