D&D MCP服务器
一组用于玩《龙与地下城》的模型上下文协议(MCP)服务器。
项目结构
该项目遵循组织多个MCP服务器的标准结构:
dnd_MPC/
├── src/
│ └── servers/
│ ├── DnD_dice/ # Dice rolling server
│ │ ├── __init__.py
│ │ ├── server.py
│ │ ├── tools.py
│ │ ├── dice_roller.py
│ │ └── README.md
│ ├── DnD_character/ # Character management server
│ │ ├── __init__.py
│ │ ├── server.py
│ │ ├── tools.py
│ │ ├── character_manager.py
│ │ └── README.md
│ ├── DnD_monster/ # Monster management server
│ │ ├── __init__.py
│ │ ├── server.py
│ │ ├── tools.py
│ │ ├── monster_manager.py
│ │ └── README.md
│ └── hello_world/ # Hello World example server
│ ├── __init__.py
│ └── server.py
├── tests/ # Test files
├── pyproject.toml # Project configuration and dependencies
├── README.md # This file
└── .gitignoreMCP框架
该项目使用官方 模型上下文协议Python SDK 构建MCP服务器。
什么是MCP?
模型上下文协议(MCP)是一种开放协议,可实现LLM应用程序与外部数据源和工具之间的无缝集成。它提供了一种标准化的方式,将人工智能模型与它们所需的上下文连接起来。
入门指南
先决条件
- Python 3.10或更高版本
- pip(Python包安装程序)
安装
- 克隆存储库:
git clone https://github.com/clydewatts1/dnd_MPC.git
cd dnd_MPC- 安装依赖项:
pip install -e .使用测试工具进行开发:
pip install -e ".[dev]"可用服务器
1.DnDic服务器
模拟D&D游戏的骰子滚动,支持标准骰子符号。
特征:
- 滚动D4、D6、D8、D10、D12、D20的任意组合
- 支持复杂符号(例如。,
2d6+3,1d20,2d3 + 1d6) - 详细的滚动故障
正在运行:
python -m src.servers.DnD_dice.server看 DnDice/README.md 了解详情。
2.DnD字符服务器
管理D&D角色数据,包括生命点、魔法点和属性。
特征:
- 创建、更新、检索、列出和删除字符
- 追踪当前/最大生命值和魔法点数
- 灵活的角色属性(力量、灵巧性等)
正在运行:
python -m src.servers.DnD_character.server看 DnD_character/README.md 了解详情。
3.DnD怪物服务器
管理战斗遭遇和NPC的D&D怪物数据。
特征:
- 创建、更新、检索、列出和删除怪物
- 追踪当前/最大生命值和魔法点数
- 怪物特定属性(挑战等级、护甲等级等)
正在运行:
python -m src.servers.DnD_monster.server看 DnD_怪物/README.md 了解详情。
4.Hello World服务器
一个简单的MCP服务器示例,演示基本功能。
特性
- 工具:
say_hello-返回问候信息
- 可选的 name 参数(默认为“World”) - 返回自定义的问候消息
运行Hello World服务器
python src/servers/hello_world/server.py服务器使用MCP协议通过stdin/stdout进行通信。
MCP检验员测试
您可以使用MCP检查器工具测试服务器:
npx @modelcontextprotocol/inspector python src/servers/hello_world/server.py示例用法
连接到MCP客户端后,您可以:
- 列出可用工具以供查看
say_hello - 使用以下命令调用该工具:
- 无参数:返回“Hello,World!欢迎使用D&D MCP服务器!” - 姓名: {"name": "Gandalf"} return“你好,甘道夫!欢迎来到D&D MCP服务器!”
MCP检验员测试
您可以使用MCP检查器工具测试任何服务器:
# Test dice server
npx @modelcontextprotocol/inspector python -m src.servers.DnD_dice.server
# Test character server
npx @modelcontextprotocol/inspector python -m src.servers.DnD_character.server
# Test monster server
npx @modelcontextprotocol/inspector python -m src.servers.DnD_monster.server
# Test hello world server
npx @modelcontextprotocol/inspector python src/servers/hello_world/server.py添加新服务器
要添加新的MCP服务器,请执行以下操作:
- 在下创建新目录
src/servers/:
mkdir src/servers/your_server_name- 创建
__init__.py和server.py新目录中的文件
- 遵循hello_world服务器的结构作为模板
- 根据需要实施服务器的工具、资源和提示
项目目标
该项目旨在作为构建MCP服务器的学习资源。重点是:
- 了解MCP协议
- 学习如何在Python中实现MCP服务器
- 为D&D游戏创建模块化、可重用的服务器组件
- 演示不同的服务器模式(掷骰子、实体管理等)
发展
运行测试
# Run all tests
pytest
# Run specific test file
pytest tests/test_dice_roller.py项目结构模式
每台服务器都遵循以下模式:
server.py-MCP服务器设置和工具路由tools.py-工具定义和执行功能*_manager.py或*_roller.py-核心业务逻辑README.md-服务器特定文档
许可证
有关详细信息,请参阅LICENSE文件。
