Skip to main content
Glama
vasayxtx

mcp-prompt-engine

by vasayxtx

MCP Prompt Engine

Go Report Card GitHub release (latest by date) License: MIT Go.Dev reference

洗練された強力なテキストテンプレートエンジンを使用して、動的なプロンプトテンプレートを管理・提供するためのModel Control Protocol (MCP) サーバーです。 変数、パーシャル、条件分岐を備えた再利用可能でロジック駆動型のプロンプトを作成し、Claude Code、Claude Desktop、Gemini CLI、Copilot搭載のVSCodeなど、互換性のあるMCPクライアントに提供できます。

主な機能

  • MCP互換: プロンプトをサポートするあらゆるMCPクライアントでそのまま動作します。

  • 強力なGoテンプレート: 変数、条件分岐、ループなど、Goのtext/template構文の全機能を活用できます。

  • 再利用可能なパーシャル: 共通コンポーネントをパーシャルテンプレート(例: _header.tmpl)として定義し、プロンプト間で再利用できます。

  • プロンプト引数: すべてのテンプレート変数は自動的にMCPプロンプト引数として公開され、クライアントからの動的な入力を可能にします。

  • ホットリロード: プロンプトファイルの変更を自動的に検出し、サーバーを再起動することなくリロードします。

  • リッチなCLI: テンプレートのリスト表示、検証、レンダリングを行うモダンなコマンドラインインターフェースにより、開発とテストが容易になります。

  • スマートな引数処理:

    • JSON引数(ブール値、数値、配列、オブジェクト)を自動的に解析します。

    • 環境変数をテンプレート引数のフォールバックとして注入します。

  • コンテナ化: Dockerを完全にサポートしており、デプロイと統合が容易です。

Related MCP server: MCP-YNU FastMCP Server

ホスト型デプロイ

Fronteir AIにてホスト型デプロイが利用可能です。

はじめに

1. インストール

Goを使用してインストールします:

go install github.com/vasayxtx/mcp-prompt-engine@latest

(Dockerやビルド済みバイナリなどの他の方法については、以下のインストールセクションを参照してください。)

2. プロンプトの作成

promptsディレクトリを作成し、テンプレートファイルを追加します。Gitコミットメッセージの作成を支援するプロンプトを作成してみましょう。

まず、prompts/_git_commit_role.tmplという名前の再利用可能なパーシャルを作成します:

```go
{{ define "_git_commit_role" }}
You are an expert programmer specializing in writing clear, concise, and conventional Git commit messages.
Commit message must strictly follow the Conventional Commits specification.

The final commit message you generate must be formatted exactly as follows:

```
<type>: A brief, imperative-tense summary of changes

[Optional longer description, explaining the "why" of the change. Use dash points for clarity.]
```
{{ if .type -}}
Use {{.type}} as a type.
{{ end }}
{{ end }}
```

次に、このパーシャルを使用するメインプロンプト prompts/git_stage_commit.tmpl を作成します:

{{- /* 現在ステージングされている変更をコミット */ -}}

GXP3

3. プロンプトの検証

プロンプトを検証して、構文エラーがないことを確認します:

mcp-prompt-engine validate git_stage_commit
✓ git_stage_commit.tmpl - Valid

4. MCPサーバーをクライアントに接続

MCPサーバーをMCPクライアントに追加します。設定例についてはクライアントへの接続を参照してください。

5. プロンプトの使用

git_stage_commit プロンプトがクライアントで利用可能になります!

例えば、Claude Desktopでは git_stage_commit プロンプトを選択し、type MCPプロンプト引数を指定することで、完璧なメッセージでコミットを行うための生成されたプロンプトを取得できます。

Claude CodeやGemini CLIでは、/git_stage_commit と入力し始めると、選択後に実行される引数付きのプロンプトが提案されます。


インストール

ビルド済みバイナリ

GitHub Releasesページから、お使いのOS用の最新リリースをダウンロードしてください。

ソースからのビルド

git clone https://github.com/vasayxtx/mcp-prompt-engine.git
cd mcp-prompt-engine
make build

Docker

ビルド済みのDockerイメージが利用可能です。ローカルの prompts および logs ディレクトリをコンテナにマウントしてください。

# Pull and run the pre-built image from GHCR
docker run -i --rm \
  -v /path/to/your/prompts:/app/prompts:ro \
  -v /path/to/your/logs:/app/logs \
  ghcr.io/vasayxtx/mcp-prompt-engine

make docker-build を使用してローカルでイメージをビルドすることも可能です。


使用方法

プロンプトテンプレートの作成

プロンプトテンプレートを保存するディレクトリを作成します。各テンプレートは、Goのtext/template構文を使用した .tmpl ファイルである必要があり、以下の形式に従います:

{{/* Brief description of the prompt */}}
Your prompt text here with {{.template_variable}} placeholders.

