宝可梦对战模拟器

一个基于FastAPI的宝可梦对战模拟服务器,提供宝可梦数据查询和战斗模拟功能,适用于游戏开发和AI训练场景。

  • by DimpleKundu
  • Python
  • 本地部署
  • 更新于
在 GitHub 查看 dimplekundu/pokemon-battle-mcp-server

使用说明

神奇宝贝战斗模拟-MCP服务器

快速开始

git clone https://github.com/your-username/pokeaiagent.git
cd pokeaiagent
pip install -r requirements.txt
python -m server.mcp_server

服务器将启动并等待MCP兼容客户端(如Claude Desktop)连接。


需求

  • python 3.10+ (3.13测试)
  • 互联网连接(使用 PokéAPI)

安装

git clone https://github.com/your-username/pokeaiagent.git
cd pokeaiagent

python -m venv venv
# Windows
venv\Scripts\activate
# macOS/Linux
source venv/bin/activate

pip install -r requirements.txt

运行MCP服务器

直接运行:

python -m server.mcp_server

或通过FastAPI进行API测试:

uvicorn server.main:app --reload

访问 http://127.0.0.1:8000.


FastAPI端点

端点 方法 描述
/ GET 返回欢迎消息: {"message": "MCP Pokemon Server"}
/pokemon/{name} 获取 按名称获取Pokémon数据(使用PokéAPI)
/battle/{p1}/{p2} GET 模拟两个神奇宝贝之间的战斗

示例用法:

GET /pokemon/pikachu
# Returns Pikachu's data

GET /battle/pikachu/bulbasaur
# Returns simulated battle results

代码片段(server/main.py):

from fastapi import FastAPI
from server.data import fetch_pokemon
from server.battle import simulate_battle

app = FastAPI()

@app.get("/")
def root():
    return {"message": "MCP Pokemon Server"}

@app.get("/pokemon/{name}")
def get_pokemon(name: str):
    return fetch_pokemon(name)

@app.get("/battle/{p1}/{p2}")
def battle(p1: str, p2: str):
    return simulate_battle(p1, p2)

项目结构

pokeaiagent/
│
├── server/
│   ├── __init__.py
│   ├── battle.py         # Battle mechanics
│   ├── data.py           # Pokémon data fetcher
│   ├── main.py           # FastAPI app with endpoints
│   └── mcp_server.py     # MCP server entrypoint
│
├── requirements.txt
└── README.md

连接到克劳德桌面(MCP)

  1. 查找Claude MCP配置文件夹:

    • macOS: ~/Library/Application Support/Claude/
    • 窗户: %AppData%\Claude\
    • Linux: ~/.config/Claude/
  2. 编辑(或创建) claude_desktop_config.json 并添加:

{
  "mcpServers": {
    "pokemon": {
      "command": "python",
      "args": [
        "/absolute/path/to/project/server/mcp_server.py"
      ],
      "env": {
        "PYTHONPATH": "/absolute/path/to/project"
      }
    }
  }
}

笔记:

  • 替换 /absolute/path/to/project 使用您实际的本地项目路径。
  • 保持正斜杠 / 为了兼容性。
  • PYTHONPATH 确保从Claude启动时导入工作正常。
  1. 重新启动克劳德桌面 加载MCP服务器。

Claude中的示例用法

1. list tools
2. simulate a battle between pikachu and bulbasaur

提示: simulate a battle between pikachu and bulbasaur

答复:

battle_simulator

What a quick and decisive battle!

Pikachu vs Bulbasaur Battle Summary:

This battle featured two of the most iconic starter Pokémon, but it was surprisingly one-sided. Both Pokémon started with nasty status conditions - Pikachu was burned while Bulbasaur was poisoned.

Turn 1:
- Pikachu struck first but only managed 5 damage against Bulbasaur
- Bulbasaur retaliated with a devastating 23 damage attack, nearly KO'ing Pikachu in one hit!
- Both Pokémon then took damage from their status conditions

Turn 2:
- Pikachu tried again with another weak 5-damage attack
- Bulbasaur finished the job with another 23-damage blow, knocking out Pikachu completely

Result: Bulbasaur wins!

Despite being poisoned and losing HP each turn, Bulbasaur completely dominated with attacks over 4× stronger than Pikachu's moves. Bulbasaur finished with 27 HP remaining, having taken minimal damage. This matchup heavily favored Bulbasaur.

交付物

该项目通过提供以下内容满足MCP技术评估:

  • 宝可梦数据资源(MCP资源)
  • 作战模拟工具(MCP工具)
  • 完整的设置说明
  • 可选FastAPI测试

鸣谢

由开发 Dimple Kundu 多亏了 斯科佩利 为了机会。