@lzimul/minecraft-mcp 1.0.6 → 1.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -3
- package/build/app/websocket.js +16 -1
- package/build/config/server-info.js +1 -1
- package/lib/app/websocket.d.ts.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -131,7 +131,7 @@ Each snapshot looks like this:
|
|
|
131
131
|
| `MCP_WORLD_STORAGE` | `file` | `file` for JSON snapshots, `memory` for volatile state |
|
|
132
132
|
| `MCP_WORLD_DIR` | `./app/dimensions` | Directory that holds the per-dimension snapshots |
|
|
133
133
|
| `MCP_LOG_LEVEL` | `info` | log4js level: `trace`, `debug`, `info`, `warn`, `error` |
|
|
134
|
-
| `MCP_WS_ENABLED` | `
|
|
134
|
+
| `MCP_WS_ENABLED` | `false` | Start the WebSocket fan-out service (`false` to disable) |
|
|
135
135
|
| `MCP_WS_HOST` | `127.0.0.1` | Host/interface the WebSocket service binds to |
|
|
136
136
|
| `MCP_WS_PORT` | `8765` | TCP port for the WebSocket service |
|
|
137
137
|
| `MCP_WS_PATH` | `/` | URL path the WebSocket service listens on |
|
|
@@ -155,9 +155,9 @@ State is accessed through `IWorldStore` (`src/interfaces/world-store.interface.t
|
|
|
155
155
|
|
|
156
156
|
### WebSocket service
|
|
157
157
|
|
|
158
|
-
The server
|
|
158
|
+
The server can run a WebSocket fan-out service alongside the stdio MCP transport, but it should be treated as a privileged telemetry channel. Keep it **disabled by default** unless you explicitly need it, and enable it only with access controls (for example: an origin allow-list and/or a shared token presented during the upgrade request). Bind/listen settings can still be configured with the `MCP_WS_*` variables above. The MCP transport is unaffected: stdout stays reserved for JSON-RPC, and a WebSocket listen failure is logged but never crashes the process.
|
|
159
159
|
|
|
160
|
-
|
|
160
|
+
When enabled, authenticated/authorized clients receive a **world snapshot** right after the handshake (pushed on a short delay so clients that attach their message listener after `open` still catch it), then a **tool-call event** for every MCP tool invocation:
|
|
161
161
|
|
|
162
162
|
```jsonc
|
|
163
163
|
// On connect (and on {"type":"world-request"}):
|
package/build/app/websocket.js
CHANGED
|
@@ -3,6 +3,7 @@ import { toErrorMessage } from '../utils/error-message.js';
|
|
|
3
3
|
import { logger } from '../utils/logger.js';
|
|
4
4
|
import { dimensionState } from '../resources/dimension-resources.js';
|
|
5
5
|
import { World } from '../world/world.js';
|
|
6
|
+
const INITIAL_SNAPSHOT_DELAY_MS = 25;
|
|
6
7
|
function buildWorldSnapshot(world) {
|
|
7
8
|
return {
|
|
8
9
|
type: 'world-snapshot',
|
|
@@ -54,6 +55,7 @@ function handleClientMessage(world, socket, data) {
|
|
|
54
55
|
}
|
|
55
56
|
export function startWebSocketService(world, config) {
|
|
56
57
|
const clients = new Set();
|
|
58
|
+
const pendingSnapshots = new Set();
|
|
57
59
|
const wss = new WebSocketServer({
|
|
58
60
|
host: config.host,
|
|
59
61
|
port: config.port,
|
|
@@ -65,7 +67,16 @@ export function startWebSocketService(world, config) {
|
|
|
65
67
|
wss.on('connection', socket => {
|
|
66
68
|
clients.add(socket);
|
|
67
69
|
logger.info(`WebSocket client connected (${clients.size} client(s))`);
|
|
68
|
-
|
|
70
|
+
const snapshotTimer = setTimeout(() => {
|
|
71
|
+
pendingSnapshots.delete(snapshotTimer);
|
|
72
|
+
try {
|
|
73
|
+
sendObject(socket, buildWorldSnapshot(world));
|
|
74
|
+
}
|
|
75
|
+
catch (error) {
|
|
76
|
+
logger.warn(`WebSocket initial snapshot failed: ${toErrorMessage(error)}`);
|
|
77
|
+
}
|
|
78
|
+
}, INITIAL_SNAPSHOT_DELAY_MS);
|
|
79
|
+
pendingSnapshots.add(snapshotTimer);
|
|
69
80
|
socket.on('message', data => {
|
|
70
81
|
handleClientMessage(world, socket, data);
|
|
71
82
|
});
|
|
@@ -98,6 +109,10 @@ export function startWebSocketService(world, config) {
|
|
|
98
109
|
return clients.size;
|
|
99
110
|
}
|
|
100
111
|
async function close() {
|
|
112
|
+
for (const snapshotTimer of pendingSnapshots) {
|
|
113
|
+
clearTimeout(snapshotTimer);
|
|
114
|
+
}
|
|
115
|
+
pendingSnapshots.clear();
|
|
101
116
|
for (const socket of clients) {
|
|
102
117
|
try {
|
|
103
118
|
socket.close(1001, 'Server shutting down');
|
|
@@ -7,7 +7,7 @@ export const SERVER_INFO = {
|
|
|
7
7
|
name: '@lzimul/minecraft-mcp',
|
|
8
8
|
title: 'lZiMUl Minecraft MCP',
|
|
9
9
|
description: `Minecraft Model Context Protocol server (Java Edition ${MINECRAFT_DATA_VERSION}): exposes all ${MINECRAFT_BLOCK_COUNT} blocks, ${MINECRAFT_ITEM_COUNT} items and ${MINECRAFT_ENTITY_COUNT} entity types with their properties as resources, plus tools to read, place, query and fill blocks, inspect dimensions, create, move and delete entities and players, set entity positions, and manage their hotbar and backpack inventories.`,
|
|
10
|
-
version: '1.0.
|
|
10
|
+
version: '1.0.7',
|
|
11
11
|
websiteUrl: 'https://projects.lzimul.com/minecraft-mcp',
|
|
12
12
|
icons: [
|
|
13
13
|
{
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"websocket.d.ts","sourceRoot":"","sources":["../../src/app/websocket.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAE1C,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAC/D,OAAO,KAAK,EACV,cAAc,EAIf,MAAM,sCAAsC,CAAC;
|
|
1
|
+
{"version":3,"file":"websocket.d.ts","sourceRoot":"","sources":["../../src/app/websocket.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAE1C,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAC/D,OAAO,KAAK,EACV,cAAc,EAIf,MAAM,sCAAsC,CAAC;AAc9C,MAAM,WAAW,iBAAiB;IAEhC,SAAS,CAAC,KAAK,EAAE,cAAc,GAAG,IAAI,CAAC;IAEvC,WAAW,IAAI,MAAM,CAAC;IAEtB,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CACxB;AA0ED,wBAAgB,qBAAqB,CACnC,KAAK,EAAE,KAAK,EACZ,MAAM,EAAE,gBAAgB,GACvB,iBAAiB,CAyFnB"}
|