@lzimul/minecraft-mcp 1.0.2 → 1.0.4

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.
Files changed (88) hide show
  1. package/README.md +219 -168
  2. package/SECURITY.md +38 -21
  3. package/build/config/server-info.js +3 -2
  4. package/build/config/world-limits.js +4 -1
  5. package/build/data/entities.js +1581 -0
  6. package/build/enums/entity-kind.enum.js +5 -0
  7. package/build/enums/inventory-section.enum.js +5 -0
  8. package/build/index.js +4 -3
  9. package/build/interfaces/entity-inventory.interface.js +1 -0
  10. package/build/interfaces/entity-type.interface.js +1 -0
  11. package/build/interfaces/entity.interface.js +1 -0
  12. package/build/resources/dimension-resources.js +23 -6
  13. package/build/resources/entity-resources.js +17 -0
  14. package/build/resources/index.js +2 -0
  15. package/build/schemas/coordinate-schema.js +5 -0
  16. package/build/schemas/dimension-schema.js +1 -0
  17. package/build/schemas/entity-schema.js +95 -0
  18. package/build/tools/block-tools.js +14 -23
  19. package/build/tools/entity-tools.js +325 -0
  20. package/build/tools/index.js +4 -0
  21. package/build/tools/result.js +3 -5
  22. package/build/tools/world-tools.js +139 -0
  23. package/build/utils/logger.js +53 -0
  24. package/build/world/block-spec.js +6 -6
  25. package/build/world/block-states.js +23 -4
  26. package/build/world/entity-inventory.js +84 -0
  27. package/build/world/item-spec.js +25 -0
  28. package/build/world/simulated-dimension.js +187 -13
  29. package/build/world/stores/file-world-store.js +67 -20
  30. package/build/world/stores/memory-world-store.js +13 -5
  31. package/build/world/stores/serialized-block.js +9 -14
  32. package/build/world/stores/serialized-entity.js +74 -0
  33. package/build/world/world.js +33 -1
  34. package/lib/config/server-info.d.ts.map +1 -1
  35. package/lib/config/world-limits.d.ts +3 -0
  36. package/lib/config/world-limits.d.ts.map +1 -1
  37. package/lib/data/entities.d.ts +5 -0
  38. package/lib/data/entities.d.ts.map +1 -0
  39. package/lib/enums/entity-kind.enum.d.ts +5 -0
  40. package/lib/enums/entity-kind.enum.d.ts.map +1 -0
  41. package/lib/enums/inventory-section.enum.d.ts +5 -0
  42. package/lib/enums/inventory-section.enum.d.ts.map +1 -0
  43. package/lib/interfaces/entity-inventory.interface.d.ts +9 -0
  44. package/lib/interfaces/entity-inventory.interface.d.ts.map +1 -0
  45. package/lib/interfaces/entity-type.interface.d.ts +8 -0
  46. package/lib/interfaces/entity-type.interface.d.ts.map +1 -0
  47. package/lib/interfaces/entity.interface.d.ts +17 -0
  48. package/lib/interfaces/entity.interface.d.ts.map +1 -0
  49. package/lib/interfaces/world-store.interface.d.ts +7 -2
  50. package/lib/interfaces/world-store.interface.d.ts.map +1 -1
  51. package/lib/resources/dimension-resources.d.ts.map +1 -1
  52. package/lib/resources/entity-resources.d.ts +3 -0
  53. package/lib/resources/entity-resources.d.ts.map +1 -0
  54. package/lib/resources/index.d.ts.map +1 -1
  55. package/lib/schemas/coordinate-schema.d.ts +5 -0
  56. package/lib/schemas/coordinate-schema.d.ts.map +1 -1
  57. package/lib/schemas/dimension-schema.d.ts +1 -0
  58. package/lib/schemas/dimension-schema.d.ts.map +1 -1
  59. package/lib/schemas/entity-schema.d.ts +134 -0
  60. package/lib/schemas/entity-schema.d.ts.map +1 -0
  61. package/lib/tools/block-tools.d.ts.map +1 -1
  62. package/lib/tools/entity-tools.d.ts +4 -0
  63. package/lib/tools/entity-tools.d.ts.map +1 -0
  64. package/lib/tools/index.d.ts.map +1 -1
  65. package/lib/tools/result.d.ts +2 -6
  66. package/lib/tools/result.d.ts.map +1 -1
  67. package/lib/tools/world-tools.d.ts +4 -0
  68. package/lib/tools/world-tools.d.ts.map +1 -0
  69. package/lib/utils/logger.d.ts +3 -0
  70. package/lib/utils/logger.d.ts.map +1 -0
  71. package/lib/world/block-states.d.ts +2 -0
  72. package/lib/world/block-states.d.ts.map +1 -1
  73. package/lib/world/entity-inventory.d.ts +16 -0
  74. package/lib/world/entity-inventory.d.ts.map +1 -0
  75. package/lib/world/item-spec.d.ts +10 -0
  76. package/lib/world/item-spec.d.ts.map +1 -0
  77. package/lib/world/simulated-dimension.d.ts +29 -0
  78. package/lib/world/simulated-dimension.d.ts.map +1 -1
  79. package/lib/world/stores/file-world-store.d.ts +3 -3
  80. package/lib/world/stores/file-world-store.d.ts.map +1 -1
  81. package/lib/world/stores/memory-world-store.d.ts +3 -4
  82. package/lib/world/stores/memory-world-store.d.ts.map +1 -1
  83. package/lib/world/stores/serialized-block.d.ts.map +1 -1
  84. package/lib/world/stores/serialized-entity.d.ts +24 -0
  85. package/lib/world/stores/serialized-entity.d.ts.map +1 -0
  86. package/lib/world/world.d.ts +3 -0
  87. package/lib/world/world.d.ts.map +1 -1
  88. package/package.json +113 -109
