MCP Prompts Server

by sparesparrow
Verified

hybrid server

The server is able to function both locally and remotely, depending on the configuration or use case.

Integrations

  • Supports deployment using Docker and Docker Compose for containerized deployment

  • Built on Node.js with support for Node.js 18 or later

  • Provides integration with PostgreSQL databases for storing prompts, with export/import functionality and synchronization between file storage and database

MCP 提示服务器

用于管理提示和模板的 MCP 服务器,具备项目编排功能。它是模型上下文协议 (MCP) 生态系统的一部分。

该服务器提供了一种存储、检索和应用 AI 提示模板的简单方法,从而更容易在 AI 应用程序中保持一致的提示模式。

目录

特征

  • 存储和检索提示
  • 创建并使用带有变量的模板
  • 通过标签过滤列出提示
  • 将变量应用于模板
  • 多种存储后端(文件系统、PostgreSQL 和 MDC 格式)
  • 易于与 Claude 和其他 AI 助手一起使用
  • 项目编排能力
  • 健康检查端点

安装

使用 npx(推荐)

npx -y @sparesparrow/mcp-prompts

全局安装

npm install -g @sparesparrow/mcp-prompts

使用 Docker

docker run -p 3003:3003 -v ~/mcp/data:/app/data sparesparrow/mcp-prompts:latest

验证安装

安装后,您可以通过以下方式验证服务器是否正常工作:

  1. 打开Claude桌面
  2. 在聊天输入中输入“/”查看是否出现来自服务器的提示
  3. 使用简单的工具调用进行测试:
    use_mcp_tool({ server_name: "prompt-manager", tool_name: "list_prompts", arguments: {} });

配置

可以使用环境变量来配置服务器:

环境变量描述默认
服务器名称服务器名称MCP 提示服务器
服务器版本服务器版本package.json 版本
存储类型存储类型:“文件”、“postgres”或“mdc”文件
PROMPTS_DIR存储提示的目录~/mcp/data/提示
备份目录备份目录~/mcp/data/备份
港口HTTP 服务器端口3003
日志级别日志级别信息
HTTP服务器启用 HTTP 服务器错误的
主持人HTTP 服务器的主机0.0.0.0

PostgreSQL 设置(如果 STORAGE_TYPE=postgres 则需要)

环境变量描述默认
PG_HOSTPostgreSQL 主机本地主机
PG_PORTPostgreSQL 端口5432
PG_数据库PostgreSQL 数据库名称mcp_提示符
PG_用户PostgreSQL 用户名PostgreSQL
PG_密码PostgreSQL 密码
PG_SSL使用 SSL 进行 PostgreSQL 连接错误的
POSTGRES_CONNECTION_STRING完整的 PostgreSQL 连接字符串(覆盖单独的设置)

MDC 设置(如果 STORAGE_TYPE=mdc 则需要)

环境变量描述默认
MDC_RULES_DIRMDC 规则目录./.光标/规则

用法

与 Claude 一起使用

在 Claude 3 桌面应用中,您可以在claude_desktop_config.json中配置 MCP Prompts 服务器:

{ "mcpServers": { "prompts": { "command": "npx", "args": [ "-y", "@sparesparrow/mcp-prompts" ], "env": { "STORAGE_TYPE": "file", "PROMPTS_DIR": "/path/to/your/prompts/directory", "LOG_LEVEL": "debug" } } } }

可用工具

MCP Prompts 服务器提供以下工具:

  • add_prompt :添加新提示
  • get_prompt :通过 ID 获取提示
  • update_prompt :更新现有提示
  • list_prompts :列出所有提示
  • delete_prompt :通过 ID 删除提示
  • apply_template :将变量应用于提示模板

API 使用示例

列出可用的提示

要查看可用的提示:

use_mcp_tool({ server_name: "prompt-manager", tool_name: "list_prompts", arguments: {} });

按标签过滤:

use_mcp_tool({ server_name: "prompt-manager", tool_name: "list_prompts", arguments: { tags: ["development"] } });

获取特定提示

要通过 ID 检索特定提示:

use_mcp_tool({ server_name: "prompt-manager", tool_name: "get_prompt", arguments: { id: "development-workflow" } });

使用模板提示

要将变量应用于模板提示:

use_mcp_tool({ server_name: "prompt-manager", tool_name: "apply_template", arguments: { id: "development-system-prompt", variables: { "project_type": "web frontend", "language": "JavaScript/React", "project_name": "TaskManager", "project_goal": "create a task management application with drag-and-drop functionality", "technical_context": "Using React 18, TypeScript, and Material UI" } } });

管理提示

添加新提示

要添加新提示:

