製品

MCP クライアント連携

PromptFlowEngine は Model Context Protocol に対応しているため、任意の MCP クライアント(GitHub Copilot のエージェントモード、Claude Desktop、Claude Code、Cursor、独自のエージェント)からエンジンをツールとして呼び出せます。アシスタントは、人が手作業で行う代わりに、プロンプトのチェック、再構成、sanitize を自分の作業の一ステップとして実行できます。

用語について:インストールするものは 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 キー、アカウント、トークンはありません。アクセスはお使いの OS が管理します。サーバーと標準入出力でやり取りできるのは、自分で起動したプロセスだけだからです。ホスト型や HTTP の MCP エンドポイントはありません。リモートで使う場合は、代わりに HTTP API を呼び出してください。

設定

PromptFlowEngine リポジトリのチェックアウトからビルド(npm での公開は準備中)し、クライアントから dist/bin.js を指定します。

shell
pnpm --filter @promptflow/engine build && pnpm --filter @promptflow/mcp-server build
VS 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_CHARS100000テキスト引数 1 つあたりの最大文字数(上限は 2,000,000)。
PROMPTFLOW_MCP_LOG未設定debug を指定すると、ツール名、入力サイズ、結果、所要時間を stderr に出力します。内容は決して出力しません。

機能:ツール(19)

ツール説明
optimize_promptOptimize 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_pipelineRun 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_promptRemove exact duplicate sentences and extra whitespace without rewriting any wording.
validate_promptCheck 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_tokensCount 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_promptDetect intent, task type, technical domain, requested output, requirements, and entities (languages, frameworks, file paths, identifiers).
extract_entitiesExtract languages, frameworks, libraries, cloud platforms, services, technologies, file paths, identifiers, URLs, and commands.
summarize_contextExtractive summary: the first N unique, non-empty sentences of a context block, in order. Does not rank or rewrite.
score_promptScore 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_promptFull 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_promptsCompare two prompts: token and estimated cost delta, quality delta per dimension, and which findings were resolved or introduced.
scan_prompt_securityPrompt-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_dataScan text for credentials, cloud secrets, and PII with local deterministic detectors. Returns offsets and per-category counts, never the sensitive values.
sanitize_promptReplace 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_promptTurn 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_payloadConvert 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_costSimulate 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_budgetMeasure 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_testsRun 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.

すべてのツールに、読み取り専用かつ冪等であるというアノテーションが付いています。最初の 11 個は 1.5.x 拡張機能と同じ結果フィールドを維持しているため、既存のエージェント設定はそのまま動作します。

リソースとプロンプト

  • promptflow://rules:ルールカタログ、評価軸、スコアリングのペナルティ。
  • promptflow://models:モデル、トークンのエンコーディング、参考価格。
  • プロンプト 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

エラーとセキュリティ

  • 引数はスキーマで検証されます。不正または大きすぎる引数は、プロトコルエラーではなく理由付きのツールエラー(isError)を返すため、エージェントは修正して再試行できます。
  • どのツールも、検出した秘密の値を返しません。機密データの結果にはカテゴリと位置だけが含まれます。
  • ツールに渡されたプロンプトのテキストはデータとして扱われます。サーバーが実行することはなく、review-prompt テンプレートはモデルに渡すときにタグで囲みます。
  • サーバーにはファイル、シェル、ネットワークのツールがないため、プロンプトインジェクションを受けたエージェントでも、これを使ってどこかに到達することはできません。