RPG MCP 服务器
一个基于模型上下文协议(MCP)构建的沉浸式角色扮演游戏服务器,旨在与Claude等AI助手协同工作,以创造互动式的故事叙述体验。
特点/特性
🎮 游戏工具
该服务器提供了7款核心工具,用于构建和管理角色扮演游戏(RPG):
createGame- 初始化一个新的角色扮演游戏(RPG)
- 设置初始游戏状态(角色、世界、物品栏等) - 自动生成唯一的游戏ID
updateGame- 更新游戏状态
- 支持嵌套字段路径(例如。, characters[0].level, world.location) - 使用Delta系统进行实时变更跟踪 - 游戏结束支持: 如果状态更新导致游戏结束(例如,生命值降至0,游戏坏结局),则设置 isGameOver=true 并提供一个 gameOverReason服务器将返回一个特殊的“游戏结束”用户界面,其中包含体贴的解释以及改进建议。
getGame- 获取当前游戏状态
- 随时访问完整游戏状态
progressStory- 推进故事情节
- 记录当前情况和事件 - 管理叙事流程
promptUserActions- 向用户展示当前的行动选项
- 动态选择: 始终提供2-4个选项,这些选项应包含正面和负面结果的混合,以打造动态、引人入胜的游戏体验。每个选项都应具有明确的后果以及风险与回报的权衡。 - 生成交互式用户界面 - 基于网络的动作选择界面
selectAction- 处理用户选择
- 将选定的操作应用于游戏状态 - 自动记录游戏历史
selectRestart- 游戏结束后重新开始
- 当玩家在游戏结束屏幕点击重启按钮时调用 - 提供游戏概述及创建新游戏的背景信息 - AI代理收到指导,以创建一个符合情境的新冒险
🎯 用户互动
基本游戏流程
createGame → progressStory → promptUserActions → selectAction → updateGame → progressStory → ...游戏结束 & 重新开始流程
当游戏结束时(例如,角色生命值降至0或故事达到结局):
updateGame (isGameOver=true) → Game Over UI displayed →
User clicks Restart button → selectRestart →
AI creates new game with context → progressStory → ...重启流程包括:
- 上下文保持之前的比赛总结已提供给人工智能
- AI建议的续写人工智能可以创造出主题相关或逐步发展的冒险故事
- 一键重启玩家无需手动干预
- 富有同理心的信息传达游戏结束画面解释了发生的情况并提出了改进建议
交互式用户界面
- 基于网页的选择界面随着故事进展自动生成的精美用户界面
- 实时变化显示通过Delta系统提供对近期更改的视觉反馈
- 游戏结束屏幕当游戏结束时,会弹出一个特殊的用户界面,解释游戏结束的原因、本可以采取的不同做法,并包含一个重新开始按钮
- 游戏历史自动保存最近10条情境-选择记录
- 重启按钮游戏结束屏幕上的交互式按钮,触发后
selectRestart工具
示例游戏场景
// 1. Create Game
{
"title": "Wizard's Adventure",
"characters": [
{"name": "Elara", "level": 1, "hp": 100, "mp": 50, "class": "Wizard"}
],
"world": {"location": "Magic Academy", "time": "morning", "weather": "sunny"},
"inventory": [{"name": "Magic Staff", "type": "weapon"}]
}
// 2. Progress Story
"Elara discovers an ancient spellbook in the academy library..."
// 3. Present Choices (always mix positive/negative outcomes)
[
"Read the spellbook (may gain power, but risk a curse)",
"Tell the professor (safe, but lose a chance for secret knowledge)",
"Leave it where it is (avoid risk, but miss opportunity)",
"Try to sell it secretly (potential reward, but risk being caught)"
]
// 4. Update game state after user selection
"characters[0].hp": 0, // triggers game over
"isGameOver": true,
"gameOverReason": "Elara triggered a powerful curse from the spellbook and lost all HP. If you had chosen to consult the professor or left the book alone, you might have avoided this fate."MCP客户端需求
基本要求
- MCP协议支持MCP SDK 0.5.0或更高版本
- MCP-UI 集成HTML资源渲染支持
- 工具执行能够执行所有6种游戏工具
推荐的客户端
- Claude Desktop(可译为“Claude桌面版”) (官方支持)
- 与MCP-UI兼容的客户端
- 备选方案: 突触流动 以及其他兼容MCP-UI的客户端
Claude 桌面版设置
步骤1:定位配置文件
特定平台的配置文件位置:
- macOS(发音类似“麦奥斯”,但通常直接称为“Mac OS”或简化为“OS”在提及苹果操作系统的上下文中):
~/Library/Application Support/Claude/claude_desktop_config.json - Windows:
%APPDATA%/Claude/claude_desktop_config.json - Linux:
~/.config/Claude/claude_desktop_config.json
步骤2:编辑配置文件
{
"mcpServers": {
"rpg-game-server": {
"command": "npx",
"args": ["rpg-mcp-server"],
"env": {
"NODE_ENV": "production"
}
}
}
}步骤3:重启Claude桌面版
完全退出并重新启动 Claude Desktop 以应用配置。
步骤4:测试设置
Hi! Can you create a fantasy RPG game for me?安装与使用
全局安装(推荐)
npm install -g rpg-mcp-server本地开发
git clone
cd rpg-mcp-server
npm install
npm run build
npm start使用MCP Inspector进行测试
npm run inspector技术栈
- TypeScript - 类型安全和开发者体验
- MCP SDK(MCP软件开发工具包) - 模型上下文协议实现
- MCP-UI(可能指“Multi-Channel Protocol User Interface”或类似含义,具体需根据上下文确定) - 交互式网页用户界面生成
- Node.js - 运行时环境
系统要求
- Node.js 18.0.0或更高版本
- npm(Node Package Manager,节点包管理器) 9.0.0或更高版本
- 与MCP兼容的客户端
许可证
MIT 许可证 - 请参阅 许可证 文件中详述。