最初の行のコメント ({{/* description */}}) はプロンプトの説明として使用され、ファイルの残りの部分はプロンプトテンプレートとなります。

パーシャルテンプレートにはアンダースコアのプレフィックス(例: _header.tmpl)を付け、{{template "partial_name" .}} を使用して他のテンプレートに含めることができます。

テンプレート構文

サーバーはGoの text/template エンジンを使用しており、強力なテンプレート機能を提供します:

  • 変数: {{.variable_name}} - テンプレート変数へのアクセス

  • 組み込み変数:

    • {{.date}} - 現在の日時

  • 条件分岐: {{if .condition}}...{{end}}, {{if .condition}}...{{else}}...{{end}}

  • 論理演算子: {{if and .condition1 .condition2}}...{{end}}, {{if or .condition1 .condition2}}...{{end}}

  • ループ: {{range .items}}...{{end}}

  • テンプレートのインクルード: {{template "partial_name" .}} または {{template "partial_name" dict "key" "value"}}

構文と機能の詳細については、Go text/templateのドキュメントを参照してください。

JSON引数の解析

サーバーは可能な限り引数の値をJSONとして自動的に解析し、テンプレート内でリッチなデータ型を扱えるようにします:

  • ブール値: true, false → Goのブール値

  • 数値: 42, 3.14 → Goの数値

  • 配列: ["item1", "item2"]{{range}} で使用するためのGoのスライス

  • オブジェクト: {"key": "value"} → 構造化データ用のGoのマップ

  • 文字列: 無効なJSONは文字列値として扱われます

これにより、以下のような高度なテンプレート操作が可能になります:

{{range .items}}Item: {{.}}{{end}}
{{if .enabled}}Feature is enabled{{end}}
{{.config.timeout}} seconds

JSON解析を無効にしてすべての引数を文字列として扱うには、serve および render コマンドで --disable-json-args フラグを使用してください。

CLIコマンド

CLIはテンプレートを管理・テストするための主要なツールです。 デフォルトでは ./prompts ディレクトリ内のテンプレートを探しますが、--prompts フラグを使用して別のディレクトリを指定することもできます。

1. テンプレートのリスト表示

# See a simple list of available prompts
mcp-prompt-engine list

# See a detailed view with descriptions and variables
mcp-prompt-engine list --verbose

2. テンプレートのレンダリング

-a または --arg フラグで引数を指定し、ターミナルで直接プロンプトをレンダリングします。 不足している引数に対しては、環境変数が自動的にフォールバックとして注入されます。例えば、環境変数 TYPE=fix がある場合、テンプレートには {{.type}} として注入されます。

# Render the git commit prompt, providing the 'type' variable
mcp-prompt-engine render git_stage_commit --arg type=feat

3. テンプレートの検証

すべてのテンプレートの構文エラーをチェックします。テンプレートが無効な場合、コマンドはエラーを返します。

# Validate all templates in the directory
mcp-prompt-engine validate

# Validate a single template
mcp-prompt-engine validate git_stage_commit

4. サーバーの起動

MCPサーバーを実行し、プロンプトをクライアントから利用可能にします。

# Run with default settings (looks for ./prompts)
mcp-prompt-engine serve

# Specify a different prompts directory and a log file
mcp-prompt-engine --prompts /path/to/prompts serve --log-file ./server.log

クライアントへの接続

MCPプロンプトをサポートするクライアントでこのエンジンを使用するには、MCPサーバー設定に新しいエントリを追加します。

グローバル設定の場所(MacOS):

  • Claude Code: ~/.claude.json (mcpServers セクション)

  • Claude Desktop: ~/Library/Application\ Support/Claude/claude_desktop_config.json (mcpServers セクション)

  • Gemini CLI: ~/.gemini/settings.json (mcpServers セクション)

ローカルバイナリの例:

{
  "prompts": {
    "command": "/path/to/your/mcp-prompt-engine",
    "args": [
      "--prompts", "/path/to/your/prompts",
      "serve",
      "--quiet"
    ]
  }
}

Dockerの例:

{
  "mcp-prompt-engine-docker": {
    "command": "docker",
    "args": [
      "run", "-i", "--rm",
      "-v", "/path/to/your/prompts:/app/prompts:ro",
      "-v", "/path/to/your/logs:/app/logs",
      "ghcr.io/vasayxtx/mcp-prompt-engine"
    ]
  }
}

ライセンス

このプロジェクトはMITライセンスの下でライセンスされています。詳細は LICENSE ファイルを参照してください。

-
security - not tested
A
license - permissive license
-
quality - not tested

Resources

Unclaimed servers have limited discoverability.

Looking for Admin?

If you are the server author, to access and configure the admin panel.

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/vasayxtx/mcp-prompt-engine'

If you have feedback or need assistance with the MCP directory API, please join our Discord server