use_mcp_tool({ server_name: "prompt-manager", tool_name: "add_prompt", arguments: { name: "Bug Report Template", description: "Template for submitting bug reports", content: "## Bug Report\n\n### Description\n{{description}}\n\n### Steps to Reproduce\n{{steps}}\n\n### Expected Behavior\n{{expected}}\n\n### Actual Behavior\n{{actual}}\n\n### Environment\n{{environment}}", isTemplate: true, variables: ["description", "steps", "expected", "actual", "environment"], tags: ["bug", "template", "documentation"] } });

编辑现有提示

要编辑现有提示:

use_mcp_tool({ server_name: "prompt-manager", tool_name: "edit_prompt", arguments: { id: "development-workflow", content: "Updated workflow content here...", tags: ["development", "workflow", "python", "updated"] } });

在工作流程中使用提示

开发工作流程示例

当开始开发新功能时:

  1. 请求开发系统提示模板
  2. 在模板中填写您的项目详细信息
  3. 使用系统提示来指导克劳德的协助

代码审查示例

审查代码时:

  1. 请求代码审查模板
  2. 提供需要审核的代码
  3. Claude 将提供结构化审查

提示格式

提示具有以下结构:

{ "id": "unique-id", "name": "Prompt Name", "description": "Optional description", "content": "The prompt content with {{variables}}", "tags": ["tag1", "tag2"], "isTemplate": true, "variables": ["variable1", "variable2"], "metadata": { "author": "Your Name", "version": "1.0.0" } }

多格式提示支持

MCP Prompts 服务器包含一个强大的MutablePrompt接口,允许提示在多种格式之间转换:

  • JSON 格式:服务器使用的标准内部格式
  • MDC 格式:光标规则 Markdown 格式(.mdc 文件)
  • PGAI 格式:支持 PostgreSQL AI 嵌入的格式
  • 模板格式:带有变量占位符的动态格式

格式转换

MutablePrompt 接口提供了在以下格式之间转换提示的方法:

// Create a mutable prompt const factory = new MutablePromptFactoryImpl(); const prompt = factory.create({ name: "API Design Guide", description: "Template for designing RESTful APIs", content: "# API Design for {{service_name}}\n\n## Endpoints\n\n{{endpoints}}\n\n## Authentication\n\n{{auth_method}}", isTemplate: true, variables: ["service_name", "endpoints", "auth_method"], tags: ["api", "design", "rest", "glob:*.md"] }); // Convert to MDC format const mdcContent = prompt.toMdc({ includeVariables: true }); // Convert to PGAI format with embeddings const pgaiData = prompt.toPgai({ generateEmbeddings: true, collection: "prompts", vectorConfig: { dimension: 1536, metric: "cosine" } }); // Convert to template format with dollar-style variables const templateContent = prompt.toTemplate({ delimiterStyle: "dollar" });

应用模板

您可以轻松地将变量应用于模板提示:

const result = prompt.applyVariables({ service_name: "User Management API", endpoints: "GET /users, POST /users, GET /users/{id}, PUT /users/{id}, DELETE /users/{id}", auth_method: "JWT Bearer Token" });

提取变量

从模板内容中提取变量:

const variables = prompt.extractVariables(); // Returns ["service_name", "endpoints", "auth_method"]

从不同格式创建

您还可以创建各种格式的提示:

// From MDC format const mdcContent = `--- description: Template for code reviews globs: ["*.js", "*.ts"] --- # Code Review Template ## Context {{context}} ## Patterns {{patterns}} ## Variables - \`context\`: Description of the code being reviewed - \`patterns\`: Common patterns to look for `; const promptFromMdc = factory.fromMdc(mdcContent); // From PGAI format const pgaiData = { id: "api-design", name: "API Design Guide", content: "# API Design Guide\n\nUse this guide...", metadata: { description: "Comprehensive API design guide", tags: ["api", "rest"], isTemplate: false } }; const promptFromPgai = factory.fromPgai(pgaiData);

与存储适配器集成

MutablePrompt 接口与现有的存储适配器无缝协作:

// Save a prompt in MDC format const mdcPrompt = factory.fromMdc(mdcContent); await fileAdapter.savePrompt(mdcPrompt); // Save a prompt to PostgreSQL with PGAI format const pgaiPrompt = factory.fromPgai(pgaiData); await postgresAdapter.savePrompt(pgaiPrompt);

这种灵活的格式处理可以实现:

  1. 跨平台兼容性:在不同的工具和平台中使用提示
  2. 矢量搜索:使用 PGAI 格式实现语义搜索功能
  3. IDE 集成:与 Cursor Rules 直接兼容
  4. 模板系统:导出用于各种编程语言的模板

存储适配器

