refactor: load MCP guide from external file
Browse files- .gitignore +2 -1
- app.py +6 -52
- docs/mcp_guide.md +49 -0
.gitignore
CHANGED
|
@@ -4,7 +4,8 @@ __pycache__/
|
|
| 4 |
*.egg-info/
|
| 5 |
|
| 6 |
# Internal documents
|
| 7 |
-
/docs/
|
|
|
|
| 8 |
|
| 9 |
# Common files
|
| 10 |
*.log
|
|
|
|
| 4 |
*.egg-info/
|
| 5 |
|
| 6 |
# Internal documents
|
| 7 |
+
/docs/internal/
|
| 8 |
+
/docs/tasks/
|
| 9 |
|
| 10 |
# Common files
|
| 11 |
*.log
|
app.py
CHANGED
|
@@ -5,6 +5,7 @@ import sys
|
|
| 5 |
sys.path.insert(0, os.path.join(os.path.dirname(__file__), "src"))
|
| 6 |
|
| 7 |
import logging
|
|
|
|
| 8 |
|
| 9 |
import gradio as gr
|
| 10 |
import spaces
|
|
@@ -23,6 +24,10 @@ logger = logging.getLogger(__name__)
|
|
| 23 |
|
| 24 |
logger.info(f"ZeroGPU: {spaces.config.Config.zero_gpu}")
|
| 25 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
# Constants
|
| 27 |
NO_GAME_MESSAGE = "_No active game. Click 'Start New Game' to begin._"
|
| 28 |
|
|
@@ -294,58 +299,7 @@ _{personality_desc}_"""
|
|
| 294 |
|
| 295 |
# MCP Server Tab
|
| 296 |
with gr.TabItem("MCP Server"):
|
| 297 |
-
gr.Markdown(
|
| 298 |
-
"""
|
| 299 |
-
## MCP Server Guide
|
| 300 |
-
|
| 301 |
-
This application functions as an **MCP (Model Context Protocol) Server**.
|
| 302 |
-
External LLMs can connect to this server and use game management tools.
|
| 303 |
-
|
| 304 |
-
### Connection URL
|
| 305 |
-
|
| 306 |
-
```
|
| 307 |
-
https://<space-name>.hf.space/gradio_api/mcp/
|
| 308 |
-
```
|
| 309 |
-
|
| 310 |
-
For local development:
|
| 311 |
-
```
|
| 312 |
-
http://localhost:7860/gradio_api/mcp/
|
| 313 |
-
```
|
| 314 |
-
|
| 315 |
-
### How to Connect
|
| 316 |
-
|
| 317 |
-
#### Claude Desktop / Cursor / VS Code
|
| 318 |
-
|
| 319 |
-
Add the following to your MCP settings configuration:
|
| 320 |
-
|
| 321 |
-
```json
|
| 322 |
-
{
|
| 323 |
-
"mcpServers": {
|
| 324 |
-
"unpredictable-lord": {
|
| 325 |
-
"url": "https://<space-name>.hf.space/gradio_api/mcp/"
|
| 326 |
-
}
|
| 327 |
-
}
|
| 328 |
-
}
|
| 329 |
-
```
|
| 330 |
-
|
| 331 |
-
### Available Tools
|
| 332 |
-
|
| 333 |
-
| Tool | Description |
|
| 334 |
-
|------|-------------|
|
| 335 |
-
| `init_game` | Initialize a new game session. Returns a session_id and available advice options. |
|
| 336 |
-
| `get_game_state` | Get the current game state for a session. |
|
| 337 |
-
| `list_available_advice` | Get all available advice options for execute_turn. |
|
| 338 |
-
| `execute_turn` | Execute a turn with the given advice. Returns whether advice was adopted and results. |
|
| 339 |
-
|
| 340 |
-
### Usage Flow
|
| 341 |
-
|
| 342 |
-
1. Call `init_game(personality)` to start a new game session
|
| 343 |
-
2. User gives free-form advice to the Lord AI
|
| 344 |
-
3. Lord AI interprets advice and calls `execute_turn(session_id, advice)`
|
| 345 |
-
4. Lord AI explains the result to the user (adopted/rejected, action taken, effects)
|
| 346 |
-
5. Repeat from step 2 until game over
|
| 347 |
-
"""
|
| 348 |
-
)
|
| 349 |
|
| 350 |
gr.Markdown("### Test: Initialize Game")
|
| 351 |
with gr.Row():
|
|
|
|
| 5 |
sys.path.insert(0, os.path.join(os.path.dirname(__file__), "src"))
|
| 6 |
|
| 7 |
import logging
|
| 8 |
+
from pathlib import Path
|
| 9 |
|
| 10 |
import gradio as gr
|
| 11 |
import spaces
|
|
|
|
| 24 |
|
| 25 |
logger.info(f"ZeroGPU: {spaces.config.Config.zero_gpu}")
|
| 26 |
|
| 27 |
+
# Load MCP guide from external file
|
| 28 |
+
MCP_GUIDE_PATH = Path(__file__).parent / "docs" / "mcp_guide.md"
|
| 29 |
+
MCP_GUIDE_CONTENT = MCP_GUIDE_PATH.read_text(encoding="utf-8")
|
| 30 |
+
|
| 31 |
# Constants
|
| 32 |
NO_GAME_MESSAGE = "_No active game. Click 'Start New Game' to begin._"
|
| 33 |
|
|
|
|
| 299 |
|
| 300 |
# MCP Server Tab
|
| 301 |
with gr.TabItem("MCP Server"):
|
| 302 |
+
gr.Markdown(MCP_GUIDE_CONTENT)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 303 |
|
| 304 |
gr.Markdown("### Test: Initialize Game")
|
| 305 |
with gr.Row():
|
docs/mcp_guide.md
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# MCP Server Guide
|
| 2 |
+
|
| 3 |
+
This application functions as an **MCP (Model Context Protocol) Server**.
|
| 4 |
+
External LLMs can connect to this server and use game management tools.
|
| 5 |
+
|
| 6 |
+
## Connection URL
|
| 7 |
+
|
| 8 |
+
```
|
| 9 |
+
https://<space-name>.hf.space/gradio_api/mcp/
|
| 10 |
+
```
|
| 11 |
+
|
| 12 |
+
For local development:
|
| 13 |
+
|
| 14 |
+
```
|
| 15 |
+
http://localhost:7860/gradio_api/mcp/
|
| 16 |
+
```
|
| 17 |
+
|
| 18 |
+
## How to Connect
|
| 19 |
+
|
| 20 |
+
### Claude Desktop / Cursor / VS Code
|
| 21 |
+
|
| 22 |
+
Add the following to your MCP settings configuration:
|
| 23 |
+
|
| 24 |
+
```json
|
| 25 |
+
{
|
| 26 |
+
"mcpServers": {
|
| 27 |
+
"unpredictable-lord": {
|
| 28 |
+
"url": "https://<space-name>.hf.space/gradio_api/mcp/"
|
| 29 |
+
}
|
| 30 |
+
}
|
| 31 |
+
}
|
| 32 |
+
```
|
| 33 |
+
|
| 34 |
+
## Available Tools
|
| 35 |
+
|
| 36 |
+
| Tool | Description |
|
| 37 |
+
|------|-------------|
|
| 38 |
+
| `init_game` | Initialize a new game session. Returns a session_id and available advice options. |
|
| 39 |
+
| `get_game_state` | Get the current game state for a session. |
|
| 40 |
+
| `list_available_advice` | Get all available advice options for execute_turn. |
|
| 41 |
+
| `execute_turn` | Execute a turn with the given advice. Returns whether advice was adopted and results. |
|
| 42 |
+
|
| 43 |
+
## Usage Flow
|
| 44 |
+
|
| 45 |
+
1. Call `init_game(personality)` to start a new game session
|
| 46 |
+
2. User gives free-form advice to the Lord AI
|
| 47 |
+
3. Lord AI interprets advice and calls `execute_turn(session_id, advice)`
|
| 48 |
+
4. Lord AI explains the result to the user (adopted/rejected, action taken, effects)
|
| 49 |
+
5. Repeat from step 2 until game over
|