Spaces:
Sleeping
Sleeping
Update MCP
Browse files- mcp_server.py +25 -0
mcp_server.py
CHANGED
|
@@ -2,6 +2,9 @@ import os
|
|
| 2 |
import asyncio
|
| 3 |
from dotenv import load_dotenv
|
| 4 |
from mcp.server.fastmcp import FastMCP
|
|
|
|
|
|
|
|
|
|
| 5 |
from app import Room, rooms, get_ai_move_for_room, get_ai_chat_for_room
|
| 6 |
|
| 7 |
load_dotenv()
|
|
@@ -412,6 +415,28 @@ async def wait_5_seconds() -> dict:
|
|
| 412 |
"message": f"Failed to wait: {str(e)}"
|
| 413 |
}
|
| 414 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 415 |
# --- Server Execution ---
|
| 416 |
if __name__ == "__main__":
|
| 417 |
print(f"Tic-Tac-Toe Rooms MCP Server starting on port 7860...")
|
|
|
|
| 2 |
import asyncio
|
| 3 |
from dotenv import load_dotenv
|
| 4 |
from mcp.server.fastmcp import FastMCP
|
| 5 |
+
from fastapi import FastAPI
|
| 6 |
+
from fastapi.staticfiles import StaticFiles
|
| 7 |
+
from fastapi.responses import FileResponse
|
| 8 |
from app import Room, rooms, get_ai_move_for_room, get_ai_chat_for_room
|
| 9 |
|
| 10 |
load_dotenv()
|
|
|
|
| 415 |
"message": f"Failed to wait: {str(e)}"
|
| 416 |
}
|
| 417 |
|
| 418 |
+
# Add web UI routes to the FastMCP server
|
| 419 |
+
@mcp.get("/rooms-ui")
|
| 420 |
+
async def rooms_ui():
|
| 421 |
+
"""Serve the room-based game UI"""
|
| 422 |
+
return FileResponse("room_game.html")
|
| 423 |
+
|
| 424 |
+
@mcp.get("/room_game.js")
|
| 425 |
+
async def room_game_js():
|
| 426 |
+
"""Serve the room game JavaScript"""
|
| 427 |
+
return FileResponse("room_game.js")
|
| 428 |
+
|
| 429 |
+
@mcp.get("/")
|
| 430 |
+
async def root():
|
| 431 |
+
"""Root endpoint with server info"""
|
| 432 |
+
return {
|
| 433 |
+
"name": "Tic-Tac-Toe MCP Server",
|
| 434 |
+
"status": "running",
|
| 435 |
+
"mcp_tools": ["create_room", "make_move", "send_chat", "get_room_state", "list_rooms", "switch_room", "get_help"],
|
| 436 |
+
"web_ui": "/rooms-ui",
|
| 437 |
+
"description": "MCP server for LeChat integration with optional web UI for testing"
|
| 438 |
+
}
|
| 439 |
+
|
| 440 |
# --- Server Execution ---
|
| 441 |
if __name__ == "__main__":
|
| 442 |
print(f"Tic-Tac-Toe Rooms MCP Server starting on port 7860...")
|