# Douyin Mini-Game MCP

> Douyin Mini-Game MCP manages the entire backend for casual mobile games. Your agent connects here to handle user authentication, save/load player progress via cloud storage, manage leaderboards, and check all user-generated content against policy violations.

## Overview
- **Category:** industry-titans
- **Price:** Free
- **Tags:** douyin, mini-game, cloud-save, leaderboard, content-moderation, casual-gaming

## Description

Building a game means managing more than just the front end. You've got logins, persistent data, scores, and moderation queues—all running on separate systems. This MCP connects your agent directly to that backend. Instead of jumping between developer consoles or writing multiple API calls, you talk to your AI client, and it handles the whole lifecycle. Your agent can first run `code2session` to get a user online, then use `set_user_storage` to save their current level and high score. When they post content, it runs `check_content_security`. If they play again later, your agent retrieves everything using `get_user_info` and `get_user_storage`, all while tracking metrics with `get_analytics`. Everything is available through one place on Vinkius, letting you focus on the game, not the plumbing.

## Tools

### check_content_security
Checks any piece of user-submitted text against Douyin's content rules and reports if it contains prohibited material.

### code2session
Exchanges a temporary login code for the permanent, unique user session tokens needed to access private data.

### get_access_token
Retrieves the necessary server access token required before making any other API call to the mini-game service.

### get_analytics
Gathers core game performance data, including daily active users and overall player retention rates.

### get_game_rank
Retrieves a user's current standing and associated leaderboard details for specific competitive modes.

### get_user_info
Pulls basic profile data about the player, such as their nickname or avatar ID.

### get_user_storage
Reads saved key-value pairs from a user's cloud storage record, like old scores or preferences.

### remove_user_storage
Clears one or more specific keys from a user's stored data, useful for resetting progress.

### set_user_storage
Saves new key-value pairs to the user's cloud storage record, updating their current game state.

### submit_score
Sends a numeric score to the designated leaderboard so players can compete for rank.

## Prompt Examples

**Prompt:** 
```
Get an access token and exchange login code 'abc123' for a user session.
```

**Response:** 
```
✅ Access token obtained. Login code exchanged successfully! User openid: tt_user_123. Session established.
```

**Prompt:** 
```
Save game progress: level 15, score 5000, coins 200 for user tt_user_123.
```

**Response:** 
```
✅ Game data saved! Level 15, score 5000, coins 200 stored in cloud storage for tt_user_123. Data will persist across sessions.
```

**Prompt:** 
```
Check if the nickname 'TestUser123' passes content moderation.
```

**Response:** 
```
✅ Content check passed! 'TestUser123' is safe to use as a nickname. No policy violations detected.
```

## Capabilities

### Manage user login
Exchange a temporary login code for permanent session tokens required to interact with the service.

### Save and retrieve player state
Write or read structured data, like progress points or settings, into a persistent cloud storage bucket tied to a user account.

### Track performance metrics
Pull current game statistics, including daily active users and player retention rates.

### Handle competitive scoring
Submit scores to designated leaderboards or check a user's current rank against competitors.

### Filter content for safety
Check any piece of text submitted by a user to ensure it doesn't violate platform community guidelines before publishing.

## Use Cases

### Resetting a user's account after cheating.
A player is caught exploiting the game. Instead of manually deleting data across three different databases, the agent runs `remove_user_storage` to clear all progress, followed by an automated notification.

### Analyzing seasonal retention dips.
The marketing team notices a drop in repeat players. The agent queries `get_analytics` and combines that data with user profile details from `get_user_info` to pinpoint when the engagement declined.

### Onboarding a new beta tester.
The QA engineer needs to test the full loop: first, use `code2session` for login. Then, manually set initial data using `set_user_storage`. Finally, verify everything works by running `get_user_info`.

### Handling a public forum post.
A user posts something potentially offensive in the game comments. The agent intercepts this text and runs it through `check_content_security`. If it fails, the system blocks publication immediately.

## Benefits

- Stop juggling multiple endpoints. With this MCP, you handle everything—from user authentication (`code2session`) to content moderation (`check_content_security`) within one conversational flow.
- Maintain persistent player data without manual intervention. Your agent can automatically `set_user_storage` progress and retrieve it later using `get_user_storage`, making the game feel continuous for the player.
- Monitor business health instantly. Instead of running reports in a separate dashboard, your agent pulls metrics like DAU or retention rates directly via `get_analytics` when you need them.
- Keep things fair and safe by automating checks. You can enforce policy rules immediately using `check_content_security` before any user-generated text is ever published.
- Manage competition fluidly. Your agent handles both updating scores with `submit_score` and checking the current rank via `get_game_rank`, keeping your leaderboards live.

## How It Works

The bottom line is that you don't write the API calls; you tell your AI client what needs to happen in the game backend.

1. Subscribe to this MCP and supply your Douyin Mini-Game App ID and secret credentials.
2. Your agent first uses `get_access_token` to grab the necessary API key, which must be refreshed when it expires.
3. You then instruct your agent on the task—for example, 'Save user progress' or 'Check content safety'—and the MCP executes the required tool call.

## Frequently Asked Questions

**How do I start using the Douyin Mini-Game MCP?**
You must first subscribe to this MCP on Vinkius. Once connected, your agent will require you to provide your specific App ID and Secret credentials.

**Can I just get a user's name using the Douyin Mini-Game MCP?**
Yes, but remember that retrieving basic profile data requires first successfully calling `code2session` to establish a valid session token.

**What is the best way to save game progress? Use set_user_storage?**
That's right. You use `set_user_storage` when you want your agent to write or update specific key-value pairs, like a player's current level or inventory count.

**Does the Douyin Mini-Game MCP handle score resets?**
You can reset progress by explicitly calling `remove_user_storage` to clear old keys. For competitive scores, you simply overwrite them using `submit_score`.

**What is the correct sequence to get an access token before I can use `code2session`?**
You must first call `get_access_token`. This provides the necessary credential that allows you to exchange a temporary login code for the final, secure user session keys. Without this initial token, subsequent API calls will fail due to invalid authentication.

**How do I validate if user-generated text is safe using `check_content_security`?**
You pass the raw text string directly into `check_content_security`. The tool returns a boolean value and an explanation of any policy violations. This confirms whether the content can be published in your mini-game.

**What specific metrics are available when I call `get_analytics`?**
You retrieve key performance indicators like Daily Active Users (DAU) and user retention rates. These analytics help you spot trends, understand how long players stay engaged, and pinpoint areas where your game needs work.

**If I only want to clear one specific setting instead of all data, should I use `remove_user_storage`?**
Yes. Use `remove_user_storage` and specify the exact keys you need gone (e.g., 'last_login', 'tutorial_completed'). This lets you surgically clean up old entries without wiping out vital game progress.

**How do I get my Douyin Mini-Game App ID and Secret?**
Register at the [Douyin Open Platform](https://developer.open-douyin.com/), create a mini-game application, and find your App ID and Secret in the application settings. You'll need entity verification for production deployment.

**What is cloud storage used for?**
Cloud storage saves user game data (progress, settings, high scores) as key-value pairs. Each user gets their own storage space. Use setUserStorage to save data and getUserStorage to load it. This is essential for cross-device game continuity.

**How does content moderation work?**
The content security API checks user-generated text (nicknames, chat, custom names) against Douyin's content policies. Submit text via the check_content_security tool and receive a pass/fail result. This is mandatory for games with user-generated content features.