jussikolehmainen/game-analytics-mcp-server
If you are the rightful owner of game-analytics-mcp-server and would like to certify it and/or have it hosted online, please leave a comment on the right or send an email to dayong@mcphub.com.
The Model Context Protocol (MCP) server is a specialized server designed to facilitate communication and data processing between AI agents and external data sources, particularly in the context of video game analytics.
Game Analytics
An AI-powered app that answers natural language questions about video games. The interface displays real-time events emitted by the agent during query processing, allowing you to observe tool calls and verify calculations before seeing the final answer.
Approach and Time Spent
- Learning: Explored Cloudflare's ecosystem and identified relevant patterns (2 hours)
- Implementation: Built with Workers and used available libraries without using AI assistant (2 hours)
- Iteration: Tried writing an agent loop that can call tools and produce text at any step, then switched to a structured flow (3 hours)
- Debugging: Refined AI behavior and prompts (3 hours)
- UI Development: Created frontend with Claude Code (1 hour)
- Deployment: Set up Pages with Basic Auth (1 hour)
Total time used was at least 10-12 hours.
Architecture
The application uses Cloudflare's edge platform with three main components:
- Frontend (Cloudflare Pages): React app with chat interface
- Chat Agent (Cloudflare Worker): AI agent that plans and executes queries using Workers AI
- MCP Server (Cloudflare Worker): Provides tools to fetch and analyze game data from RAWG API
Request Flow:
Browser → Pages → Chat Agent → MCP Server → RAWG API
The Chat Agent uses a 3-phase approach:
- Planning: Converts natural language to tool calls
- Execution: Fetches data and runs calculations
- Analysis: Generates natural language answers
The MCP Server has two tools:
- fetch_game_data: Fetches data from Rawg.io.
- Input: platforms, genres, dateFrom, dateTo, limit, ordering
- Transformation: maps platform/genre slugs into IDs required by Rawg.io
- Output: list of games
- execute_calculation: Aggregates games data.
- Input: games, groupBy, property, aggregate
- Output: list of numbers
Security
- Pages: Basic HTTP authentication
- Agent-to-MCP: Bearer token authentication
- MCP-to-RAWG: API key authentication
Limitations and constraints
- Agent expects one data fetch followed by one calculation step; queries outside this pattern will fail
- Cold-start time of the app is high
- AI model may struggle with complex queries or hallucinate parameters
- No proper error handling or retries have been implemented
- No LLM query sanitization (CRITICAL!)
- Many LLMs don't support function calling and I wanted to use that natively
- Missing production features like rate-limiting and proper authentication
- Tried to add Cloudflare Zero Trust but adding payment method did not work so resorted to basic auth
Improvements
- Make agent flow more flexible to handle various query patterns
- Add conversation history to support follow-up questions
- Implement proper authentication and rate-limiting
- Add caching layer for RAWG API responses
- Use service bindings between workers instead of HTTP calls
- Improve error handling and retry logic
- Switch to a better AI model and improve prompts to reduce hallucinations
- Actually deploy to production instead of preview URLs
- Continue work on evaluating and visualizing the results
Evaluation
The UI shows a full event trace for each query.
For example, the question “What’s the average rating for PC games released in Q1 2024?” produces:
- Planning: The agent creates tool plans (fetch + calculation)
- Tool Calls: Both MCP tools run, and their raw responses stream into the UI
- Reasoning: The agent interprets the tool outputs
- Final Answer: e.g. "The average rating is approximately 3.99"
This makes the whole chain visible (plan → tool inputs → tool outputs → answer) and provides a base for adding automated answer checking later.
Event log for this query:
Tool response expanded:
Installation
npm install
Local Development
1. Set up environment variables
Create .env files with the following content:
workers/mcp-server/.env
RAWG_API_KEY=your-rawg-api-key
MCP_SERVER_API_KEY=your-mcp-server-auth-token
workers/chat-agent/.env
MCP_SERVER_API_KEY=your-mcp-server-auth-token
MCP_SERVER_URL=http://localhost:8788
2. Start all services
Run in three separate terminals:
Terminal 1:
npm run dev:mcp
Terminal 2:
npm run dev:chat
Terminal 3:
npm run dev
Open http://localhost:5173 in your browser.
Deployment
1. Deploy MCP Server
npx wrangler secret put RAWG_API_KEY -c workers/mcp-server/wrangler.jsonc
npx wrangler secret put MCP_SERVER_API_KEY -c workers/mcp-server/wrangler.jsonc
npm run deploy:mcp
Note the deployed URL.
2. Deploy Chat Agent
npx wrangler secret put MCP_SERVER_URL -c workers/chat-agent/wrangler.jsonc
npx wrangler secret put MCP_SERVER_API_KEY -c workers/chat-agent/wrangler.jsonc
wrangler deploy -c workers/chat-agent/wrangler.jsonc
Note the deployed URL.
3. Deploy Frontend
npm run deploy
4. Configure Pages Environment Variables
In Cloudflare dashboard → Workers & Pages → game-analytics → Settings → Environment variables:
Required:
CHAT_AGENT_URL= your chat agent URL from step 2
Optional (for basic auth):
BASIC_AUTH_USER= usernameBASIC_AUTH_PASS= password
Redeploy after adding variables.