mcp-promptdiff
Zero-dependency stdio MCP server for token-aware prompt version diffs. Compare prompts or files and get machine-readable token delta reports with confidence labels.
README
mcp-promptdiff
Zero-dependency stdio MCP server and CLI for token-aware prompt version diffs.
Compare two prompt strings or files and get a machine-readable token delta report — no external APIs, no native dependencies, runs anywhere.
Quick Start
pip install git+https://github.com/prasad-a-abhishek/mcp-promptdiff.git
from mcp_promptdiff import diff_prompts, estimate_tokens
# Token-aware diff between two prompts
report = diff_prompts(
"You are a helpful assistant.",
"You are a helpful, concise assistant.",
)
print(f"Token delta: {report.token_delta:+d}") # e.g. +4
print(f"Changed: {report.changed}") # True
# Estimate token count for any string
est = estimate_tokens("Hello 🤖 world")
print(f"Tokens: {est.token_count}") # e.g. 5
print(f"Confidence: {est.confidence.value}") # low (emoji)
Performance & Benchmarks
Token estimation is a fast heuristic (byte-length ÷ 4), making it suitable for CI pipelines and high-throughput MCP tooling without network latency or native dependencies.
| Operation | Latency | Notes |
|---|---|---|
estimate_tokens (1 KB ASCII) |
< 1 ms | Pure Python, no I/O |
diff_prompts (1 KB each) |
< 2 ms | Section-level breakdown included |
| MCP server round-trip | < 5 ms | stdio, no network |
Local benchmark reproduction:
python3 benchmarks/run_benchmark.py
Why mcp-promptdiff?
The problem: LLM application developers version-control prompts but get no token-level signal from git diff. You can't answer "how many tokens were added?" or "which section grew most?" from a character-level diff.
Existing tools are too heavy: tiktoken and tokenizers require native data files and per-model downloads. Git diff has no concept of token boundaries. The MCP ecosystem had no dedicated prompt diff tool.
mcp-promptdiff is the minimal building block: Zero dependencies, pure stdlib, runs in any Python 3.11+ environment. Estimates are clearly labeled approximate with confidence/method fields so callers decide how much to trust them.
Key Features
- Zero dependencies — pure Python stdlib, no pip installs beyond the package itself
- Both CLI and library API — use in CI, code review, or embedded MCP tooling
- MCP stdio server — drop into any MCP client (Claude Desktop, Cursor, etc.)
- Batch diff — compare many prompt pairs in one call
- Encoding presets —
cl100k_approx,o200k_base,p50k_base - Confidence labels — every estimate reports LOW/MEDIUM/HIGH confidence so clients can decide trust level
API Reference
estimate_tokens(text, encoding="cl100k_approx")
Returns a TokenEstimate:
@dataclass(frozen=True)
class TokenEstimate:
text: str
token_count: int # estimated token count
confidence: Confidence # HIGH | MEDIUM | LOW
method: str # e.g. "cl100k_approx_byte_ratio"
encoding: str # the encoding used
diff_prompts(prompt_a, prompt_b, encoding="cl100k_approx")
Returns a TokenReport:
@dataclass(frozen=True)
class TokenReport:
token_delta: int # tokens added (negative = removed)
token_count_a: int
token_count_b: int
section_deltas: List[SectionDelta] # per-paragraph breakdown
changed: bool # True if content differs
encoding: str
method: str
estimated_cost_a: float # USD at ~$0.01/1k tokens
estimated_cost_b: float # USD at ~$0.01/1k tokens
diff_files(path_a, path_b, encoding="cl100k_approx")
Same shape as diff_prompts, loaded from disk paths.
batch_diff(pairs, encoding="cl100k_approx")
Takes a list of PromptPair(prompt_a, prompt_b, label=None) and returns a list of TokenReport.
MCP Server
# Run as stdio MCP server (stays alive on stdin/stdout)
from mcp_promptdiff.mcp_server import run
run()
Tools exposed: diff_prompts, diff_files, estimate_tokens, batch_diff
CLI Reference
mcp-promptdiff diff --a "original" --b "revised"
mcp-promptdiff diff --file-a prompt_v1.md --file-b prompt_v2.md
mcp-promptdiff diff --file-a a.md --file-b b.md --format json
mcp-promptdiff estimate --text "Hello world"
mcp-promptdiff estimate --text "Hello 🤖" --encoding o200k_base
| Flag | Description |
|---|---|
--a, --b |
Prompt strings to diff |
--file-a, --file-b |
Paths to prompt files |
--encoding |
cl100k_approx (default), o200k_base, p50k_base |
--format |
text (default) or json |
--text |
Text string to estimate |
Limitations
- Estimates, not exact counts. This is a byte-length heuristic (byte_length ÷ 4), not exact tokenization. Every result includes a
confidencefield so callers can decide how much to trust it. - No multi-turn conversation diffs. Compares two flat prompt strings or two files only.
- No HTTP/SSE transport. stdio JSON-RPC only — the MCP server reads stdin and writes stdout.
- No prompt optimization or templating. This is a diff tool, not a prompt engineering tool.
Non-Goals
- Exact tokenizer parity with any specific provider (OpenAI, Anthropic, etc.)
- Calling any hosted LLM API for evaluation
- Prompt optimization, variable substitution, or templating
- Persistent state or history
- HTTP/SSE transport
License
MIT License — Abhishek Prasad
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。