产品
MCP 客户端集成
PromptFlowEngine 支持 Model Context Protocol,因此任何 MCP 客户端(GitHub Copilot 智能体模式、Claude Desktop、Claude Code、Cursor 或你自己的智能体)都可以把引擎当作工具调用。这样,你的助手就能把检查、重构和脱敏提示词当作自己工作中的一个步骤,而不用你手动去做。
关于术语:你要安装的是一个 MCP 服务器(
@promptflow/mcp-server v2.1.0,服务器名称 promptflow-engine)。连接它的 AI 工具是 MCP 客户端。Claude Code、Windsurf 和 Gemini CLI 的设置、TypeScript 客户端示例和故障排查:连接 PromptFlowEngine。
连接方式
连接
MCP client (Copilot, Claude, Cursor, your agent)
│ spawns a local process and talks JSON-RPC over stdio
▼
promptflow-mcp (node packages/mcp-server/dist/bin.js)
│ validates arguments, runs the engine in-process
▼
@promptflow/engine no network, no model calls, no files read传输方式仅限 stdio。服务器作为客户端的子进程运行在你的电脑上,只读取收到的参数,不发起任何网络调用。
身份验证
既不需要,也不支持:没有 API 密钥、账号或 token。访问由你的操作系统控制,因为只有你启动的进程才能通过标准输入输出与服务器通信。没有托管的或 HTTP 的 MCP 端点;如需远程使用,请改为调用 HTTP API。
配置
从 PromptFlowEngine 仓库的检出代码构建(npm 发布尚在进行中),然后让客户端指向 dist/bin.js:
shell
pnpm --filter @promptflow/engine build && pnpm --filter @promptflow/mcp-server buildVS Code / Copilot: .vscode/mcp.json
{
"servers": {
"promptflow": {
"type": "stdio",
"command": "node",
"args": ["/absolute/path/to/checkout/packages/mcp-server/dist/bin.js"]
}
}
}Claude Desktop、Cursor 和其他客户端
{
"mcpServers": {
"promptflow": { "command": "node", "args": ["/absolute/path/to/checkout/packages/mcp-server/dist/bin.js"] }
}
}VS Code 扩展内置了同一个服务器,并会为你写入第一条配置。
| 环境变量 | 默认值 | 用途 |
|---|---|---|
PROMPTFLOW_MCP_MAX_PROMPT_CHARS | 100000 | 每个文本参数的最大字符数(硬上限 2,000,000)。 |
PROMPTFLOW_MCP_LOG | 未设置 | debug 会把工具名称、输入大小、结果和耗时记录到 stderr。从不记录内容。 |
功能:工具(19)
| 工具 | 说明 |
|---|---|
optimize_prompt | Optimize a prompt with deterministic, verified transforms (duplicates, filler, optional sections). Every candidate is checked to preserve all sentences, requirements, code, and variables; the original is kept if nothing is better. Returns the selected prompt, token savings, quality score, and what changed. |
optimize_prompt_pipeline | Run the optimization pipeline and return per-stage results plus token and estimated cost metrics, in the result shape used by the PromptFlow VS Code extension. |
compress_prompt | Remove exact duplicate sentences and extra whitespace without rewriting any wording. |
validate_prompt | Check a prompt for missing objective or output format, ambiguity, conflicting instructions, duplicates, prompt-injection patterns, secrets, and undelimited variables. isValid is false only when a critical issue exists. |
estimate_tokens | Count tokens and estimate input cost for a model. "exact" is true only for OpenAI models with a loaded tokenizer; other providers are approximate. Costs are estimates from a reference price table. |
analyze_prompt | Detect intent, task type, technical domain, requested output, requirements, and entities (languages, frameworks, file paths, identifiers). |
extract_entities | Extract languages, frameworks, libraries, cloud platforms, services, technologies, file paths, identifiers, URLs, and commands. |
summarize_context | Extractive summary: the first N unique, non-empty sentences of a context block, in order. Does not rank or rewrite. |
score_prompt | Score prompt quality 0-100: 100 minus a penalty per issue (critical 30, warning 10, info 3; capped at 50 with any critical issue), with per-dimension scores and suggestions. |
evaluate_prompt | Full quality report: overall score, grade, eight quality dimensions with the checks that failed, and every finding with why it matters and how to fix it. |
compare_prompts | Compare two prompts: token and estimated cost delta, quality delta per dimension, and which findings were resolved or introduced. |
scan_prompt_security | Prompt-injection risk (0-100, signature-based, with threat ids), sensitive-data counts by category, undelimited template variables, and destructive operations. Never returns detected secret values. |
scan_sensitive_data | Scan text for credentials, cloud secrets, and PII with local deterministic detectors. Returns offsets and per-category counts, never the sensitive values. |
sanitize_prompt | Replace detected sensitive data with placeholders such as [REDACTED_API_KEY]. Returns the sanitized text and counts, never the original values. Use before sending a prompt to an external model. |
restructure_prompt | Turn a loosely written request into a sectioned engineering prompt: Role, Objective, Context, Requirements, Constraints, Edge cases, Testing, Acceptance criteria, Expected output. Only sections with content appear. The author's clauses are kept and reordered; for software tasks, fixed engineering guidance chosen by intent and topic is added, and every line is labeled "prompt" or "engine" so additions can be reviewed. Set scaffold=false to reorganize without adding guidance. |
convert_structured_payload | Convert a JSON payload to TOON (Token-Oriented Object Notation) and say whether to use it. Returns token counts for pretty JSON, compact JSON and TOON, a round-trip check (the TOON must decode back to the same value), and the recommendation: "toon" only when it round-trips and saves at least 5 % over compact JSON, otherwise "json". Lossless or it keeps JSON. |
simulate_cost | Simulate what a prompt costs across models at a request volume, from catalog list prices (labelled simulated, never a bill). Optionally optimizes the prompt first and reports hypothetical savings. Flags models whose context window is too small. |
analyze_context_budget | Measure the context sources you intend to send with a prompt: tokens and share per source, context-window usage with an output reserve, sensitive data (categories and counts only), instruction-like text in retrieved sources, and duplicates. Reads only the text passed in; never reads files. |
run_prompt_tests | Run a regression suite against a prompt. Assertions check the prompt (contains, not_contains, matches, max_tokens, min_quality, no_finding, max_severity, has_variables, max_injection_risk, no_sensitive_data, output_format) and, when a case carries a recorded model response, the response (response_valid_json, response_has_keys, response_contains, response_max_chars). With baseline_prompt, also runs the suite on the baseline and lists cases that regressed. No model is called. |
所有工具都标注为只读且幂等。前十一个保持了它们在 1.5.x 扩展中的结果字段,因此现有的智能体配置仍然可用。
资源与提示词
promptflow://rules:规则目录、维度和评分扣分。promptflow://models:模型、token 编码和参考价格。- 提示词
review-prompt:请助手评估并优化一个提示词,该提示词作为数据被包裹在标签中。
示例
在与智能体的聊天中,用自然语言提出要求,客户端会选择工具:
你
Use promptflow to restructure this before you start:
"fix login issue and make google login work and don't break anything"客户端发送的 tools/call
{
"name": "restructure_prompt",
"arguments": { "prompt": "fix login issue and make google login work and don't break anything" }
}结果(节选)
{
"restructuredPrompt": "## Role\nAct as a senior software engineer.\n\n## Objective\nFix login issue and make Google login work.\n…",
"intent": "debugging",
"topics": ["authentication"],
"counts": { "prompt": 4, "engine": 20, "codebase": 0 }
}如需在没有客户端的情况下试用,可以用管道把 JSON-RPC 发给该进程:
shell
printf '%s\n' \
'{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"2025-06-18","capabilities":{},"clientInfo":{"name":"cli","version":"1"}}}' \
'{"jsonrpc":"2.0","method":"notifications/initialized"}' \
'{"jsonrpc":"2.0","id":2,"method":"tools/call","params":{"name":"estimate_tokens","arguments":{"prompt":"Hello, world!","model":"gpt-4o"}}}' \
| node packages/mcp-server/dist/bin.js错误与安全
- 参数通过 schema 验证。错误或过大的参数会返回带原因的工具错误(
isError),而不是协议错误,这样智能体可以纠正后重试。 - 没有任何工具会返回检测到的密钥值:敏感数据的结果只包含类别和位置。
- 传给工具的提示词文本被视为数据。服务器从不执行它,
review-prompt模板会把它包裹在标签中再交给模型。 - 服务器没有文件、shell 或网络工具,因此遭到提示词注入的智能体无法借它访问任何东西。