提示保护程序MCP服务器
MCP服务器,将成功的对话线程转换为可重用的提示,可用于未来的任务。基于这样一个原则,即LLM交互中最重要的工件是你为产生结果所做的工作,而不是结果本身。
特性
- 将对话另存为提示:将对话线程转换为可重用的markdown格式的提示模板
- 语义搜索:使用Voyage AI嵌入的矢量搜索查找相关提示
- 及时管理:根据反馈更新、检索和改进提示
- 用例分类:自动对提示进行分类(代码生成、文本生成、数据分析、创意、通用)
- 人工智能驱动的改进:使用GPT-4o-mini根据用户反馈自动改进提示
工具
save_prompt
对对话历史进行总结、分类,并将其转换为markdown格式的提示模板。
参数:
conversation_messages(string,必填):包含对话历史的JSON字符串task_description(字符串,可选):正在执行的任务的描述context_info(字符串,可选):关于对话的其他上下文
search_prompts
使用语义搜索从数据库中检索提示。
参数:
query(字符串,必填):搜索查询以查找相关提示limit(整数,可选):最大结果数(默认值:5)
search_prompts_by_use_case
检索按用例类别筛选的提示。
参数:
use_case(字符串,必填):用例类别(代码生成、文本生成、数据分析、创意、通用)limit(整数,可选):最大结果数(默认值:10)
update_prompt
用新信息更新现有提示。
参数:
prompt_id(string,必填):要更新的提示的IDchange_description(string,必填):更改内容的描述prompt_template(字符串,可选):新建提示模板summary(字符串,可选):新摘要(触发嵌入再生)use_case(字符串,可选):新用例类别history(字符串,可选):更新历史记录
get_prompt_details
检索特定提示的完整详细信息。
参数:
prompt_id(string,必填):要检索的提示的ID
improve_prompt_from_feedback
使用AI根据用户反馈自动改进提示。
参数:
prompt_id(string,必填):要改进的提示IDfeedback(string,必填):用户对提示的反馈conversation_context(string,可选):关于如何使用提示的上下文
文档
- 入门指南 -逐步设置
- 团队设置指南 - 用于队友在Cursor中设置MCP服务器 ⭐
- 团队设置检查表 -快速参考清单
- 光标使用 -在Cursor中使用Python导入
- 自然语言工作流 -自然语言命令
- MCP专用工作流 -直接使用MCP工具
团队快速入门:
- 从GitHub安装:
pip install git+https://github.com/YOUR-ORG/prompt-saver-mcp.git - 复制
mcp.json.template到~/.cursor/mcp.json填写你的价值观 - 跟随 团队_设置\_ ECKLIST.md
安装
- 克隆存储库:
git clone
cd prompt-saver-mcp- 安装依赖项:
pip install -e .
# or with uv:
uv sync- 设置MongoDB Atlas:
- 创建MongoDB Atlas集群(免费层可用) - 创建一个名为的数据库 prompt_saver - 在上创建矢量搜索索引 embedding 字段: - 索引名称: vector_index - 尺寸: 2048 - 相似性: dotProduct - 路径: embedding
- 配置环境变量:
cp .env.example .env
# Edit .env with your API keys and MongoDB Atlas URI配置
环境变量
| 变量 | 描述 | 默认值 | 必填 |
|---|---|---|---|
MONGODB_URI | MongoDB Atlas连接字符串 | - | 是 |
MONGODB_DATABASE | 数据库名称 | prompt_saver | 没有 |
MONGODB_COLLECTION | 收藏名称 | prompts | 没有 |
VOYAGE_AI_API_KEY | Voyage AI API密钥 | - | 是 |
VOYAGE_AI_EMBEDDING_MODEL | 嵌入模型 | voyage-3-large | 没有 |
OPENAI_API_KEY | OpenAI API密钥 | - | 是 |
OPENAI_MODEL | 分析模型 | gpt-4o-mini | 没有 |
在游标中使用
此包旨在通过导入模块直接在Cursor中使用。无需设置MCP客户端!
快速开始
import asyncio
from prompt_saver_mcp.tools.search_prompts import handle_search_prompts
from prompt_saver_mcp.tools.save_prompt import handle_save_prompt
# Search for prompts
result = await handle_search_prompts("Python API client", limit=5)
print(result[0].text)
# Save a conversation
conversation_json = json.dumps([
{"role": "user", "content": "Help me create..."},
{"role": "assistant", "content": "Here's how..."}
])
result = await handle_save_prompt(conversation_json, "Creating API client")助手脚本
我们在 scripts/ 目录以便于使用:
prompt_helper.py-具有搜索、保存和其他功能的主要助手save_branch_prompt.py-保存GitHub分支中的提示
看 CURSOR_USAGE.md 查看详细的示例和工作流程。
用法示例
保存提示
在Cursor中完成复杂任务后,将对话另存为可重用的提示:
import asyncio
import json
from prompt_saver_mcp.tools.save_prompt import handle_save_prompt
# Example conversation messages (JSON format)
conversation = [
{"role": "user", "content": "Help me create a Python function to parse CSV files"},
{"role": "assistant", "content": "I'll help you create a robust CSV parser..."},
# ... more conversation
]
# Save the prompt
async def save():
result = await handle_save_prompt(
conversation_messages=json.dumps(conversation),
task_description="Creating a CSV parser function",
context_info="Successfully created a parser with error handling"
)
print(result[0].text)
asyncio.run(save())搜索提示
启动新任务时搜索相关提示:
import asyncio
from prompt_saver_mcp.tools.search_prompts import handle_search_prompts
async def search():
result = await handle_search_prompts("I need help with data processing in Python", limit=5)
print(result[0].text)
asyncio.run(search())获取提示详细信息
检索特定提示的完整详细信息:
import asyncio
from prompt_saver_mcp.tools.get_prompt_details import handle_get_prompt_details
async def get_details():
result = await handle_get_prompt_details("prompt_id_here")
print(result[0].text)
asyncio.run(get_details())更新提示
使用提示后,根据您的经验进行更新:
import asyncio
from prompt_saver_mcp.tools.update_prompt import handle_update_prompt
async def update():
result = await handle_update_prompt(
prompt_id="prompt_id_here",
change_description="Added error handling examples",
prompt_template="Updated template with better error handling..."
)
print(result[0].text)
asyncio.run(update())通过反馈改进提示
使用AI自动改进提示:
import asyncio
from prompt_saver_mcp.tools.improve_prompt_from_feedback import handle_improve_prompt_from_feedback
async def improve():
result = await handle_improve_prompt_from_feedback(
prompt_id="prompt_id_here",
feedback="The prompt worked well but could use more specific examples for edge cases",
conversation_context="Used for debugging a complex API integration issue"
)
print(result[0].text)
asyncio.run(improve())使用辅助脚本
为了便于使用,请使用辅助脚本:
# Search prompts
python scripts/prompt_helper.py search "Python API client"
# Save a prompt (will prompt for conversation JSON)
python scripts/prompt_helper.py save数据库模式
每个提示都以以下结构存储:
{
"_id": ObjectId,
"use_case": "code-gen" | "text-gen" | "data-analysis" | "creative" | "general",
"summary": "Summary of the prompt and its use case",
"prompt_template": "Universal problem-solving prompt template (markdown)",
"history": "Summary of steps taken and end result",
"embedding": [0.1, 0.2, ...], // 2048 dimensions
"last_updated": ISODate,
"num_updates": 0,
"changelog": ["Change 1", "Change 2", ...],
"created_by": "user123" // Optional, for team sharing
}MongoDB Atlas矢量搜索设置
- 转到您的MongoDB Atlas集群
- 导航到“搜索”选项卡
- 点击“创建搜索索引”
- 选择“JSON编辑器”
- 使用以下配置:
{
"fields": [
{
"type": "vector",
"path": "embedding",
"numDimensions": 2048,
"similarity": "dotProduct"
}
]
}- 命名索引
vector_index - 选择
prompts收集
发展
运行测试
pytest代码格式化
black prompt_saver_mcp/
ruff check prompt_saver_mcp/许可证
MIT许可证-有关详细信息,请参阅许可证文件。
备注
- 使用
gpt-4o-mini成本效益模型(比gpt-4o便宜得多,但仍然有能力) - MongoDB Atlas免费版包括512MB存储空间和共享集群,足以供个人使用
- Voyage AI提供每月有限请求的免费套餐
- 矢量搜索索引需要在MongoDB Atlas UI中手动创建(一次性设置)
