Welcome! At Tadata, we typically builds tech to help companies launch Model Context Protocol (MCP) servers.
In our spare time, however, we've played around with using the MCP in a more unique way to power this escape room game. It's an interactive text-based adventure where you are trapped in an escape room. Players must navigate the room, solve puzzles, and collect items by interacting with an AI to find their way to freedom. This game, beyond being enjoyable to build and play, offers significant insights into the world of MCPs and their increasingly vital role. You can read about these learnings in our blog post.
Start playing right now, online, with our hosted version of the game.
As mentioned, this game leverages the power of the MCP. Here's a breakdown of its architecture:
This project consists of two main components: the client and the server.
- Client (
client/
): A Python application that manages user interaction and communicates with the game server. It's responsible for taking user input, orchestrating calls to Large Language Models (LLMs), and invoking MCP tools (which map to the various actions you can take within the room) provided by the server. - Server (
server/
): A FastAPI-based server that maintains the game state, handles room logic, and defines all available player actions. This server was transformed into an MCP server in just three lines of code using the open-source FastAPI-MCP project.
-
Clone the repository:
git clone https://github.com/tadata-org/MCP-Game.git cd MCP-Game
-
Install dependencies:
# Install all dependencies pip install -r requirements.txt
-
Set up your environment variables:
# Create a .env file in the client directory to provide your LLM API key echo "ANTHROPIC_API_KEY=your_api_key_here" > client/.env
-
Run the server:
cd server uvicorn behind_bars_fastapi_server:app --reload --port 8000
-
Start the game client:
cd client python game_client.py
-
Follow the instructions to play the game and escape! For the best experience, don't forget to view the images (as they change!) by opening up client/current_room_png.
-
If you finish a game and wish to restart, make sure to restart the server as well (to renew the state of the game)
- Interactive Text Adventure: Navigate the room and perform actions using natural language commands.
- AI-Powered Responses: Experience dynamic and engaging narrative responses based on your actions and the current game state.
- Inventory System: Collect and strategically use items to solve intricate puzzles.
- Visual Elements: Immerse yourself with descriptive images and rich room descriptions that evolve with your progress.
- Built with Python.
- Manages user input/output and orchestrates the game flow.
- Communicates with the server via the MCP protocol.
- Integrates with Anthropic's API for AI responses: one LLM call parses the user's intended action, and a second narrates the result back to the user.
- Utilizes Streamable HTTP for efficient client-server communication.
- FastAPI-based server implementation.
- Transformed into an MCP server using FastAPI-MCP.
- Manages core game logic and room states.
- Handles asset management (for dynamic image generation).
- Each available action in the game is exposed as a dedicated FastAPI endpoint.
- Uses Streamable HTTP to communicate with the client.
This project serves primarily as a proof-of-concept, demonstrating the utility of the MCP in game applications where LLM power is desired. The client-server architecture inherent to the MCP lends itself exceptionally well to such scenarios, where MCP "tools" directly represent the actions available for the LLM (and, by extension, the user) to interact with the game world.
We encourage you to expand upon our single escape room. Consider adding:
- New Rooms: Implement additional room logic and corresponding visual assets.
- New Items and Puzzles: Introduce more complex puzzles and items, offering multiple paths for user interaction.
- AI Enhancements: Experiment with and modify the client's AI interaction logic. The game's quality is significantly influenced by the LLM prompts that power it. We spent considerable time refining these prompts and encourage you to do the same!
We welcome contributions!
- Fork the repository.
- Create a feature branch (
git checkout -b feature/amazing-feature
). - Commit your changes (
git commit -m 'Add some amazing feature'
). - Push to the branch (
git push origin feature/amazing-feature
). - Open a Pull Request.
This project is licensed under the MIT License.
If you encounter any issues or have questions, please open an issue on GitHub.
Enjoy escaping from Behind Bars! 🚪🔑