这是一个全面的基于TypeScript的模型上下文协议(MCP)服务器,为AI助手提供高级的骰子滚动功能。非常适合桌面游戏、角色扮演游戏(RPG),以及任何需要具有游戏机制的复杂随机数生成的应用程序。
本MCP服务器可作为AI助手与实际随机数生成之间的桥梁,让AI助手能够提供真正随机的骰子滚动结果。以下是使用该服务器的相关步骤:
claude_desktop_config.json文件。1d20、3d6、2d10等基本表示法。1d20+5、2d6 - 3、1d8*2等修饰符。1d20+2d6+3等多种骰子类型组合。1d%(即d100)。4dF(Fate/Fudge系统)。2d20kh1(保留最高值)、2d20kl1(保留最低值)。4d6dl1(丢弃最低值)、4d6dh1(丢弃最高值)。3d6!(最大值时重新滚动并累加)。4d6r1(重新滚动1点)。5d10>7(统计大于等于7的成功次数)。dice_roll使用标准表示法执行骰子滚动,支持可选的标签和详细输出。
notation(必需):骰子表示法字符串(例如,"3d6+2")。label(可选):滚动的描述性标签。verbose(可选):显示单个骰子的详细分解。dice_validate验证骰子表示法而不执行滚动,并提供表示法含义的详细分解。
notation(必需):要验证的骰子表示法字符串。git clone https://github.com/jimmcq/dice-rolling-mcp
cd dice-rolling-mcp
npm install
npm run build
Human: Roll 3d6+2 for damage
Assistant: You rolled 3d6+2 for damage:
🎲 Total: 13
📊 Breakdown: 3d6:[4,2,5] + 2
Human: Roll 2d20kh1+5 for attack with advantage
Assistant: You rolled 2d20kh1+5 for attack with advantage:
🎲 Total: 23
📊 Breakdown: 2d20:[12,18] keep highest + 5
Human: Is "4d6kh3+2d8+5" valid dice notation?
Assistant: ✅ Valid dice notation: 4d6kh3+2d8+5
Breakdown:
• 4d6 (keep highest 3)
• 2d8
• Modifier: +5
本服务器已部署,可与Claude Desktop配合使用。配置claude_desktop_config.json文件如下:
{
"mcpServers": {
"dice-rolling-remote": {
"command": "npx",
"args": [
"@modelcontextprotocol/client-stdio",
"connect",
"https://dice-rolling-mcp.vercel.app/mcp"
]
}
}
}
在claude_desktop_config.json中添加以下配置:
{
"mcpServers": {
"dice-roller": {
"command": "node",
"args": ["path/to/dice-rolling-mcp/dist/index.js"]
}
}
}
特定平台示例: Windows (WSL):
{
"mcpServers": {
"dice-roller": {
"command": "wsl",
"args": ["node", "/path/to/dice-rolling-mcp/dist/index.js"]
}
}
}
macOS/Linux:
{
"mcpServers": {
"dice-roller": {
"command": "node",
"args": ["/path/to/dice-rolling-mcp/dist/index.js"]
}
}
}
npm run start
dice-rolling-mcp/
├── src/
│ ├── index.ts # MCP server implementation
│ ├── parser/ # Dice notation parser
│ ├── roller/ # Dice rolling engine
│ ├── statistics/ # Statistical analysis tools
│ └── types.ts # TypeScript definitions
├── __tests__/ # Test suite
├── dist/ # Compiled JavaScript
└── examples/ # Usage examples
types.ts中扩展DiceTerm接口。dice-notation-parser.ts中的解析器正则表达式。dice-roller.ts中实现新机制。服务器通过DiceRollerConfig接口支持各种配置选项:
src/parser/):使用基于正则表达式的解析方法对骰子表示法进行分词和解析。src/roller/):使用加密安全的随机数生成执行骰子表达式。src/index.ts):实现用于AI助手集成的模型上下文协议。src/types.ts):为所有骰子机制提供全面的TypeScript定义。crypto.randomInt()实现加密安全的随机性。npm test
测试套件覆盖以下内容:
| 属性 | 详情 |
|---|---|
| 语言 | TypeScript 5.8+ |
| 运行时 | Node.js 18+(已在v24.0.2上测试) |
| 协议 | MCP(模型上下文协议)2024 - 11 - 05 |
| 依赖项 | 最少(zod,@modelcontextprotocol/sdk) |
| 模块系统 | ES模块 |
| 测试框架 | Jest with ts - jest |
本项目采用ISC许可证。
欢迎贡献代码!请确保:
npm test)。Jim McQuillan