> For the complete documentation index, see [llms.txt](https://docs.edgegap.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.edgegap.com/docs/sample-projects/web-games/vibe-coded-multiplayer.md).

# Vibe-Coded Multiplayer

Make your vibe-coded game multiplayer: take a browser game made with ChatGPT, Claude or Gemini online with an AI agent and the Edgegap MCP, with matchmaking and one server per match.

Learn how to make a vibe-coded game online multiplayer with one prompt, using an AI agent and the Edgegap MCP server.

![Thin Ice Tussle, a vibe-coded game running online matches on Edgegap](https://raw.githubusercontent.com/edgegap/netcode-sample-threejs-thin-ice-tussle/main/docs/images/match.jpg)

Games made with ChatGPT, Claude or Gemini usually start the same way: one web page, the player against bots, everything running in the browser. Thin Ice Tussle started like that. It's a [three.js](https://threejs.org/) game where penguins shove each other off breaking ice. Then an AI agent with the [Edgegap MCP server](https://docs.edgegap.com/docs/mcp-integration.md) connected turned it into online multiplayer, and solo play kept working.

This sample shows:

* **Play online**: players click one button. Edgegap's matchmaker groups 2 to 4 of them, and a player waiting alone gets a match with bots after 20 seconds.
* **One server per match, near its players**: the server runs the game rules, so nobody can cheat from the browser console.
* **Servers stop by themselves**: when the match is over, or everyone has left. You pay only while people play.
* **The same rules file** runs in the page for solo play and on the server for online matches, so the two can't drift apart.

{% hint style="info" %}
[**Play Thin Ice Tussle**](https://edgegap.github.io/netcode-sample-threejs-thin-ice-tussle/) in your browser, on a phone or a computer. The [sample repository](https://github.com/edgegap/netcode-sample-threejs-thin-ice-tussle) has the single-player game (tag `before`), the online game (tag `after`), the diff between them, and every prompt in `PROMPTS.md`.
{% endhint %}

## ✔️ Preparation

Before we start, you will need:

* **Thin Ice Tussle sample** ([repository](https://github.com/edgegap/netcode-sample-threejs-thin-ice-tussle)), optional, to try the finished game locally.
* **A web game.** A single HTML file from a chat, or a project folder from Cursor, Lovable, Bolt or v0. Games made in Lovable, Bolt or v0 need to be connected to GitHub or downloaded first, so the agent can edit them.
* **A coding agent that can run commands and use MCP servers**, such as Claude Code, ChatGPT Codex, Gemini CLI, Cursor or VS Code. Chat apps can write the game, but adding multiplayer means building and testing a server, which needs an agent working in your project folder. This sample was built with Claude Code.
* [Node.js](https://nodejs.org/) 22 or newer, which the agent uses to run the server.
* An [Edgegap account](https://app.edgegap.com/auth/register). No credit card required.

<details>

<summary><a href="https://www.docker.com/products/docker-desktop/">Install Docker Desktop (or Docker CLI)</a></summary>

* [Install Docker Desktop from the official source](https://www.docker.com/products/docker-desktop/) (no account required).
* Restart your computer after completing the installation.

</details>

☑️ Optionally, try the sample locally first:

{% code collapsedlinecount="10" %}

```bash
npm ci
node server/main.js
```

{% endcode %}

In a second terminal, serve the page with `npx http-server client -p 8081`, open <http://localhost:8081> in two tabs, and click **Local server :7777** in both.

## 🤖 Go Multiplayer

### 1. Connect the Edgegap MCP

☑️ Create an API token in the Edgegap dashboard (**User Settings**, then **Tokens**), and add the Edgegap MCP server to your agent with it. Follow [MCP Integration](https://docs.edgegap.com/docs/mcp-integration.md) for your agent.

{% hint style="danger" %}
**Your Edgegap API token stays in your agent's settings.** It must never end up in your game's page, your repository or a chat. The agent knows this, and the MCP server refuses calls that would put it in a server's environment variables.
{% endhint %}

✅ You may now proceed to the next step.

### 2. Check Your Game Suits Online Play

Online, a key press travels to the server and back before it shows on screen. Some games hide that delay well, others don't:

| Feels fine online                                                                                       | Needs care                                                     | Change the design first                                             |
| ------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------- | ------------------------------------------------------------------- |
| Slippery or floaty movement, pushing and bumping, party games, collecting, slow projectiles, turn-based | Fast top-down shooters, ball sports, racing with tight corners | Precise platforming, rhythm games, fighting games with frame timing |

Thin Ice Tussle was picked for this: the ice is slippery anyway, so the delay barely shows, even on mobile data. Not sure about yours? Ask the agent, it will tell you before changing anything.

✅ You may now proceed to the next step.

### 3. Send One Prompt

☑️ Open your game's folder in the agent, and send:

> Make this game online multiplayer on Edgegap. Use the Edgegap MCP and its skills. Keep the solo mode, add a Find Match button, 2 to 4 players per match, bots fill empty seats. Ask me before you create anything in my Edgegap account.

The agent loads Edgegap's skills through the MCP server and follows them:

1. moves the game rules into one file the page and the server share,
2. writes a node.js server that runs one match, fills empty seats with bots and stops itself,
3. adds **Find match** to the page with the [Edgegap JS SDK](https://www.npmjs.com/package/@edgegap/sdk),
4. tests two headless players on a local server, then the server's container the way Edgegap runs it,
5. pushes the server image and creates the app version on Edgegap, asking you first,
6. writes the matchmaker configuration, and tests a full match on Edgegap.

{% hint style="info" %}
**Prefer to do it by hand?** [Three.js Minigames](https://docs.edgegap.com/docs/sample-projects/web-games/threejs-minigames.md) walks through the same steps without an agent: build the server image, create the app version, and create the matchmaker.
{% endhint %}

✅ You may now proceed to the next step.

### 4. Do the Account Steps

A few steps need you in the dashboard. The agent tells you when, with the exact values:

☑️ Find your [Container Registry](https://docs.edgegap.com/learn/advanced-features/edgegap-container-registry.md) project name and credentials, and add them to the app version the agent created, so Edgegap can pull the server image.

{% hint style="warning" %}
**TLS Upgrade** lets browsers on `https` pages connect to `wss://<id>.pr.edgegap.net:<port>`. Check that the app version the agent created has your server port (`7777` in this sample) with protocol **WS** and **TLS Upgrade** enabled. Connect with the FQDN, not the IP, so the certificate matches.
{% endhint %}

☑️ Open the [Matchmaker](https://app.edgegap.com/matchmaker-management-v2/matchmakers/list) page, click **Create**, upload the configuration file the agent wrote, and click **Create and Start**.

☑️ Ask the agent to run the end-to-end test, then open your game in two browser tabs and click **Find match** in both.

{% hint style="success" %}
**The matchmaker's Auth Token is made to ship in your game's page.** It lets players join the queue and gives no access to your Edgegap account.
{% endhint %}

Both tabs are now in the same match, on a server near you. Send the page to a friend on another network to play for real.

🙌 Congratulations on your first matchmade Deployment on Edgegap!

## 📢 Share It

Host the page anywhere that serves static files: GitHub Pages, itch.io, your own site. Add its address to the matchmaker configuration's `allowed_cors_origins`.

To keep a public demo cheap, only the matchmaker runs all the time, and every server stops within seconds of its players leaving. Ask the agent to set it up, or set these on the app version:

* `REQUIRE_TICKET` - `1`, only players the matchmaker sent can join,
* `EMPTY_TIMEOUT_S` - `10`, stop 10 seconds after the last player leaves,
* `FIRST_JOIN_TIMEOUT_S` - `45`, stop if the matched players never connect,
* **Restart policy** never, and **Max duration** 30 minutes as a safety net.

{% hint style="warning" %}
**Free tier limits:** one server at a time, and the matchmaker stops 3 hours after each start. That's enough to test with friends. A demo that stays up for everyone needs a paid tier.
{% endhint %}

{% hint style="info" %}
Free Tier is limited to 2 Applications, 2 versions, and 10 GB of Container Registry storage.
{% endhint %}

To ship an update, ask the agent: it builds a new server image and points the app version at it. Running matches keep the old build.

{% hint style="info" %}
The `edgegap-vibe-coded` skill in [Edgegap's agent skills](https://github.com/edgegap/llm-agent-skills) holds this whole workflow, and the `edgegap-threejs` skill has the server, Find Match and test templates. The MCP server gives them to your agent, so you don't need to install anything else.
{% endhint %}