package/README.md CHANGED
@@ -1,168 +1,219 @@
1
- # lZiMUl Minecraft MCP
2
-
3
- Minecraft Model Context Protocol (MCP) server. It exposes the complete Minecraft registry (Java Edition data) as MCP resources and provides tools to read and write blocks in persisted, per-dimension worlds. Requires Node.js 22 or newer.
4
-
5
- ## Features
6
-
7
- - All Minecraft blocks and items exposed as MCP resources with full properties (name, hardness, blast resistance, durability, enchantment categories, light level, collision box, and more)
8
- - Block lookup and placement tools backed by simulated dimensions (Overworld, The Nether, The End), each with its own isolated world state and height range
9
- - Block states are supported everywhere: `minecraft:oak_stairs[facing=south,half=bottom]`
10
- - World state is persisted per dimension as JSON and survives restarts
11
- - Structured tool output (`outputSchema` / `structuredContent`) plus human readable text
12
- - Every failure path returns a readable message instead of an unhandled exception
13
- - Tool annotations for safe client automation
14
-
15
- ## Protocol
16
-
17
- The server implements the MCP `2026-07-28` revision. Modern clients open a session with `server/discover` and carry the per-request envelope in every request's `params._meta` (`io.modelcontextprotocol/protocolVersion`, `io.modelcontextprotocol/clientCapabilities`, and optionally `io.modelcontextprotocol/clientInfo`). Responses use the modern result shape (`resultType`, server identity under `_meta['io.modelcontextprotocol/serverInfo']`). Legacy clients that open with `initialize` are still served through the 2025-era handshake.
18
-
19
- ## Tools
20
-
21
- | Tool | Description |
22
- | ---------- | -------------------------------------------------------------------------------------- |
23
- | `getBlock` | Get the block (and its states) at coordinates in a dimension (defaults to `overworld`) |
24
- | `setBlock` | Place a block with optional states in a dimension and return the replaced block |
25
- | `getItem` | Look up item properties by id (`minecraft:diamond_sword` or `diamond_sword`) |
26
-
27
- `setBlock` accepts both the full form (`minecraft:oak_stairs[facing=south,half=bottom]`) and the short form (`oak_stairs[facing=south]`). Setting `minecraft:air` removes the block; air cannot carry states.
28
-
29
- ## Persistence
30
-
31
- World snapshots are stored as one JSON document per dimension, so the dimensions never share a file:
32
-
33
- ```text
34
- world-data/
35
- overworld.json
36
- the_nether.json
37
- the_end.json
38
- ```
39
-
40
- Each snapshot looks like this:
41
-
42
- ```json
43
- {
44
- "format": "lzimul-world/2",
45
- "dimension": "minecraft:overworld",
46
- "updatedAt": "2026-01-01T00:00:00.000Z",
47
- "modifiedBlockCount": 1,
48
- "blocks": [
49
- {
50
- "x": 0,
51
- "y": 64,
52
- "z": 0,
53
- "block": "minecraft:oak_stairs",
54
- "states": { "facing": "south", "half": "bottom" }
55
- }
56
- ]
57
- }
58
- ```
59
-
60
- - The whole dimension is loaded once at startup and kept in memory; mutations are written back debounced and atomically (temporary file + rename).
61
- - `setBlock` awaits the write, so a successful response means the block is durably stored. If persisting fails the tool returns an error instead of pretending success.
62
- - Parallel tool calls share a single in-flight snapshot write instead of writing one full file per call, so building with many simultaneous `setBlock` calls stays fast.
63
- - Unmodified coordinates are air; only placed blocks are stored. Placing air removes the coordinate from the snapshot.
64
- - Empty state maps are omitted from the file to keep snapshots small.
65
- - Snapshots are written as compact JSON (about half the bytes of pretty-printed JSON) with a trailing newline.
66
- - Files written by format v1 (`lzimul-world/1`, no states) still load; new files use `lzimul-world/2`.
67
- - A dimension file is created on its first write; untouched dimensions stay empty.
68
-
69
- ### Configuration
70
-
71
- | Variable | Default | Description |
72
- | ------------------- | -------------- | ------------------------------------------------------ |
73
- | `MCP_WORLD_STORAGE` | `file` | `file` for JSON snapshots, `memory` for volatile state |
74
- | `MCP_WORLD_DIR` | `./world-data` | Directory that holds the per-dimension snapshots |
75
-
76
- A corrupt or oversized snapshot is moved aside as `<dimension>.json.corrupt-<uuid>` and the dimension starts empty, so a bad file never blocks startup.
77
-
78
- ### Storage backends
79
-
80
- State is accessed through `IWorldStore` (`src/interfaces/world-store.interface.ts`):
81
-
82
- | Backend | Used by | Notes |
83
- | ------------------ | ------------------- | ----------------------------------------------------- |
84
- | `FileWorldStore` | stdio (`npm start`) | Atomic per-dimension JSON files under `MCP_WORLD_DIR` |
85
- | `MemoryWorldStore` | tests, `memory` | Volatile; useful for throwaway sessions |
86
-
87
- ## Resources
88
-
89
- | URI | Description |
90
- | -------------------------------------- | ---------------------------------------------- |
91
- | `lzimul://minecraft/blocks` | Block index |
92
- | `lzimul://minecraft/blocks/{name}` | Single block properties |
93
- | `lzimul://minecraft/items` | Item index |
94
- | `lzimul://minecraft/items/{name}` | Single item properties |
95
- | `lzimul://minecraft/dimensions` | Persisted dimension index with world state |
96
- | `lzimul://minecraft/dimensions/{type}` | Single dimension state including placed blocks |
97
-
98
- Placed blocks in the dimension resources include a `states` object. If a resource read fails, the server returns a JSON document with an `error` field instead of dropping the request.
99
-
100
- ## Security
101
-
102
- - Tool input is validated with Zod: coordinates are bounded, dimensions come from an enum, and ids are limited in length.
103
- - Block ids are resolved against the generated registry; unknown blocks and namespaces are rejected.
104
- - State names and values are restricted to `[a-z0-9_]` / `[a-z0-9_.-]`, 64 characters each, and reserved keys (`__proto__`, `constructor`, `prototype`) are rejected to rule out prototype pollution.
105
- - Each dimension holds at most 250,000 modified blocks, and the file store refuses snapshots over 128 MiB.
106
- - Snapshot writes are atomic, corrupt files are quarantined with a UUID suffix, and malformed blocks are skipped while the rest of the world loads.
107
- - Run `npm audit` after dependency changes. The dependency tree currently reports no vulnerabilities; the `katex` override keeps the markdown lint toolchain patched.
108
-
109
- ## Performance
110
-
111
- Measured on Node.js 26 (results vary by hardware):
112
-
113
- - Startup, including registry import and 2,686 resource registrations: about 0.4 s.
114
- - 300 concurrent `setBlock` tool calls: about 70 ms end-to-end, because parallel flushes share in-flight snapshot writes instead of writing the file 300 times.
115
- - 20,000 persisted blocks: about 1.1 MiB of compact JSON, ~25 ms to save and ~24 ms to load.
116
- - In-memory reads and writes are O(1) map operations; only the debounced snapshot write is proportional to the number of modified blocks.
117
-
118
- ## Project Structure
119
-
120
- ```text
121
- src/
122
- index.ts Entry point
123
- app/ Server assembly
124
- config/ Server metadata, dimensions, storage, world limits
125
- data/ Generated registry data (blocks, items, version)
126
- enums/ Enumerations (EBoundingBox, EIconTheme, EDimensionType)
127
- interfaces/ Interfaces (IBlock, IItem, IDimension, IPlacedBlock, IDataEntry, IWorldStore)
128
- resources/ Resource registration and error fallbacks
129
- schemas/ Zod schemas and converters
130
- tools/ Tool registration and error handling
131
- utils/ Shared helpers (error messages)
132
- world/ Simulated dimension world state
133
- stores/ IWorldStore implementations (file, memory)
134
- scripts/
135
- generate-data.mjs Regenerates src/data from minecraft-data
136
- smoke-test.mjs End-to-end smoke test (including states)
137
- persistence-test.mjs Restart test for the world snapshots
138
- error-test.mjs Error fallbacks, sanitizing and storage limit tests
139
- stress-test.mjs Parallel write, coalescing and restart stress test
140
- clean.mjs Removes build output
141
- ```
142
-
143
- ## Scripts
144
-
145
- | Command | Description |
146
- | ----------------------- | ----------------------------------------------------- |
147
- | `npm run build` | Lint, compile and generate docs |
148
- | `npm run dev` | Build then start the server |
149
- | `npm start` | Start the server (stdio) |
150
- | `npm test` | Run the smoke, persistence, security and stress tests |
151
- | `npm run test:stress` | Run only the parallel write stress test |
152
- | `npm run generate-data` | Regenerate registry data (see below) |
153
- | `npm run clean` | Remove build output |
154
- | `npm run lint` | Lint and auto-fix |
155
-
156
- ## Data
157
-
158
- Registry data is generated from [PrismarineJS/minecraft-data](https://github.com/PrismarineJS/minecraft-data). To regenerate for a specific version:
159
-
160
- ```bash
161
- node scripts/generate-data.mjs <version> [blocks.json] [items.json]
162
- ```
163
-
164
- When local JSON files are provided they are used directly, otherwise the data is fetched from GitHub. The data version is exported as `MINECRAFT_DATA_VERSION` and used in all descriptions.
165
-
166
- ## License
167
-
168
- MIT
1
+ # lZiMUl Minecraft MCP
2
+
3
+ Minecraft Model Context Protocol (MCP) server. It exposes the complete Minecraft registry (Java Edition data) as MCP resources and provides tools to read and write blocks, inspect dimensions, create entities and players, and manage inventories in persisted, per-dimension worlds. Requires Node.js 22 or newer.
4
+
5
+ ## Features
6
+
7
+ - All Minecraft blocks, items and entity types exposed as MCP resources with full properties (name, hardness, blast resistance, durability, enchantment categories, light level, collision box, entity dimensions, category, and more)
8
+ - Block lookup and placement tools backed by simulated dimensions (Overworld, The Nether, The End), each with its own isolated world state and height range
9
+ - Block states are supported everywhere: `minecraft:oak_stairs[facing=south,half=bottom]`
10
+ - Dimension tools for metadata and paginated access to every placed block
11
+ - Entity and player tools with a 9-slot hotbar and 27-slot backpack per entity, managed through `getInventory` and `setInventory`
12
+ - World state (blocks, entities, players and inventories) is persisted per dimension as JSON and survives restarts
13
+ - log4js logging to stderr with chalk colours (error red, warn yellow, info green); stdout stays clean for the MCP transport
14
+ - Structured tool output (`outputSchema` / `structuredContent`) plus human readable text
15
+ - Every failure path returns a readable message instead of an unhandled exception
16
+ - Tool annotations for safe client automation
17
+
18
+ ## Protocol
19
+
20
+ The server implements the MCP `2026-07-28` revision. Modern clients open a session with `server/discover` and carry the per-request envelope in every request's `params._meta` (`io.modelcontextprotocol/protocolVersion`, `io.modelcontextprotocol/clientCapabilities`, and optionally `io.modelcontextprotocol/clientInfo`). Responses use the modern result shape (`resultType`, server identity under `_meta['io.modelcontextprotocol/serverInfo']`). Legacy clients that open with `initialize` are still served through the 2025-era handshake.
21
+
22
+ ## Tools
23
+
24
+ | Tool | Description |
25
+ | -------------------- | ----------------------------------------------------------------------------------------- |
26
+ | `getBlock` | Get the block (and its states) at coordinates in a dimension (defaults to `overworld`) |
27
+ | `setBlock` | Place a block with optional states in a dimension and return the replaced block |
28
+ | `getDimension` | Get dimension metadata, block count, entity count and player count |
29
+ | `getDimensionBlocks` | Page through every placed (non-air) block in a dimension, sorted by coordinates |
30
+ | `getItem` | Look up item properties by id (`minecraft:diamond_sword` or `diamond_sword`) |
31
+ | `createEntity` | Create a non-player entity with an empty hotbar and backpack |
32
+ | `getEntity` | Get an entity by UUID, including position, dimension and full inventory |
33
+ | `createPlayer` | Create a uniquely named player with an empty hotbar and backpack |
34
+ | `getPlayer` | Get a player by name (case-insensitive), including position, dimension and full inventory |
35
+ | `getInventory` | Read the 9 hotbar slots and 27 backpack slots of an entity or player |
36
+ | `setInventory` | Set or clear one hotbar/backpack slot of an entity or player |
37
+
38
+ `setBlock` accepts both the full form (`minecraft:oak_stairs[facing=south,half=bottom]`) and the short form (`oak_stairs[facing=south]`). Setting `minecraft:air` removes the block; air cannot carry states.
39
+
40
+ `getDimensionBlocks` is paginated because a dimension can hold up to 250,000 placed blocks. `limit` defaults to 1,000 and is capped at 10,000; `offset` skips rows. Rows are sorted by `x`, `y`, `z` and include the block id, display name and states.
41
+
42
+ ### Entities, players and inventories
43
+
44
+ - Entity type ids come from the generated registry (`lzimul://minecraft/entities`), for example `minecraft:zombie` or `zombie`. `createEntity` rejects `minecraft:player`; use `createPlayer` for players.
45
+ - Players are addressed by name, case-insensitively, and names are unique across all dimensions. Entity and player UUIDs come from the creation response.
46
+ - Every entity and player has a 9-slot hotbar plus a 27-slot backpack (36 slots total). Slots are zero-based within their section.
47
+ - `getInventory` and `setInventory` accept either an entity UUID or a player name. `setInventory` requires `section` (`hotbar` or `inventory`, default `inventory`), `slot`, `item` and `count`.
48
+ - `count` must not exceed the item's stack size. Set the item to `minecraft:air` or the count to `0` to clear a slot. Empty slots are returned as `null`.
49
+ - A dimension holds at most 10,000 entities and players combined. Entity names are limited to 64 characters and player names to 32 characters (`A-Z`, `a-z`, `0-9`, `_`).
50
+
51
+ ## Persistence
52
+
53
+ World snapshots are stored as one JSON document per dimension, so the dimensions never share a file:
54
+
55
+ ```text
56
+ world-data/
57
+ overworld.json
58
+ the_nether.json
59
+ the_end.json
60
+ ```
61
+
62
+ Each snapshot looks like this:
63
+
64
+ ```json
65
+ {
66
+ "format": "lzimul:minecraft/dimension",
67
+ "dimension": "minecraft:overworld",
68
+ "updatedAt": "2026-01-01T00:00:00.000Z",
69
+ "modifiedBlockCount": 1,
70
+ "entityCount": 1,
71
+ "blocks": [
72
+ {
73
+ "x": 0,
74
+ "y": 64,
75
+ "z": 0,
76
+ "block": "minecraft:oak_stairs",
77
+ "states": { "facing": "south", "half": "bottom" }
78
+ }
79
+ ],
80
+ "entities": [
81
+ {
82
+ "id": "0f0f2f4e-7d5a-4d8e-9a3b-2f6c1d8e4a10",
83
+ "kind": "player",
84
+ "type": "minecraft:player",
85
+ "name": "Steve",
86
+ "x": 1,
87
+ "y": 64,
88
+ "z": 0,
89
+ "createdAt": "2026-01-01T00:00:00.000Z"
90
+ }
91
+ ]
92
+ }
93
+ ```
94
+
95
+ - The whole dimension (blocks, entities and players) is loaded once at startup and kept in memory; mutations are written back debounced and atomically (temporary file + rename).
96
+ - `setBlock`, `createEntity`, `createPlayer` and `setInventory` await the write, so a successful response means the change is durably stored. If persisting fails the tool returns an error instead of pretending success.
97
+ - Parallel tool calls share a single in-flight snapshot write instead of writing one full file per call, so building with many simultaneous `setBlock` calls stays fast.
98
+ - Unmodified coordinates are air; only placed blocks are stored. Placing air removes the coordinate from the snapshot.
99
+ - Empty state maps are omitted from the file to keep snapshots small.
100
+ - Entity and player inventories are omitted when they are completely empty. When present, `inventory.hotbar` has 9 entries and `inventory.inventory` has 27 entries; each entry is `{ "item": "minecraft:diamond_sword", "count": 1 }` or `null`.
101
+ - Player names are not stored in a separate index: the player name index is rebuilt from the snapshots when the world loads. If two dimension files contain the same case-insensitive name, the first dimension wins and the duplicate player is dropped with a warning.
102
+ - Snapshots are written as compact JSON (about half the bytes of pretty-printed JSON) with a trailing newline.
103
+ - Files written by format v1 (`lzimul-world/1`, no states) and v2 (`lzimul-world/2`, no entities) still load; new files use `lzimul:minecraft/dimension` and include an `entities` array. A missing `entities` array simply means the dimension has no entities.
104
+ - Malformed block or entity entries are skipped without discarding the rest of the dimension. An entity's dimension always comes from the file it was loaded from, so an entry cannot claim to live in another dimension.
105
+ - A dimension file is created on its first write; untouched dimensions stay empty.
106
+
107
+ ### Configuration
108
+
109
+ | Variable | Default | Description |
110
+ | ------------------- | -------------- | ------------------------------------------------------- |
111
+ | `MCP_WORLD_STORAGE` | `file` | `file` for JSON snapshots, `memory` for volatile state |
112
+ | `MCP_WORLD_DIR` | `./world-data` | Directory that holds the per-dimension snapshots |
113
+ | `MCP_LOG_LEVEL` | `info` | log4js level: `trace`, `debug`, `info`, `warn`, `error` |
114
+
115
+ A corrupt or oversized snapshot is moved aside as `<dimension>.json.corrupt-<uuid>` and the dimension starts empty, so a bad file never blocks startup.
116
+
117
+ ### Logging
118
+
119
+ Server logs use [log4js](https://log4js-node.github.io/log4js-node/) with a chalk-based layout. `error`/`fatal` are red, `warn` yellow, `info` green, `debug` cyan and `trace` blue. Chalk disables ANSI colours automatically when the output is redirected to a non-colour terminal.
120
+
121
+ Logs are written to **stderr**, never stdout: stdout is the MCP JSON-RPC transport, so mixing log lines into it would corrupt the protocol stream. `MCP_LOG_LEVEL` controls the verbosity (default `info`). Developer scripts use a small stdout logger (`scripts/logger.mjs`) with the same colours, so test output stays readable.
122
+
123
+ ### Storage backends
124
+
125
+ State is accessed through `IWorldStore` (`src/interfaces/world-store.interface.ts`):
126
+
127
+ | Backend | Used by | Notes |
128
+ | ------------------ | ------------------- | ----------------------------------------------------- |
129
+ | `FileWorldStore` | stdio (`npm start`) | Atomic per-dimension JSON files under `MCP_WORLD_DIR` |
130
+ | `MemoryWorldStore` | tests, `memory` | Volatile; useful for throwaway sessions |
131
+
132
+ ## Resources
133
+
134
+ | URI | Description |
135
+ | -------------------------------------- | ---------------------------------------------------- |
136
+ | `lzimul://minecraft/blocks` | Block index |
137
+ | `lzimul://minecraft/blocks/{name}` | Single block properties |
138
+ | `lzimul://minecraft/items` | Item index |
139
+ | `lzimul://minecraft/items/{name}` | Single item properties |
140
+ | `lzimul://minecraft/entities` | Entity type index (157 types, including `player`) |
141
+ | `lzimul://minecraft/entities/{name}` | Single entity type properties |
142
+ | `lzimul://minecraft/dimensions` | Dimension index with block, entity and player counts |
143
+ | `lzimul://minecraft/dimensions/{type}` | Single dimension state including blocks and entities |
144
+
145
+ Placed blocks in the dimension resources include a `states` object. If a resource read fails, the server returns a JSON document with an `error` field instead of dropping the request. The dimensions index stays small on purpose: it reports per-dimension metadata, `modifiedBlockCount`, `entityCount` and `playerCount`, while `lzimul://minecraft/dimensions/{type}` returns the placed blocks plus the full entity/player list. In total the server registers 2,838 resources: every block, item and entity type, the indexes, and the seven dimension-related resources.
146
+
147
+ ## Security
148
+
149
+ - Tool input is validated with Zod: coordinates are bounded, dimensions come from an enum, and ids are limited in length.
150
+ - Block and item ids are resolved against the generated registries; unknown blocks, items and entity types and unknown namespaces are rejected.
151
+ - State names and values are restricted to `[a-z0-9_]` / `[a-z0-9_.-]`, 64 characters each, and reserved keys (`__proto__`, `constructor`, `prototype`) are rejected to rule out prototype pollution.
152
+ - Inventory input is validated too: the section and slot must be in range, the item must exist, and the count must fit the item's stack size. `minecraft:air` or count `0` clears a slot.
153
+ - Each dimension holds at most 250,000 modified blocks and 10,000 entities/players. Entity names are capped at 64 characters, player names at 32 characters, and player names are case-insensitively unique across all dimensions. The file store refuses to load or write a snapshot over 128 MiB, so an oversized world fails the tool call instead of producing a file that would be quarantined on restart.
154
+ - Snapshot writes are atomic, corrupt files are quarantined with a UUID suffix, and malformed block or entity entries are skipped while the rest of the world loads. Entity dimensions are taken from the snapshot file rather than trusted from the entry.
155
+ - Run `npm audit` after dependency changes. The dependency tree currently reports no vulnerabilities; the `katex` override keeps the markdown lint toolchain patched.
156
+
157
+ ## Performance
158
+
159
+ Measured on Node.js 26 (results vary by hardware):
160
+
161
+ - Startup, including registry import and 2,838 resource registrations: about 0.4 s.
162
+ - 300 concurrent `setBlock` tool calls: about 70 ms end-to-end, because parallel flushes share in-flight snapshot writes instead of writing the file 300 times.
163
+ - 20,000 persisted blocks: about 1.1 MiB of compact JSON, ~25 ms to save and ~24 ms to load.
164
+ - In-memory block, entity and inventory reads/writes are O(1) map operations; only the debounced snapshot write is proportional to the number of modified blocks and entities.
165
+ - `getDimensionBlocks` pages a cached, coordinate-sorted block array instead of re-sorting the world on every call.
166
+
167
+ ## Project Structure
168
+
169
+ ```text
170
+ src/
171
+ index.ts Entry point
172
+ app/ Server assembly
173
+ config/ Server metadata, dimensions, storage, world limits
174
+ data/ Generated registry data (blocks, items, entities, version)
175
+ enums/ Enumerations (EBoundingBox, EIconTheme, EDimensionType, EEntityKind, EInventorySection)
176
+ interfaces/ Interfaces (IBlock, IItem, IEntityType, IEntity, IEntityInventory, IDimension, IPlacedBlock, IWorldSnapshot, IWorldStore)
177
+ resources/ Block, item, entity and dimension resource registration
178
+ schemas/ Zod schemas and converters (blocks, entities, inventories)
179
+ tools/ Block, dimension, entity, player and inventory tools
180
+ utils/ Shared helpers (error messages, log4js + chalk logger)
181
+ world/ Simulated dimension state, entity inventory and item specs
182
+ stores/ IWorldStore implementations (file, memory) and serializers
183
+ scripts/
184
+ logger.mjs Coloured stdout logger for developer scripts
185
+ generate-data.mjs Regenerates src/data from minecraft-data
186
+ smoke-test.mjs End-to-end smoke test (blocks, dimensions, entities, inventories)
187
+ persistence-test.mjs Restart test for blocks, entities and inventories
188
+ error-test.mjs Error fallbacks, sanitizing and storage limit tests
189
+ stress-test.mjs Parallel write, coalescing and restart stress test
190
+ clean.mjs Removes build output
191
+ ```
192
+
193
+ ## Scripts
194
+
195
+ | Command | Description |
196
+ | ----------------------- | ----------------------------------------------------- |
197
+ | `npm run build` | Lint, compile and generate docs |
198
+ | `npm run dev` | Build then start the server |
199
+ | `npm start` | Start the server (stdio) |
200
+ | `npm test` | Run the smoke, persistence, security and stress tests |
201
+ | `npm run test:stress` | Run only the parallel write stress test |
202
+ | `npm run generate-data` | Regenerate registry data (see below) |
203
+ | `npm run clean` | Remove build output |
204
+ | `npm run lint` | Lint without modifying files |
205
+ | `npm run lint:fix` | Lint and auto-fix |
206
+
207
+ ## Data
208
+
209
+ Registry data is generated from [PrismarineJS/minecraft-data](https://github.com/PrismarineJS/minecraft-data). To regenerate for a specific version:
210
+
211
+ ```bash
212
+ node scripts/generate-data.mjs <version> [blocks.json] [items.json] [entities.json]
213
+ ```
214
+
215
+ When local JSON files are provided they are used directly, otherwise the data is fetched from GitHub. The fourth argument is optional and only needed for a custom entity registry; without it the entity list is fetched from the same minecraft-data release. The data version is exported as `MINECRAFT_DATA_VERSION` and used in all descriptions.
216
+
217
+ ## License
218
+
219
+ MIT
package/SECURITY.md CHANGED
@@ -1,21 +1,38 @@
1
- # Security Policy
2
-
3
- ## Supported Versions
4
-
5
- Use this section to tell people about which versions of your project are
6
- currently being supported with security updates.
7
-
8
- | Version | Supported |
9
- |---------|--------------------|
10
- | 5.1.x | :white_check_mark: |
11
- | 5.0.x | :x: |
12
- | 4.0.x | :white_check_mark: |
13
- | < 4.0 | :x: |
14
-
15
- ## Reporting a Vulnerability
16
-
17
- Use this section to tell people how to report a vulnerability.
18
-
19
- Tell them where to go, how often they can expect to get an update on a
20
- reported vulnerability, what to expect if the vulnerability is accepted or
21
- declined, etc.
1
+ # Security Policy
2
+
3
+ ## Supported Versions
4
+
5
+ Only the latest `1.x` release line receives security fixes.
6
+
7
+ | Version | Supported |
8
+ | ------- | ------------------ |
9
+ | 1.0.x | :white_check_mark: |
10
+ | < 1.0 | :x: |
11
+
12
+ ## Reporting a Vulnerability
13
+
14
+ Please do **not** open a public issue for security problems.
15
+
16
+ - Email: lZiMUl@lzimul.com
17
+ - Or use GitHub's private vulnerability reporting on
18
+ <https://github.com/lZiMUl/minecraft-mcp/security/advisories/new>
19
+
20
+ Include the affected version, a minimal reproduction (tool call, resource URI
21
+ or world snapshot), and the impact you observed. You can expect an initial
22
+ response within a few days. Please allow time for a fix and release before
23
+ disclosing the issue publicly.
24
+
25
+ ## Scope
26
+
27
+ The server is designed to run locally over stdio. Reports that are in scope
28
+ include, but are not limited to:
29
+
30
+ - Prototype pollution or code execution through block ids, block states or
31
+ snapshot files
32
+ - Path traversal or arbitrary file writes through `MCP_WORLD_DIR`
33
+ - Denial of service through oversized tool input or snapshots
34
+ - Data loss when persisting world state
35
+
36
+ The following are generally out of scope: running the server with an
37
+ untrusted `MCP_WORLD_DIR`, modifying files on disk without restarting the
38
+ server, and issues that require an already-compromised host.
@@ -1,12 +1,13 @@
1
1
  import { MINECRAFT_BLOCK_COUNT } from '../data/blocks.js';
2
+ import { MINECRAFT_ENTITY_COUNT } from '../data/entities.js';
2
3
  import { MINECRAFT_ITEM_COUNT } from '../data/items.js';
3
4
  import { MINECRAFT_DATA_VERSION } from '../data/version.js';
4
5
  import { EIconTheme } from '../enums/icon-theme.enum.js';
5
6
  export const SERVER_INFO = {
6
7
  name: 'lzimul',
7
8
  title: 'lZiMUl Minecraft MCP',
8
- description: `Minecraft Model Context Protocol server (Java Edition ${MINECRAFT_DATA_VERSION}): exposes all ${MINECRAFT_BLOCK_COUNT} blocks and ${MINECRAFT_ITEM_COUNT} items with their properties (name, hardness, blast resistance, durability, enchantment categories, etc.) as resources, plus tools to get and place blocks and look up items.`,
9
- version: '1.0.2',
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 and place blocks, inspect dimensions, create entities and players, and manage their hotbar and backpack inventories.`,
10
+ version: '1.0.4',
10
11
  websiteUrl: 'https://mcp.lzimul.com/lZiMUl',
11
12
  icons: [
12
13
  {
@@ -3,5 +3,8 @@ export const WORLD_LIMITS = {
3
3
  maxHorizontal: 30000000,
4
4
  minVertical: -64,
5
5
  maxVertical: 320,
6
- maxModifiedBlocks: 250_000
6
+ maxModifiedBlocks: 250_000,
7
+ maxEntitiesPerDimension: 10_000,
8
+ maxEntityNameLength: 64,
9
+ maxPlayerNameLength: 32
7
10
  };