该服务器支持三种类型的存储适配器:

  1. 文件适配器:将提示作为单独的 JSON 文件存储在目录中。
  2. PostgreSQL 适配器:将提示存储在 PostgreSQL 数据库中。
  3. MDC 适配器:以光标规则 MDC 格式存储提示。

可以使用STORAGE_TYPE环境变量配置存储类型:

STORAGE_TYPE=file # Default STORAGE_TYPE=postgres # Requires PostgreSQL configuration STORAGE_TYPE=mdc # For Cursor Rules format

PostgreSQL 设置

使用PostgreSQL存储时,配置以下环境变量:

PG_HOST=localhost PG_PORT=5432 PG_DATABASE=mcp_prompts PG_USER=postgres PG_PASSWORD=your_password PG_SSL=false

或者,使用连接字符串:

POSTGRES_CONNECTION_STRING=postgresql://user:password@host:port/database

Docker 部署

Docker Compose 编排

MCP Prompts Server 针对不同的部署场景提供了各种 Docker Compose 配置:

简单部署

docker compose up -d

这将使用端口 3003 上的文件存储部署 MCP Prompts 服务器。

PostgreSQL 部署

docker compose -f docker-compose.postgres.yml up -d

这将部署:

  • PostgreSQL 数据库服务器
  • 为 PostgreSQL 配置的 MCP Prompts 服务器
  • 数据库管理管理员:http://localhost:8080

开发环境

docker compose -f docker-compose.dev.yml up -d

这将设置一个支持热加载的开发环境。它会从本地目录挂载源代码,并包含 Adminer。

测试环境

docker compose -f docker-compose.test.yml up --build

这将创建一个专用的测试环境,其中包含:

  • 包含测试数据的临时 PostgreSQL 实例
  • 执行所有测试的独立测试运行器容器
  • 测试结果保存到./test-results目录

Docker管理脚本

为了简化 Docker Compose 操作,请使用提供的管理脚本:

# Start development environment ./scripts/docker-manage.sh start dev # Run tests in Docker ./scripts/docker-manage.sh test # View logs from production environment ./scripts/docker-manage.sh logs prod # Clean up test environment ./scripts/docker-manage.sh clean test # Show help ./scripts/docker-manage.sh help

管理脚本支持以下命令:

  • start :启动 Docker 容器
  • stop :停止 Docker 容器
  • restart :重新启动 Docker 容器
  • logs :显示容器的日志
  • clean :删除容器、网络和卷
  • build :构建 Docker 镜像
  • test :在 Docker 容器中运行测试

以及以下环境:

  • dev :开发环境(默认)
  • test :测试环境
  • prod :生产环境

自定义配置

您可以通过扩展基本配置来创建自己的自定义 Docker Compose 配置:

# custom-compose.yml version: '3.8' include: - docker-compose.yml services: mcp-prompts: environment: - CUSTOM_ENV=value

然后运行它:

docker compose -f custom-compose.yml up -d

发展

开发工作流程

设置开发环境

  1. 克隆存储库
    git clone https://github.com/user/mcp-prompt-manager.git cd mcp-prompt-manager
  2. 安装依赖项
    npm install
  3. 设置环境变量创建一个具有必要配置的.env文件。

开发命令

  • 使用热重载启动开发服务器
    npm run dev
  • 构建项目
    npm run build
  • 运行单元测试
    npm test
  • 运行集成测试
    npm run test:integration
  • 测试构建过程
    npm run test:build
  • 测试 Docker 构建
    npm run test:docker
  • 构建 Docker 镜像
    npm run docker:build

构建过程

构建过程包括几个重要步骤:

  1. TypeScript 编译
    npm run build
  2. 使入口点可执行
    chmod +x dist/index.js

测试

运行测试:

npm test

运行 MCP Inspector 进行测试:

npm run test:inspector

全面的测试脚本

如需更多高级测试选项,请使用提供的测试脚本:

# Run all tests (unit and integration) ./scripts/run-tests.sh # Run only unit tests ./scripts/run-tests.sh --unit # Run only integration tests ./scripts/run-tests.sh --integration # Generate test coverage report ./scripts/run-tests.sh --coverage # Run tests in Docker ./scripts/run-tests.sh --docker # Clean up Docker resources after testing ./scripts/run-tests.sh --docker --clean

Docker容器健康测试

测试 Docker 容器的健康状况:

# Run the Docker health check tests TEST_DOCKER_HEALTH=true npm test -- tests/integration/docker-health.integration.test.ts

此测试验证当 MCP-Prompts 服务器在 Docker 容器中运行时,健康检查端点是否正常工作。

目录结构

该项目遵循结构化组织来保持关注点的清晰分离:

