AI提示与工具服务器

一个可扩展的AI助手提示库和工具服务器,提供多种预设提示和实用工具,支持VS Code集成和HTTP访问。

  • by jerfletcher
  • JavaScript
  • 本地部署
  • 更新于
在 GitHub 查看 jerfletcher/mcp-prompt-server

使用说明

MCP提示服务器

一种模型上下文协议(MCP)服务器,为人工智能助手提供可扩展的提示和工具库。

特性

📝 鼓励

  • 如何写俳句:俳句写作说明
  • 总结文本:可自定义输入的文本摘要
  • 产生想法:任何主题的创意生成
  • 代码审查:结构化代码审查清单
  • api文档:API文档模板生成器

🛠️ 工具

  • 文本计数器:分析文本(字符、单词、行)
  • json格式化程序:格式化和验证JSON字符串
  • 时间戳转换器:在不同格式之间转换时间戳

安装

  1. 克隆或下载此存储库
  2. 无需依赖-纯Node.js实现

用法

可用脚本

npm run setup     # Automated VS Code MCP setup
npm start         # Start stdio MCP server
npm run serve     # Start HTTP server (port 3000)
npm test          # Run test suite

独立测试

直接运行服务器:

node mcpPromptsServer.js

HTTP服务器

启动HTTP服务器以进行基于web的访问:

npm run serve

向发送POST请求 http://localhost:3000/mcp 使用JSON-RPC有效载荷:

curl -X POST http://localhost:3000/mcp \
  -H "Content-Type: application/json" \
  -d '{"jsonrpc": "2.0", "id": 1, "method": "prompts/list", "params": {}}'

根据样品请求进行测试:

# List available prompts
echo '{"jsonrpc": "2.0", "id": 1, "method": "prompts/list", "params": {}}' | node mcpPromptsServer.js

# Get a specific prompt
echo '{"jsonrpc": "2.0", "id": 2, "method": "prompts/get", "params": {"name": "how-to-write-haiku"}}' | node mcpPromptsServer.js

# List available tools
echo '{"jsonrpc": "2.0", "id": 3, "method": "tools/list", "params": {}}' | node mcpPromptsServer.js

# Call a tool
echo '{"jsonrpc": "2.0", "id": 4, "method": "tools/call", "params": {"name": "text-counter", "arguments": {"text": "Hello world"}}}' | node mcpPromptsServer.js

VS代码MCP服务器集成

快速设置

运行自动安装脚本:

npm run setup
# or
node setup.js

此脚本将:

  • 检查先决条件(Node.js、服务器文件)
  • 使用MCP配置更新VS Code settings.json
  • 使服务器脚本可执行
  • 测试服务器功能
  • 显示下一步

手动配置

先决条件

  • 支持MCP扩展的VS代码
  • 系统上已安装Node.js

配置

  1. 添加到VS代码MCP配置

    打开VS代码设置并添加MCP服务器配置:

    {
      "mcp.servers": {
        "prompt-server": {
          "command": "node",
          "args": ["/absolute/path/to/mcpPromptsServer.js"],
          "env": {}
        }
      }
    }
    
  2. 替代方案:全球安装

    使脚本可执行并添加到PATH:

    chmod +x mcpPromptsServer.js
    sudo cp mcpPromptsServer.js /usr/local/bin/mcp-prompt-server
    

    然后在VS Code中配置:

    {
      "mcp.servers": {
        "prompt-server": {
          "command": "mcp-prompt-server",
          "args": [],
          "env": {}
        }
      }
    }
    

在VS代码中使用

配置后,您可以:

  1. 访问提示:使用命令面板或MCP界面:

    • 列出可用提示 prompts/list
    • 通过以下方式获取特定提示 prompts/get
    • 将参数传递给参数化提示
  2. 使用工具:通过MCP接口执行工具:

    • 统计文本统计信息 text-counter
    • 使用格式化JSON json-formatter
    • 将时间戳转换为 timestamp-converter
  3. AI助手集成:服务器与支持MCP的AI助手配合使用,提供上下文感知提示和实用工具。

api参考

鼓励

prompts/list

返回所有可用的提示。

prompts/get

参数:

  • name (必填):提示名称
  • arguments (可选):具有提示特定参数的对象

工具

tools/list

返回所有可用的工具及其模式。

tools/call

参数:

  • name (必填):工具名称
  • arguments (可选):具有工具特定参数的对象

测试

自动化测试

该项目包括对所有提示和工具的全面测试:

npm test

测试验证:

  • 结构:必填字段(名称、描述、内容/inputSchema、处理程序)
  • 功能:工具执行时没有错误
  • 结果:输出与预期值匹配(如果提供)
  • 覆盖:警告缺少测试配置

测试结果

  • ✅ 通过:工具/提示正常工作
  • ❌ 失败:执行或结果验证时出错
  • ⚠️ 警告:缺少测试配置

扩展服务器

项目结构

mcp-prompt-server/
├── mcpPromptsServer.js    # Main MCP server
├── httpServer.js          # HTTP wrapper server
├── test.js               # Test runner
├── setup.js              # VS Code setup script
├── prompts/              # Prompt modules
│   ├── writing.js        # Writing-related prompts
│   ├── development.js    # Development prompts
│   └── text-analysis.js  # Text analysis prompts
└── tools/                # Tool modules
    ├── text-analysis.js  # Text analysis tools
    └── utilities.js      # Utility tools

添加新提示

  1. 在中创建或编辑文件 prompts/ 目录
  2. 添加具有所需结构的提示:
module.exports = {
    "your-prompt-name": {
        name: "your-prompt-name",
        description: "Description of your prompt",
        arguments: [
            { name: "param1", description: "Parameter description", required: true }
        ],
        content: `
            **Your Prompt Title:**
            
            Your prompt content here...
        `,
        llmInstruction: (args) => `LLM instruction with ${args.param1}`,
        test: { param1: "test value" }  // Test configuration
    }
};

添加新工具

  1. 在中创建或编辑文件 tools/ 目录
  2. 添加具有所需结构的工具:
module.exports = {
    "your-tool-name": {
        name: "your-tool-name",
        description: "Tool description",
        inputSchema: {
            type: "object",
            properties: {
                input: { type: "string", description: "Input description" }
            },
            required: ["input"]
        },
        handler: (args) => {
            // Your tool logic here
            return { result: "tool output" };
        },
        test: {
            input: "test input",
            expected: {
                result: "tool output"
            }
        }
    }
};

测试配置

每个提示和工具应包括 test 财产:

提示:

test: { param1: "value1", param2: "value2" }

对于工具:

test: {
    input: "test input",
    expected: {  // Optional: validate specific output fields
        result: "expected result",
        status: "success"
    }
}

验证规则

  • 缺少测试:无工具/提示 test 属性显示警告
  • 预期结果:如果 expected 如果提供,实际输出必须完全匹配
  • 必需参数:测试配置中必须存在所有必需的参数

故障排除

常见问题

  1. 服务器未启动:检查Node.js安装和文件权限
  2. VS代码未检测到服务器:验证配置中的绝对路径
  3. JSON解析错误:确保请求遵循JSON-RPC 2.0格式

调试模式

监视服务器日志:

node mcpPromptsServer.js 2>debug.log

服务器会记录到stderr,因此响应不会与调试输出混合。

许可证

国际协调委员会

贡献

  1. 分叉存储库
  2. 将您的提示/工具添加到相应的库中
  3. 在独立模式下进行测试
  4. 提交拉取请求

如有疑问或问题,请在存储库中打开问题。