2026-03-25 13:51:10 +00:00
# WebSocket Bot
The WebSocket Bot is an **external example bot** that lets you remotely control MCC over WebSocket.
It runs a local WebSocket server inside your MCC session, accepts commands as JSON messages, and pushes game events back to connected clients in real time.
::: warning External Bot
This bot is **not** built into MCC.
You load it as a standalone script with `/script ChatBots/WebSocketBot.cs` .
:::
## Quick Start
1. Copy `config/ChatBots/WebSocketBot.cs` into your MCC `config/ChatBots/` folder (it ships in the repo under that path).
2026-03-25 16:58:16 +00:00
1. Open the file and edit the line near the top:
2026-03-25 13:51:10 +00:00
```csharp
2026-03-25 13:54:04 +00:00
MCC.LoadBot(new WebSocketBot("127.0.0.1", 8043, "CHANGE_THIS_PASSWORD"));
2026-03-25 13:51:10 +00:00
```
- Replace `127.0.0.1` with the IP to bind (use `+` or `*` for all interfaces).
- Replace `8043` with your preferred port.
2026-03-25 13:54:04 +00:00
- Replace `CHANGE_THIS_PASSWORD` with a strong, unique password.
2026-03-25 16:58:16 +00:00
1. Optionally enable debug logging:
2026-03-25 13:51:10 +00:00
```csharp
MCC.LoadBot(new WebSocketBot("127.0.0.1", 8043, "mypassword", debugMode: true));
```
2026-03-25 16:58:16 +00:00
1. In MCC, run: `/script ChatBots/WebSocketBot.cs`
2026-03-25 13:51:10 +00:00
The bot starts a WebSocket server. Connect to `ws://127.0.0.1:8043/` with any WebSocket client.
## Protocol Overview
All communication uses JSON over WebSocket text frames.
### Authentication Flow
```
Connect via WebSocket
|
v
(Optional) Send "ChangeSessionId" to set a friendly session name
|
v
Send "Authenticate" with the configured password
|
v
Send commands and receive events
```
### Sending Commands
Commands are JSON objects with this shape:
```json
{
"command": "CommandName",
"requestId": "any-unique-string",
"parameters": [1, "text", true]
}
```
- `command` - the procedure name (case-sensitive)
- `requestId` - a client-generated ID so you can match responses to requests
- `parameters` - an ordered array of arguments (types depend on the command)
Every command produces an `OnWsCommandResponse` event with `success` , `requestId` , and optionally `message` .
### Sending Plain Text
You can also send plain text directly:
2026-03-25 16:58:16 +00:00
2026-03-25 13:51:10 +00:00
- Text starting with `/` is forwarded to MCC as an internal command (e.g., `/move north` ).
- Other text is sent as chat.
### Receiving Events
Events arrive as JSON:
```json
{
"event": "EventName",
"data": "{ ... serialized payload ... }"
}
```
The `data` field is a JSON string that you parse separately to get the event payload.
## Enum Serialization (String Names)
All enum values (ItemType, EntityType, Direction, Hand, etc.) are serialized as **string names** , not numeric IDs.
For example, an entity of type `Zombie` appears as:
2026-03-25 16:58:16 +00:00
2026-03-25 13:51:10 +00:00
```json
{ "type": "Zombie", "location": { "x": 10, "y": 64, "z": -20 } }
```
When sending commands that accept enum parameters, you can pass **either** a string name or a numeric value:
2026-03-25 16:58:16 +00:00
2026-03-25 13:51:10 +00:00
```json
{ "command": "InteractEntity", "requestId": "abc", "parameters": [42, "Interact", "MainHand"] }
```
2026-03-25 16:58:16 +00:00
2026-03-25 13:51:10 +00:00
or:
2026-03-25 16:58:16 +00:00
2026-03-25 13:51:10 +00:00
```json
{ "command": "InteractEntity", "requestId": "abc", "parameters": [42, 0, 0] }
```
Two dedicated commands let you query the full mapping tables:
2026-03-25 16:58:16 +00:00
2026-03-25 13:51:10 +00:00
- `GetItemTypeMappings` returns `{ "DiamondSword": 798, "Stone": 1, ... }`
- `GetEntityTypeMappings` returns `{ "Player": 128, "Zombie": 119, ... }`
These are useful if your client needs a name-to-ID lookup for the current MCC version.
## Reference
- [Commands ](Commands.md ) - full list of available commands
- [Events ](Events.md ) - full list of emitted events
## Compatibility
- Requires any MCC version that supports `/script` (standalone MCCScript 1.0 bots).
- Uses only `System.Text.Json` (built into .NET), so no extra DLLs are needed.
- Compatible with [MCC.js ](https://github.com/milutinke/MCC.js ) and any WebSocket client library.