mcp-prompt-manager/ ├── .github/workflows/ # CI/CD workflow configurations ├── dist/ # Built files ├── src/ # Source code │ ├── adapters.ts # Storage adapters │ ├── interfaces.ts # Core types and interfaces │ └── index.ts # Main entry point ├── scripts/ # Maintenance and utility scripts ├── package.json # Project metadata and scripts └── README.md # Project documentation

发布流程

预发布检查清单

  • 所有 TypeScript 错误均已解决
  • 代码检查通过,没有错误
  • 代码格式符合项目标准
  • 单元测试通过
  • 集成测试通过
  • 构建测试通过
  • Docker 构建测试通过
  • 软件包安装测试通过
  • README 包含最新的功能和更改
  • CHANGELOG 已更新所有值得注意的变更

版本更新

  • 根据语义版本更新package.json中的版本
  • 确保依赖项是最新的
  • 更新文档中的任何版本引用

出版

  • 为新版本创建一个 git 标签
  • 将更改和标签推送到 GitHub
  • 发布到 npm( npm publish
  • 构建并推送 Docker 镜像

发布后验证

  • 从 npm 验证安装
  • 验证包是否可以使用 npx 运行
  • 验证 Docker 镜像是否按预期工作
  • 验证与 Claude Desktop 的集成

变更日志

[1.2.20] - 2025-03-14

  • 自动化版本升级

[1.2.19] - 2024-03-16

固定的

  • 修复了 PostgresAdapter 实现中的 TypeScript 错误
  • 增强了 savePrompt 方法,以正确返回创建的提示
  • 向 PostgresAdapter 添加了 updatePrompt 方法
  • 修复了 StorageAdapter 接口,使其包含 listPrompts 和 clearAll 方法
  • 改进了 database-tools.ts 中 clearAll 方法的错误处理
  • 增强的健康检查端点,提供更详细的信息

额外

  • 为健康检查端点添加了更好的文档和错误处理

[1.2.18] - 2024-03-14

额外

  • 添加了具有健康检查端点的 HTTP 服务器
  • 添加了 Docker 容器健康检查
  • 增加了对 Node.js 18-23+ 的 ESM 模块兼容性
  • 增强的数据库工具,具有更好的错误处理能力

已更改

  • 通过多阶段构建改进 Docker 构建过程
  • 简化的配置管理
  • 优化 PostgreSQL 适配器连接处理
  • 已将依赖项更新至最新版本

固定的

  • 修复了某些文件系统上的文件适配器问题
  • 改进错误消息以便更好地调试
  • 固定模板变量提取

[1.2.0] - 2025-03-14

已更改

  • 重新组织代码库结构以提高可维护性
  • 将 Docker 相关文件移至docker/目录
  • 将构建脚本移至scripts/build/目录
  • 将测试脚本移至scripts/test/目录
  • 更新了 GitHub 工作流程以使用新的文件路径
  • 更新了 Docker Compose 配置以使用新的文件路径
  • 添加了全面的开发文档

额外

  • 创建包含详细说明的开发文档
  • 创建发布准备清单
  • 添加了 CHANGELOG.md 来跟踪更改

已移除

  • 删除重复和冗余文件
  • 删除了不完整的脚本

[1.1.0] - 2024-03-01

额外

  • 用于语义提示发现的 PGAI 向量搜索
  • 支持 PostgreSQL 中的嵌入
  • 使用专业模板改进提示收集
  • 批量处理能力,方便快速收集

已更改

  • 增强提示处理流程
  • 改进的命令行界面,提供更多选项
  • 更好的错误处理和验证

[1.0.0] - 2024-02-15

额外

  • MCP Prompts 服务器的初始版本
  • 基本提示管理功能(添加、编辑、获取、列出、删除)
  • 模板变量替换
  • 基于标签的组织
  • 基于文件的存储
  • 导入/导出功能
  • MCP 协议兼容性

最佳实践

  1. 使用标签进行组织:使用标签对提示进行分类,以便于检索
  2. 使用模板:创建带有变量的可重复使用模板,以实现一致的提示
  3. 包括元数据:添加作者、版本和其他元数据以便更好地组织
  4. 定期备份:如果管理关键提示,请使用备份功能
  5. 优化大型集合:检索大型提示集合时使用分页
  6. 使用一致的命名:清晰一致地命名提示,以便于发现
  7. 有效标记:使用标签按目的、项目或上下文组织提示
  8. 模板化可重复使用的提示:使用变量为常用提示创建模板
  9. 定期更新:随着需求的变化,保持提示的更新
  10. 与团队分享:与您的团队分享有效的提示,以实现持续的互动

执照

麻省理工学院

ID: i0z4f3pr82