提示模板MCP服务器
用于管理具有动态变量替换的提示模板的模型上下文协议(MCP)服务器。此服务器提供用于保存、更新、检索和管理可重用提示模板的工具,并具有自动变量提取功能。
特性
- 动态变量提取:自动检测
{variable}模板中的占位符 - MCP工具:可通过MCP客户端访问的全套模板管理工具
- REST API:用于与外部应用程序集成的HTTP端点
- 永久存储:使用Cloudflare D1数据库进行可靠存储
- 变量替换:使用提供的输入值渲染模板
MCP工具
服务器公开了以下MCP工具:
save_prompt_template-使用自动输入提取保存新模板update_prompt_template-修改现有模板delete_prompt_template-删除模板list_prompt_templates-查看所有已保存的模板get_prompt_by_name-使用输入值检索和渲染模板
示例用法
// Save a template
await save_prompt_template({
name: "greeting",
template: "Hello my name is {firstName} {lastName}. What is my name?"
});
// Automatically extracts: firstName, lastName as required inputs
// Use the template
await get_prompt_by_name({
name: "greeting",
inputs: {
firstName: "John",
lastName: "Doe"
}
});
// Returns: "Hello my name is John Doe. What is my name?"REST API端点
GET /prompts-列出所有模板GET /prompts/:name-获取特定模板POST /prompts-创建新模板PUT /prompts/:name-更新模板DELETE /prompts/:name-删除模板
入门指南
该项目使用HONC堆栈(Hono+CCloudflare)和D1数据库进行存储。
项目结构
├── src
│ ├── index.ts # MCP server & API endpoints
│ └── db
│ └── schema.ts # Database schema for prompt templates
├── wrangler.toml # Cloudflare Workers configuration
├── drizzle.config.ts # Drizzle ORM configuration
├── package.json
└── tsconfig.json地方发展
运行迁移并(可选)为数据库设置种子:
# this is a convenience script that runs db:touch, db:generate, db:migrate, and db:seed
npm run db:setup运行开发服务器:
npm run dev当你迭代数据库模式时,你需要生成一个新的迁移文件,并按如下方式应用它:
npm run db:generate
npm run db:migrate部署
在将您的worker部署到Cloudflare之前,请确保您在Cloudflare上有一个正在运行的D1实例来连接您的workers。
您可以通过导航到以下位置来创建D1实例 Workers & Pages 部分和选择 D1 SQL Database.
或者,您可以使用CLI创建D1实例:
npx wrangler d1 create 创建数据库后,更新 wrangler.toml 带有数据库id的文件。
[[d1_databases]]
binding = "DB"
database_name = "honc-d1-database"
database_id = ""
migrations_dir = "drizzle/migrations"将以下信息纳入 .prod.vars 文件:
CLOUDFLARE_D1_TOKEN="" # An API token with D1 edit permissions. You can create API tokens from your Cloudflare profile
CLOUDFLARE_ACCOUNT_ID="" # Find your Account id on the Workers & Pages overview (upper right)
CLOUDFLARE_DATABASE_ID="" # Find the database ID under workers & pages under D1 SQL Database and by selecting the created database如果您尚未生成最新的迁移文件,请运行:
npm run db:generate之后,运行生产迁移脚本:
npm run db:migrate:prod在中更改项目的名称 wrangler.toml 选择适合您项目的内容:
name = "prompt-templates-mcp"最后,部署你的worker:
npm run deploy数据库模式
服务器使用一个简单的模式来存储提示模板:
promptTemplates {
id: integer (primary key)
name: text (unique)
template: text
inputs: text (JSON array of required variables)
createdAt: text
updatedAt: text
}在Claude Desktop中设置MCP服务器
部署服务器后,请按照以下步骤将其连接到Claude Desktop:
- 打开Claude桌面配置
- 在 macOS 上: ~/Library/Application Support/Claude/claude_desktop_config.json - 在Windows上: %APPDATA%\Claude\claude_desktop_config.json
- 将您的MCP服务器添加到配置文件中:
{
"mcpServers": {
"prompt-templates": {
"command": "npx",
"args": [
"@modelcontextprotocol/server-fetch",
"https://YOUR-WORKER-URL/mcp"
]
}
}
}替换 YOUR-WORKER-URL 使用您部署的Cloudflare Worker URL。
- 重新启动克劳德桌面 完全(退出并重新打开应用程序)
- 验证连接 通过寻找🔌 Claude Desktop中的图标,表示MCP服务器已连接
测试您的MCP服务器
连接后,您可以在对话中使用这些工具:
保存模板:
Use the save_prompt_template tool to save this template:
- Name: "greeting"
- Description: "A personalized greeting template"
- Template: "Hello my name is {firstName} {lastName}. What is my name?"列出您的模板:
Use the list_prompt_templates tool to show me all saved templates使用模板:
Use the get_prompt_by_name tool with:
- Name: "greeting"
- Inputs: {"firstName": "John", "lastName": "Doe"}服务器将自动从您保存的任何模板中提取变量(如 {firstName} 和 {lastName} 根据您的示例),并将其作为结构化输入提供。
构建于
- 你好 -Web框架
- Cloudflare员工 -无服务器平台
- Cloudflare D1 -SQLite数据库
- 淋ORM -TypeScript ORM
- 模型上下文协议 -AI工具集成协议
