- Poké-Battle
Poké-Battle
This is a Pokemon game built with FastAPI and Python, leveraging Anthropic's Claude AI through a custom Model Context Protocol (MCP) server and client. It features real-time battles and utilizes AI for creative battle descriptions, attack recommendations, and generating unique personalities for caught Pokemon.
Tech Stack
- Backend: FastAPI, Uvicorn (ASGI server)
- AI Integration: Anthropic's Claude API, custom Model Context Protocol (MCP) server (
mcp_server.py) and client (mcp_client.py) - External API: PokeAPI
- Frontend: HTML, CSS, JavaScript (served by FastAPI)
- Dependencies: python-dotenv, httpx, websockets, Jinja2
Setup Instructions
-
Clone the repository:
git clone <repository_url> cd <repository_directory> -
Create a virtual environment:
python -m venv .venv -
Activate the virtual environment:
- On Windows:
.venv\Scripts\activate - On macOS and Linux:
source .venv/bin/activate
- On Windows:
-
Install dependencies:
pip install -r requirements.txt -
Set up your Anthropic API Key:
- Create a file named
.envin the root directory. - Add your Anthropic API key in the following format:
ANTHROPIC_API_KEY=your_api_key_here
Note: For security, it's recommended to manage API keys using environment variables provided by your hosting environment rather than storing them in a
.envfile, especially in production. - Create a file named
-
Run the MCP Server: Open your terminal in the project root and run:
uvicorn mcp_server:app --reload --port 8000 -
Run the Main Game Server: Open a new terminal in the project root (and activate the virtual environment if necessary) and run:
uvicorn server:app --reload --port 8080 -
Open the game in your browser: Go to
http://localhost:8080
Project Structure
server.py: Main FastAPI application handling game logic and serving the frontend.mcp_server.py: FastAPI application acting as the Model Context Protocol server, handling communication with the Anthropic API.mcp_client.py: Python client library used byserver.pyto communicate withmcp_server.py.index.html: The main frontend HTML file.static/: Directory for static assets (CSS, JavaScript, images - although currently only the directory is present).requirements.txt: Lists the Python dependencies.api.env: Environment file to load the API key (should be added to.gitignore)..gitignore: Specifies intentionally untracked files that Git should ignore.
Features
- Pokemon Catching: Catch random Pokemon to build your team.
- Pokemon Battles: Turn-based battles against a random opponent Pokemon.
- AI Battle Descriptions: Creative commentary for battle actions generated by Anthropic's Claude.
- AI Attack Recommendations: Get AI suggestions for the best move to use in battle.
- AI Pokemon Personalities: Each caught Pokemon gets a unique, AI-generated personality trait or backstory.
- Real-time Updates: Game state and messages updated via WebSocket.
- MCP Implementation: Demonstrates using a Model Context Protocol for AI model interaction.
- Responsive UI: Basic UI adjustments for better display of caught Pokemon.