神奇宝贝战斗模拟-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______________________________________________________________________
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)
- 查找Claude MCP配置文件夹:
- macOS: ~/Library/Application Support/Claude/ - 窗户: %AppData%\Claude\ - Linux: ~/.config/Claude/
- 编辑(或创建)
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启动时导入工作正常。
- 重新启动克劳德桌面 加载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 多亏了 斯科佩利 为了机会。
______________________________________________________________________
