truepng-mcp

truepng-mcp

Recovers genuine transparency from images with painted checkerboard backgrounds, outputting RGBA PNGs with proper alpha channels. Supports CLI and MCP stdio server for macOS.

Category
访问服务器

README

truepng-mcp

Turn painted transparency checkerboards into real PNG alpha.

truepng-mcp is built for images that look transparent because they contain a gray-and-white PNG checkerboard, but are actually flat RGB images with no usable alpha channel. It detects the painted checker pattern, reconstructs foreground edges, recovers enclosed transparent holes, and writes a genuine RGBA PNG.

This is not a general image-format converter. The primary job is to recover real transparency from fake checkerboard backgrounds embedded in PNG, JPEG, or WebP image pixels.

The input may already have a .png extension and still be fake: PNG is a file format, not proof that transparency exists. A flattened PNG often has mode RGB and the checkerboard is ordinary visible pixel data. The output from truepng has mode RGBA and a verified, used alpha channel.

It provides an on-demand CLI and a standard MCP stdio server for macOS. It never installs a daemon, HTTP server, login item, or background service.

Synthetic checkerboard recovery comparison

Why this exists

Image previews, generated assets, screenshots, and some download sites may flatten an originally transparent asset onto a visible checkerboard before saving it. A conventional background remover treats this as a generic segmentation problem and may damage colors, pixel-art edges, white foreground details, or holes inside map pins and rings.

truepng treats the checkerboard as a known compositing pattern. It detects the grid period, colors, origin, and parity, then reconstructs transparency against the expected checker color. Enclosed regions are classified with parity coverage, size, density, robust border error, and periodic fit so genuine holes become transparent while white foreground remains intact.

The design is derived from the MIT-licensed image_tools_mcp v1.3.0 checker reconstruction. See UPSTREAM.md.

Features

  • Deterministic fake-checkerboard detection and removal
  • Genuine RGBA PNG output from flattened RGB checkerboard images
  • Hole-aware recovery for rings, map pins, frames, and glyph counters
  • White and light foreground preservation
  • Existing-alpha sanitization with hidden RGB cleanup
  • Optional BiRefNet and rembg fallback for non-checker images
  • CLI and MCP stdio server in one command
  • Absolute output paths and structured JSON results
  • Atomic PNG writes, safe overwrite behavior, and output validation
  • No resident process, daemon, HTTP server, Docker container, or CUDA dependency

Requirements

  • macOS on Apple Silicon
  • Python 3.11, 3.12, or 3.13
  • uv
  • Internet access only during installation and the first use of an AI model

Install

Clone the repository, then install the lightweight checker, sanitize, CLI, and MCP routes:

git clone https://github.com/gkhntpbs/truepng-mcp.git
cd truepng-mcp
./install.sh

Installation with the optional AI fallback:

TRUEPNG_INSTALL_AI=1 ./install.sh

The executable is installed at ~/.local/bin/truepng, support files at ~/.local/share/truepng-mcp, and models at ~/.cache/truepng-mcp. Models download only on their first AI use. No CUDA packages are installed and the system Python environment is not modified.

Add to an MCP client

After running ./install.sh, add the installed stdio server globally with one command.

Codex

codex mcp add true-png -- "$HOME/.local/bin/truepng" mcp

Confirm the entry:

codex mcp get true-png

Claude Code

claude mcp add --scope user --transport stdio true-png -- "$HOME/.local/bin/truepng" mcp

Confirm the entry:

claude mcp get true-png

Restart an already-open client session if the tools do not appear immediately.

CLI

truepng input.png
truepng input.jpg -o output.png
truepng convert input.webp --output output.png
truepng input.png --mode checker
truepng input.png --mode ai --model isnet-anime
truepng input.png --mode sanitize
truepng inspect output.png --json
truepng verify output.png --json
truepng doctor

auto preserves and sanitizes used alpha, otherwise tries deterministic checker recovery, and only then starts the isolated AI worker. The AI model is imported in a short-lived child process with compute thread counts fixed to one. Checker and sanitize calls never import ONNX or load a model.

Existing output files are not overwritten by default. A safe numbered name is selected. Use --force for explicit overwrite. Reported paths are absolute.

MCP

The main tool is image_to_true_png with input_path, optional output_path, mode, model, overwrite, and return_preview. return_preview is accepted for schema compatibility but the full image is never embedded in the response. The result includes an absolute path and file URI. Additional tools are inspect_image_transparency and verify_true_png.

Codex ~/.codex/config.toml:

[mcp_servers.true-png]
command = "/Users/ACTUAL_USER/.local/bin/truepng"
args = ["mcp"]

Claude Code:

claude mcp add --scope user --transport stdio true-png -- /Users/ACTUAL_USER/.local/bin/truepng mcp

Claude Desktop, Cursor, and generic MCP clients:

{
  "mcpServers": {
    "true-png": {
      "command": "/Users/ACTUAL_USER/.local/bin/truepng",
      "args": ["mcp"]
    }
  }
}

MCP tools

image_to_true_png:

{
  "input_path": "/absolute/path/input.png",
  "output_path": "/absolute/path/output.png",
  "mode": "auto",
  "model": "birefnet-general",
  "overwrite": false,
  "return_preview": false
}

The server also exposes inspect_image_transparency and verify_true_png.

Processing modes

Mode Behavior Model loaded
auto Preserve used alpha, recover fake checkerboard, otherwise use optional AI fallback Only if needed
checker Require deterministic checkerboard recovery No
sanitize Preserve alpha and clear hidden RGB No
ai Force background-removal fallback Yes

The default AI model is birefnet-general. birefnet-general-lite, isnet-anime, and other safe rembg model identifiers can be selected with --model.

The AI route is a fallback for inputs that are not fake-checkerboard images. It is not the defining feature of this project. Checker recovery remains deterministic, lighter, and better suited to the core use case.

Resource usage

Checker recovery uses compact byte masks and float arrays instead of full-size Python object grids. It does not import rembg, NumPy, or ONNX. AI inference runs in a short-lived child process, restricts compute libraries to one thread, and is stopped if it exceeds the configurable RSS limit.

TRUEPNG_MAX_AI_RSS_MB=3072 truepng photo.jpg --mode ai

The default AI RSS limit is 4096 MB.

Maintenance

git pull --ff-only
./update.sh
./uninstall.sh

The uninstaller intentionally retains downloaded models. Remove ~/.cache/truepng-mcp manually if they are no longer needed.

Troubleshooting

If truepng is not found, add this to your shell configuration:

export PATH="$HOME/.local/bin:$PATH"

If auto mode reaches AI fallback and reports that rembg is missing, rerun TRUEPNG_INSTALL_AI=1 ./install.sh. If memory pressure matters more than segmentation, use --mode checker or --mode sanitize; these deterministic paths have no model runtime.

Development

uv sync --extra test
uv run pytest -q
uv build

See TESTING.md, ARCHITECTURE.md, and CONTRIBUTING.md.

Releases

Version tags create GitHub Releases automatically:

git tag -a v1.0.0 -m "truepng-mcp v1.0.0"
git push origin v1.0.0

The release workflow runs the test suite, builds the package, and attaches:

  • truepng_mcp-1.0.0-py3-none-any.whl
  • truepng_mcp-1.0.0.tar.gz
  • GitHub-generated source code archives in ZIP and TAR.GZ formats

Security

Path values are normalized and never interpolated into shell commands. Same-file writes and symlink outputs are rejected. See SECURITY.md for vulnerability reporting.

License

MIT. See LICENSE and UPSTREAM.md.

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选