Spaces:
Sleeping
Sleeping
File size: 2,854 Bytes
551ad28 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# MCP (Model Context Protocol) Integration
This document explains how to use the MCP integration for the RTS Commander game.
## Overview
The MCP integration allows AI agents to interact with the RTS game through the Model Context Protocol. It exposes game state information and provides tools for performing actions in the game.
## Architecture
The MCP server runs on port 8001 and provides:
1. **Tools** - Functions that AI agents can call to interact with the game
2. **Resources** - Static information about the game (documentation, rules)
## Available Tools
### get_game_state()
Returns the current state of the game as JSON, including:
- Units (infantry, tanks, helicopters, harvesters)
- Buildings (HQ, power plants, barracks, etc.)
- Player resources (credits, power)
- Map terrain information
### get_ai_analysis(language="en")
Returns AI tactical analysis of the current game state in the specified language.
### move_units(unit_ids, target_x, target_y)
Moves the specified units to the target position.
### attack_unit(attacker_ids, target_id)
Commands the specified units to attack an enemy unit.
### build_building(building_type, position_x, position_y, player_id=0)
Builds a building at the specified position.
### send_game_command(command_type, **kwargs)
Sends a generic command to the game.
## Available Resources
### game_documentation
Provides the game's README documentation.
### game_rules
Provides the game's architecture and rules documentation.
## Running the MCP Server
To start the MCP server:
```bash
cd web
python mcp_server.py
```
The server will start on port 8001.
## Connecting an AI Client
AI clients can connect to the MCP server using any MCP-compatible client library. For example, with Claude:
```bash
claude --mcp-server localhost:8001
```
## Example Usage
An AI agent might use the MCP integration to:
1. Get the current game state
2. Analyze the tactical situation
3. Make strategic decisions
4. Execute actions in the game
## Implementation Details
The MCP server is implemented in `mcp_server.py` and uses the existing game infrastructure:
- It accesses the game state through the `manager` instance from `app.py`
- It sends commands using the existing `handle_command` method
- It integrates with the existing AI analysis system
## Extending the Integration
To add new tools or resources:
1. Add new methods to the `_register_tools` or `_register_resources` methods in `RTSGameMCP`
2. Implement the functionality using existing game infrastructure
3. Test the new functionality
## Security Considerations
The MCP server runs on a separate port (8001) from the main game server (7860) to isolate AI access from player connections.
In a production environment, you should consider:
- Authentication for MCP clients
- Rate limiting for commands
- Input validation for all commands |