MCP提示引擎
 ](https://github.com/vasayxtx/mcp-prompt-engine/releases)  
一个模型控制协议(MCP)服务器,用于使用优雅而强大的文本模板引擎管理和提供动态提示模板。 创建可重用的、逻辑驱动的提示,其中包含可以提供给任何人的变量、部分和条件 兼容MCP客户端 如Claude Code、Claude Desktop、Gemini CLI、带Copilot的VSCode等。
主要特点
- 强大的Go模板:充分利用围棋的力量 文本/模板 语法,包括变量、条件、循环等。
- 可重复使用的片段:在部分模板中定义通用组件(例如。,
_header.tmpl)并在提示中重复使用它们。 - 提示论点:所有模板变量都会自动作为MCP提示参数公开,允许客户端进行动态输入。
- 热重新加载:自动检测对提示文件的更改,并在不重新启动服务器的情况下重新加载它们。
- 丰富的CLI:一个现代的命令行界面,用于列出、验证和呈现模板,以便于开发和测试。
- 智能论点处理:
- 自动解析JSON参数(布尔值、数字、数组、对象)。 - 注入环境变量作为模板参数的回退。
- 容器化:完全支持Docker,便于部署和集成。
托管部署
托管部署可在 Frontier AI.
入门指南
1.安装
使用Go安装:
go install github.com/vasayxtx/mcp-prompt-engine@latest(有关Docker或预构建二进制文件等其他方法,请参阅 安装部分 在......下面)
2.创建提示
创建一个 prompts 目录并添加模板文件。让我们创建一个提示来帮助编写Git提交消息。
首先,创建一个名为 prompts/_git_commit_role.tmpl:
{{ 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:
: 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 使用此部分: \\\`走吧 {{-/\*提交当前阶段的更改\*/-}
{{- template "_git_commit_role" . -}}
Your task is to commit all currently staged changes.
To understand the context, analyze the staged code using the command: `git diff --staged`
Based on that analysis, commit staged changes using a suitable commit message.
### 3.验证您的提示
验证您的提示以确保它没有语法错误:
mcp-prompt-engine validate git_stage_commit ✓ git_stage_commit.tmpl - Valid
### 4.将MCP服务器连接到您的客户端
将MCP服务器添加到MCP客户端。看 [连接到客户](#connecting-to-clients) 用于配置示例。
### 5.使用您的提示
你的 `git_stage_commit` 提示现在将在您的客户端中可用!
例如,在Claude Desktop中,您可以选择 `git_stage_commit` 提示,提供 `type` MCP Prompt参数,并获取一个生成的提示,该提示将帮助您使用完美的消息进行提交。
在Claude Code或Gemini CLI中,您可以开始键入 `/git_stage_commit` 它将使用提供的参数来建议提示,这些参数将在您选择它后执行。
______________________________________________________________________
## 安装
### 预构建二进制文件
从以下网址下载适用于您操作系统的最新版本 .
### 从源代码构建
git clone https://github.com/vasayxtx/mcp-prompt-engine.git cd mcp-prompt-engine make build
### 码头工人
预构建的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`.
______________________________________________________________________
## 用法
### 创建提示模板
创建一个目录来存储提示模板。每个模板都应该是 `.tmpl` 使用Go的文件 [文本/模板](https://pkg.go.dev/text/template) 语法格式如下:
{{/* 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文本/模板文档](https://pkg.go.dev/text/template) 有关语法和功能的更多详细信息。
### JSON参数解析
服务器在可能的情况下会自动将参数值解析为JSON,从而在模板中启用丰富的数据类型:
- **布尔值**: `true`, `false` → Go布尔值
- **数字**: `42`, `3.14` → Go数值
- **数组**: `["item1", "item2"]` → Go切片与 `{{range}}`
- **对象**: `{"key": "value"}` → 结构化数据的Go映射
- **字符串**:无效的JSON回退到字符串值
这允许进行高级模板操作,例如:
{{range .items}}Item: {{.}}{{end}} {{if .enabled}}Feature is enabled{{end}} {{.config.timeout}} seconds
要禁用JSON解析并将所有参数视为字符串,请使用 `--disable-json-args` 旗帜为 `serve` 和 `render` 命令。
### 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 Prompts的任何客户端一起使用,请在其MCP服务器配置中添加一个新条目。
全局配置位置(MacOS):
- 克劳德代码: `~/.claude.json` (`mcpServers` 部分)
- 克劳德桌面: `~/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) 文件以获取详细信息。