import gradio as gr import anthropic import os import json import re import html as html_module import asyncio from mcp import ClientSession, StdioServerParameters from mcp.client.stdio import stdio_client # Anthropic client client = anthropic.Anthropic() # MCP Server configurations STEAM_MCP_SERVER = StdioServerParameters( command="python", args=["tools/steam_mcp_server.py"], env={ "STEAM_API_KEY": os.getenv("STEAM_API_KEY", ""), "ANTHROPIC_API_KEY": os.getenv("ANTHROPIC_API_KEY", ""), } ) IGDB_MCP_SERVER = StdioServerParameters( command="uvx", args=["--from", "git+https://github.com/bielacki/igdb-mcp-server.git", "igdb-mcp-server"], env={ # IGDB MCP server expects IGDB_CLIENT_ID/SECRET (these are Twitch credentials) "IGDB_CLIENT_ID": os.getenv("IGDB_CLIENT_ID", ""), "IGDB_CLIENT_SECRET": os.getenv("IGDB_CLIENT_SECRET", "") } ) # System prompt for the agent SYSTEM_PROMPT = """You are Dream Game Forge, an autonomous agent that discovers what game a person truly needs. Your process: 1. INVESTIGATE: When a user provides their Steam ID, announce that you're connecting to the Steam MCP server, then fetch their library using the get_steam_library tool. Briefly mention the MCP connection in your response (e.g., "Connecting to Steam MCP server to fetch your library..."). Note playtime patterns - what do they sink hundreds of hours into? What do they buy and never play? 2. ENRICH: For the user's top 3-5 most played games, announce that you're querying the IGDB MCP server for enrichment, then use search_games tool to fetch detailed genre, theme, platform, and rating data. Mention the MCP usage (e.g., "Querying IGDB MCP server for game metadata..."). This provides deeper insight into what truly resonates with them. 3. ANALYZE: Build a taste profile from their gaming patterns combining Steam playtime data with IGDB genre/theme insights. Identify patterns in mechanics, pacing, and emotional engagement. 4. COLLABORATE: Present your analysis findings to the user with a summary of their gaming DNA. Then ask: "Anything you'd like me to consider? (play session length, themes to avoid, specific mechanics you enjoy, etc.)" - WAIT for the user's response before proceeding - This is a REQUIRED step - do not skip to game generation without user input - If they say "no" or "nothing", that's fine, proceed to design 5. IDENTIFY THE GAP: Based on your analysis AND the user's input, determine what game *should* exist for this person but doesn't. Be specific and creative, incorporating their preferences. 6. DESIGN: Write a mini Game Design Document - core loop, unique mechanic, emotional hook, incorporating user preferences from the collaboration phase. 7. BUILD: Generate a playable HTML5 Canvas prototype that captures the game concept. CRITICAL - Game Generation Requirements: STRUCTURE & POLISH: - Create a COMPLETE, self-contained HTML file (no external dependencies) - Use HTML5 Canvas for rendering - Include all CSS in