## ⚠️ 已弃用--不再维护 此存储库已被取代。所有新的开发和支持都存在于: - systempromptio/systemprompt模板 --从这里开始。对完整的systemprompt.io人工智能治理基础设施进行自托管评估。 - systempromptio/systemprompt核心 --底层Rust库(MCP、A2A、OAuth 2.1、审计、编译时扩展)。 了解更多 系统提示.io. _下面保留了原始的README以供历史参考。_
______________________________________________________________________
系统提示mcp服务器
](https://www.npmjs.com/package/@systemprompt/systemprompt-mcp-server)   
由systemprompt.io赞助
此MCP服务器实现是 主办单位 系统提示.io --创作者 全球首款适用于iOS和Android的原生移动MCP客户端 --并完全提供 免费开源 社区。
如果您觉得这个项目有用,我们将不胜感激:
- ⭐ 此存储库中的一颗星
- 👍 在我们的社交渠道上点赞/关注
- 🔗 与您的网络共享
您的支持帮助我们继续为人工智能社区创建有价值的开源工具!
🚀 了解更多:有关此实现与实时SDK测试的交互式演练,请访问 systemprompt.io/mcp服务器
一个生产就绪的模型上下文协议(MCP)服务器,演示了 完整的MCP规范 包括OAuth 2.1、采样、启发、结构化数据验证和实时通知。
此实现使用Reddit作为真实世界的示例来演示OAuth 2.1流程和高级MCP功能,但该体系结构被设计为易于适用于任何需要OAuth身份验证的API。
此服务器可与任何支持采样和通知等高级功能的MCP兼容客户端配合使用。
🔍 MCP检查器兼容
此服务器是 完全兼容 随着 MCP检查员,为以下方面提供完美支持:
- ✅ OAuth 2.1身份验证 -使用PKCE完成流程
- ✅ 工具 -所有Reddit交互功能
- ✅ 提示 -动态内容生成提示
- ✅ 采样 -人工智能辅助内容获得人类认可
- ✅ 通知 -实时进度更新
自己测试一下: npm run inspector
🌟 为什么这一实施很重要
OAuth 2.1在Reddit上的演示
此实现使用 Reddit的API作为一个现实世界的例子 演示如何在MCP服务器中构建完整的OAuth 2.1流。选择Reddit是因为:
- 大多数操作都需要OAuth身份验证
- 它提供了丰富的API,用于演示各种MCP功能
- 这是一个文档齐全、可公开访问的API
- 它展示了现实世界中的身份验证挑战和解决方案
备注:虽然此服务器使用Reddit,但OAuth实现和架构模式的设计可轻松适用于任何基于OAuth的API(GitHub、Google、Slack等)。
演示的主要功能
此存储库用作 金本位 对于MCP服务器实现,展示:
- 完整的MCP规范覆盖范围:实现了从OAuth到采样的每个功能
- 生产架构:内置多用户会话、安全性和可扩展性
- 开发者体验:干净的代码结构非常适合学习或分叉
- 真实世界OAuth集成:具有PKCE、JWT令牌和会话管理的完整OAuth 2.1流
- AI原生设计:与LLM深度集成,用于内容生成和分析
📚 目录
✨ 特性
核心MCP实施
- 🔐 OAuth 2.1流程:使用PKCE和JWT完成8步实现
- 🛠️ 工具系统:Reddit互动的综合工具
- 📚 资源和提示:动态提示生成和资源管理
- 🤖 采样:人工智能辅助内容生成,人工监督
- 💬 引出:工具执行期间的动态用户输入收集
- ✅ 结构化数据:所有输入/输出的JSON模式验证
- 📡 通知:实时进度更新和状态通知
- 🔄 会话管理:具有自动清理功能的多用户支持
Reddit集成功能
- 内容发现:搜索和分析Reddit内容
- 用户交互:查看消息、通知和管理帐户
- 子涡流信息:检索subreddit详细信息和帖子
- 评论线索:浏览和分析Reddit讨论
开发人员功能
- TypeScript:全型安全,接口全面
- 模块化架构:明确区分关注点
- 错误处理:具有自定义错误类型的强大错误管理
- Docker支持:已准备好进行集装箱化部署
- 测试:包括示例测试实现
- 文档:大量内联文档和示例
🚀 快速开始
🐳 最简单的安装(带npx的Docker)
使用Docker立即运行服务器-无需安装:
步骤1:创建Reddit应用程序和初始配置
- 创建一个Reddit应用程序 reddit.com/prefs/apps
- 选择“脚本”类型 - 设置重定向URI: http://localhost:3000/oauth/reddit/callback
- 创建初始
.env文件:
cat > .env > .env
# Restart with the token
docker run -it --rm \
-p 3000:3000 \
--env-file .env \
node:20-slim \
npx @systemprompt/systemprompt-mcp-server现在,您可以在经过身份验证的会话中使用所有Reddit工具!
安装
# Via npm
npm install -g @systemprompt/systemprompt-mcp-server
# Via npx (no installation)
npx @systemprompt/systemprompt-mcp-server
# Clone for development
git clone https://github.com/systempromptio/systemprompt-mcp-server.git
cd systemprompt-mcp-server
npm install
npm run build配置
- 创建Reddit应用程序: reddit.com/prefs/apps
- 选择“脚本”类型 - 设置重定向URI: http://localhost:3000/oauth/reddit/callback
- 设置环境变量:
创建一个 .env 项目根目录中的文件:
# Required for Reddit API
REDDIT_CLIENT_ID=your_reddit_client_id
REDDIT_CLIENT_SECRET=your_reddit_client_secret
JWT_SECRET=your_jwt_secret # Secret for JWT signing
# Optional
PORT=3000 # Server port (default: 3000)
OAUTH_ISSUER=http://localhost:3000 # OAuth issuer URL
REDIRECT_URL=http://localhost:3000/oauth/reddit/callback # OAuth redirect
REDDIT_USER_AGENT=linux:systemprompt-mcp-reddit:v2.0.0 # Reddit user agent
REDDIT_USERNAME=your_reddit_username # Your Reddit username (optional)
LOG_LEVEL=debug # Logging level (debug, info, warn, error)备注:本地开发和Docker部署都需要环境变量。
运行服务器
# Build the TypeScript code
npm run build
# Run the built server
node build/index.js
# Development with watch mode
npm run watch
# In another terminal:
node build/index.js
# With Docker
npm run docker🏗️ 建筑
此实现遵循干净的架构原则,层之间有明确的分离:
┌─────────────────────────────────────────────────────────┐
│ Client Application │
│ (systemprompt.io) │
└────────────────────────┬────────────────────────────────┘
│ MCP Protocol
┌────────────────────────┴────────────────────────────────┐
│ MCP Server Layer │
│ ┌─────────────┐ ┌─────────────┐ ┌────────────────┐ │
│ │ OAuth 2.1 │ │ Session │ │ Notification │ │
│ │ Handler │ │ Manager │ │ Manager │ │
│ └─────────────┘ └─────────────┘ └────────────────┘ │
└────────────────────────┬────────────────────────────────┘
│
┌────────────────────────┴────────────────────────────────┐
│ Handler Layer │
│ ┌─────────────┐ ┌─────────────┐ ┌────────────────┐ │
│ │ Tools │ │ Resources │ │ Sampling │ │
│ │ Handler │ │ Handler │ │ Handler │ │
│ └─────────────┘ └─────────────┘ └────────────────┘ │
└────────────────────────┬────────────────────────────────┘
│
┌────────────────────────┴────────────────────────────────┐
│ Service Layer │
│ ┌─────────────┐ ┌─────────────┐ ┌────────────────┐ │
│ │ Reddit │ │ Auth │ │ Fetch │ │
│ │ Service │ │ Service │ │ Service │ │
│ └─────────────┘ └─────────────┘ └────────────────┘ │
└─────────────────────────────────────────────────────────┘关键组件
src/server.ts:主HTTP服务器设置和Express配置src/server/:核心服务器基础架构(MCP、OAuth、身份验证管理)src/handlers/:请求工具、提示、资源和采样的处理程序src/services/:业务逻辑与Reddit API集成src/constants/:工具定义、服务器配置和架构src/types/:TypeScript类型定义和接口
🔐 OAuth实现
此服务器实现了完整 MCP OAuth 2.1规范:
OAuth流程步骤
- 401初始响应 (src/server/oauth.ts)
WWW-Authenticate: Bearer realm="MCP Reddit Server"- 资源元数据 (src/server/oauth.ts)
{
"authorization_server": "http://localhost:3000/.well-known/oauth"
}- 授权服务器元数据 (src/server/oauth.ts)
- 令牌端点配置 - PKCE支持声明 - 支持的补助类型
- 授权请求 (src/server/oauth.ts)
- PKCE代码挑战 - CSRF保护状态参数 - Reddit OAuth重定向处理
- Reddit OAuth回调 (src/server/oauth.ts)
- Reddit授权处理 - 安全状态验证
- 代币交换 (src/server/oauth.ts)
- PKCE验证 - JWT令牌生成 - Reddit凭据嵌入
- 经过身份验证的请求 (src/server/middleware.ts)
- JWT验证 - 会话管理 - 请求上下文注入
安全特性
- PKCE实现:防止授权码被拦截
- JWT代币:安全的凭证存储和传输
- 会话隔离:每个用户都有独立的Reddit凭据
- 自动清理:会话在不活动后过期
🛠️ 工具参考
内容发现工具
search_reddit
使用过滤器在Reddit上搜索(src/handlers/tools/search-reddit.ts)
{
"query": "typescript MCP",
"subreddit": "programming", // Optional specific subreddit
"sort": "relevance",
"time": "week",
"limit": 10
}get_post
获取带有评论的特定帖子(src/处理程序/工具/get-post.ts)
{
"id": "post_id_here" // Reddit post ID
}get_channel
获取subreddit帖子(src/处理程序/工具/get-channel.ts)
{
"subreddit": "programming",
"sort": "hot" // "hot", "new", or "controversial"
}用户交互工具
get_notifications
获取用户通知和消息(src/handlers/tools/get-notifications.ts)
{
"filter": "unread", // "all", "unread", "messages", "comments", "mentions"
"limit": 25,
"markRead": false
}get_comment
检索特定评论(src/handlers/tools/get-comment.ts)
{
"id": "comment_id_here",
"includeThread": true // Include full comment thread
}示例和开发工具
elicitation_example
演示用户输入收集(src/处理程序/工具/启发-example.ts)
{
"type": "input", // "input", "confirm", "choice"
"prompt": "Enter your choice",
"options": ["option1", "option2"] // For choice type
}sampling_example
演示人工智能辅助内容生成(src/handles/tools/sampling-example.ts)
{
"prompt": "Generate a code example",
"maxTokens": 1000,
"temperature": 0.7
}structured_data_example
演示结构化数据处理(src/处理程序/工具/结构化数据示例.ts)
{
"format": "json", // "json", "table", "markdown"
"data": { "key": "value" }
}validation_example
演示输入验证(src/handlers/tools/validation-example.ts)
{
"test_string": "example",
"test_number": 42,
"test_enum": "option1"
}mcp_logging
请求服务器记录消息(src/处理程序/工具/日志.ts)
{
"level": "info", // "debug", "info", "warning", "error"
"message": "Debug message",
"data": { "additional": "context" }
}🎯 高级功能
采样(人工智能辅助内容生成)
采样实施(src/handlers/sampling.ts)遵循完整的MCP规范:
// 1. Client requests AI assistance
await client.callTool("sampling_example", {
prompt: "Analyze this subreddit and suggest actions",
maxTokens: 1000,
temperature: 0.7
});
// 2. Server initiates sampling for content generation
const samplingRequest = {
method: "sampling/createMessage",
params: {
messages: [{
role: "user",
content: {
type: "text",
text: "Analyze this subreddit and suggest actions"
}
}],
maxTokens: 1000,
temperature: 0.7,
_meta: {
callback: "suggest_action"
}
}
};
// 3. AI generates content
// 4. Callback processes the response
// 5. Client receives the final result启发式(动态输入收集)
示例实现(src/处理程序/工具/启发-example.ts):
// Call the elicitation example tool
await client.callTool("elicitation_example", {
type: "input",
prompt: "Enter post title",
options: []
});
// The tool demonstrates different elicitation types:
// - "input": Text input from user
// - "confirm": Yes/no confirmation
// - "choice": Multiple choice selection进度通知
操作过程中的实时更新(src/handler/notifications.ts):
// Send notifications during long-running operations
await sendProgressNotification("Processing request...", sessionId);
await sendSamplingCompleteNotification("Analysis complete", sessionId);
// Notifications are automatically sent to the MCP client
// providing real-time feedback during tool execution结构化数据验证
所有输入都使用Zod模式验证(src/handlers/tool-handlers.ts):
// Example Zod schema for Reddit search
const SearchRedditSchema = z.object({
query: z.string().min(1).max(500).describe("Search query"),
subreddit: z.string().optional().describe("Optional subreddit filter"),
sort: z.enum(["relevance", "hot", "new", "top"]).default("relevance"),
time: z.enum(["hour", "day", "week", "month", "year", "all"]).default("all"),
limit: z.number().int().min(1).max(100).default(25)
});
// Validation is automatic and provides detailed error messages
const args = SearchRedditSchema.parse(request.params.arguments);🎨 用作模板
此代码库旨在分叉并适用于其他MCP实现:
第一步:分叉和克隆
git clone https://github.com/your-username/your-mcp-server.git
cd your-mcp-server步骤2:替换服务层
替换Reddit特定服务 src/services/ 使用API:
// src/services/your-api/your-service.ts
export class YourAPIService {
async fetchData(params: YourParams): Promise {
// Your API integration
}
}步骤3:定义新工具
在中创建工具 src/handlers/tools/:
// src/handlers/tools/your-tool.ts
export const yourTool: ToolDefinition = {
schema: {
name: "your_tool",
description: "What your tool does",
inputSchema: {
type: "object",
properties: {
// Your parameters
}
}
},
handler: async (params, context) => {
// Tool implementation
}
};步骤4:更新配置
修改 src/constants/server/server-config.ts:
export const serverConfig = {
name: "your-mcp-server",
version: "1.0.0",
description: "Your MCP server description"
};
export const serverCapabilities = {
tools: {},
prompts: {},
resources: {},
sampling: {}
};💻 发展
先决条件
- Node.js 18+
- npm或纱线
- Reddit帐户和应用程序凭据
开发命令
# Install dependencies
npm install
# Build TypeScript
npm run build
# Watch mode for development
npm run watch
# Run tests (requires OAuth tokens - see below)
npm run test
# Run end-to-end tests
npm run e2e
# Build and run with Docker
npm run docker测试
MCP检验员测试
服务器与完全兼容 MCP检查员,它为测试所有MCP功能提供了强大的接口:
# Build the server first
npm run build
# Launch the inspector with the built server
npx @modelcontextprotocol/inspector build/index.js此命令将:
- 构建TypeScript项目
- 在浏览器中打开MCP检查器文档
- 启动连接到本地服务器的检查器
全功能兼容性
Reddit MCP服务器与MCP检查器完美配合,用于:
- 🔐 OAuth身份验证:使用PKCE支持完成OAuth 2.1流程
- 🛠️ 工具:所有Reddit互动工具(搜索、获取帖子、通知等)
- 📚 提示:动态生成内容创建提示
- 🤖 采样:人工智能辅助内容生成,人工参与审批
- 📡 通知:运营期间的实时进度更新
- ✅ 结构化数据:输入/输出的完整JSON模式验证
检查员提供:
- 交互式工具测试与参数验证
- OAuth流可视化和调试
- 取样请求/响应检查
- 实时通知监控
- 会话管理可见性
测试设置
重要:要运行与Reddit交互的测试,您需要先完成OAuth流程:
- 启动服务器并打开MCP检查器:
# Build and start the server
npm run build
node build/index.js
# In another terminal, open the MCP Inspector
npx @modelcontextprotocol/inspector build/index.js- 完成OAuth身份验证:
- 检查员将提示您进行身份验证 - 按照OAuth流程在Reddit上进行授权 - 成功身份验证后,服务器存储令牌
- 保存OAuth令牌以供测试:
- 通过检查器验证后,复制生成的令牌 - 将它们添加到您的 .env 用于持久性测试的文件:
# Add these to your .env after completing OAuth
REDDIT_ACCESS_TOKEN=your_access_token
REDDIT_REFRESH_TOKEN=your_refresh_token运行测试
# Run all tests (requires OAuth tokens in .env)
npm run test
# Run end-to-end tests
npm run e2e使用Docker进行测试
# Build and run with Docker
npm run docker
# Run the server with npx in Docker
docker run --rm -it \
-p 3000:3000 \
-e REDDIT_CLIENT_ID=your_id \
-e REDDIT_CLIENT_SECRET=your_secret \
-e JWT_SECRET=your_jwt_secret \
node:18-alpine \
npx @systemprompt/mcp-server手动测试
# Test OAuth flow manually
curl -X POST http://localhost:3000/mcp/v1/initialize \
-H "Content-Type: application/json" \
-d '{"protocolVersion": "2024-11-05", "capabilities": {}}'
# The response will include auth details if tokens are neededDocker开发
Docker快速入门
# Build and run with docker-compose (recommended)
npm run docker:build-and-run手动Docker命令
# Build image
docker build -t systemprompt-mcp-reddit .
# Run with environment variables
docker run -p 3001:3001 \
-e REDDIT_CLIENT_ID=your_id \
-e REDDIT_CLIENT_SECRET=your_secret \
-e JWT_SECRET=your_jwt_secret \
systemprompt-mcp-redditDocker的环境变量
创建一个 .env 项目根目录中的文件,包含以下变量:
# Required - Reddit OAuth Application Credentials
REDDIT_CLIENT_ID=your_reddit_client_id
REDDIT_CLIENT_SECRET=your_reddit_client_secret
# Optional - Server Configuration
MCP_PORT=3001 # Port for the MCP server (default: 3001)
JWT_SECRET=your_jwt_secret # Secret for JWT signing (default: auto-generated)
DEBUG=true # Enable debug logging (default: false)重要:The docker:build-and-run 命令要求在 .env 文件或导出到shell中。如果没有正确的Reddit凭据,OAuth流将无法工作。
📁 代码结构
systemprompt-mcp-reddit/
├── src/
│ ├── index.ts # Main entry point
│ ├── server.ts # HTTP server setup
│ ├── server/ # Server infrastructure
│ │ ├── mcp.ts # MCP protocol handler with session management
│ │ ├── oauth.ts # OAuth 2.1 implementation
│ │ ├── middleware.ts # Express middleware (rate limiting, auth)
│ │ ├── auth-store.ts # Authentication storage
│ │ └── config.ts # Server configuration
│ ├── handlers/ # Request handlers
│ │ ├── tool-handlers.ts # Tool execution and validation
│ │ ├── prompt-handlers.ts # Prompt processing
│ │ ├── resource-handlers.ts # Resource management
│ │ ├── sampling.ts # AI sampling implementation
│ │ ├── notifications.ts # Real-time notifications
│ │ ├── callbacks/ # Sampling callback handlers
│ │ └── tools/ # Individual tool implementations
│ ├── services/ # Business logic
│ │ └── reddit/ # Reddit API integration
│ ├── constants/ # Configuration and definitions
│ │ ├── tools.ts # Tool definitions
│ │ ├── resources.ts # Resource definitions
│ │ ├── sampling/ # Sampling prompt templates
│ │ ├── server/ # Server configuration constants
│ │ └── tool/ # Individual tool constants
│ ├── types/ # TypeScript definitions
│ │ ├── reddit.ts # Reddit-specific types
│ │ ├── config.ts # Configuration types
│ │ ├── sampling.ts # Sampling types
│ │ └── request-context.ts # Request context types
│ └── utils/ # Helper functions
│ ├── logger.ts # Logging utilities
│ ├── reddit-transformers.ts # Reddit data transformers
│ └── validation.ts # Validation utilities
├── scripts/ # Development and testing scripts
├── docker-compose.yml # Docker configuration
├── tsconfig.json # TypeScript configuration
└── package.json # Project configuration关键文件
- src/index.ts:应用程序入口点
- src/server.ts:HTTP服务器设置和Express配置
- src/server/mcp.ts:带会话管理的MCP协议实现
- src/server/oauth.ts:完成OAuth 2.1流程
- src/handlers/tool-handlers.ts:使用Zod验证执行工具
- src/handlers/sampling.ts:AI采样实施
- src/services/reddit/reddit-service.ts:Reddit API集成
🤝 贡献
我们欢迎捐款!请查看我们的 贡献指南 了解详情。
开发流程
- 分叉存储库
- 创建要素分支
- 通过测试进行更改
- 提交拉取请求
代码的风格
- 对所有代码使用TypeScript
- 遵循现有模式
- 为公共API添加JSDoc注释
- 包括新功能的测试
🔗 相关项目
- 交互式实施指南:现场测试和教程
- MCP规范:MCP官方文件
- systemprompt.io文档:平台文档
📄 许可证
此项目根据MIT许可证获得许可-请参阅 许可证 文件以获取详细信息。
🙏 致谢
______________________________________________________________________
内置于❤️ 由 系统提示.io 团队
如需支持,请加入我们 Discord 的中文翻译是“不和谐”或“纷争”。 或联系 推特
