mcbe-ws-sdk 0.1.0__tar.gz

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 (105) hide show
  1. mcbe_ws_sdk-0.1.0/.gitignore +48 -0
  2. mcbe_ws_sdk-0.1.0/LICENSE +21 -0
  3. mcbe_ws_sdk-0.1.0/PKG-INFO +138 -0
  4. mcbe_ws_sdk-0.1.0/README.md +108 -0
  5. mcbe_ws_sdk-0.1.0/README.zh.md +105 -0
  6. mcbe_ws_sdk-0.1.0/addon/README.md +116 -0
  7. mcbe_ws_sdk-0.1.0/addon/README.zh.md +110 -0
  8. mcbe_ws_sdk-0.1.0/addon/behavior_packs/mc-ws-sdk/manifest.json +46 -0
  9. mcbe_ws_sdk-0.1.0/addon/behavior_packs/mc-ws-sdk/pack_icon.png +0 -0
  10. mcbe_ws_sdk-0.1.0/addon/package-lock.json +5681 -0
  11. mcbe_ws_sdk-0.1.0/addon/package.json +39 -0
  12. mcbe_ws_sdk-0.1.0/addon/resource_packs/mc-ws-sdk/manifest.json +30 -0
  13. mcbe_ws_sdk-0.1.0/addon/resource_packs/mc-ws-sdk/pack_icon.png +0 -0
  14. mcbe_ws_sdk-0.1.0/addon/scripts/bootstrap.ts +79 -0
  15. mcbe_ws_sdk-0.1.0/addon/scripts/bridge/capabilities/commandSafety.ts +92 -0
  16. mcbe_ws_sdk-0.1.0/addon/scripts/bridge/capabilities/getInventorySnapshot.ts +65 -0
  17. mcbe_ws_sdk-0.1.0/addon/scripts/bridge/capabilities/getPlayerSnapshot.ts +42 -0
  18. mcbe_ws_sdk-0.1.0/addon/scripts/bridge/capabilities/index.ts +19 -0
  19. mcbe_ws_sdk-0.1.0/addon/scripts/bridge/capabilities/runWorldCommand.ts +49 -0
  20. mcbe_ws_sdk-0.1.0/addon/scripts/bridge/chunking.ts +76 -0
  21. mcbe_ws_sdk-0.1.0/addon/scripts/bridge/constants.ts +21 -0
  22. mcbe_ws_sdk-0.1.0/addon/scripts/bridge/responseSync.ts +227 -0
  23. mcbe_ws_sdk-0.1.0/addon/scripts/bridge/router.ts +320 -0
  24. mcbe_ws_sdk-0.1.0/addon/scripts/bridge/testing.ts +5 -0
  25. mcbe_ws_sdk-0.1.0/addon/scripts/bridge/toolPlayer.ts +87 -0
  26. mcbe_ws_sdk-0.1.0/addon/scripts/main.ts +12 -0
  27. mcbe_ws_sdk-0.1.0/addon/scripts/runtime-globals.d.ts +7 -0
  28. mcbe_ws_sdk-0.1.0/addon/tests/__mocks__/minecraft-server-gametest.ts +3 -0
  29. mcbe_ws_sdk-0.1.0/addon/tests/__mocks__/minecraft-server-ui.ts +3 -0
  30. mcbe_ws_sdk-0.1.0/addon/tests/__mocks__/minecraft-server.ts +132 -0
  31. mcbe_ws_sdk-0.1.0/addon/tests/capabilities.test.ts +38 -0
  32. mcbe_ws_sdk-0.1.0/addon/tests/chunking.test.ts +191 -0
  33. mcbe_ws_sdk-0.1.0/addon/tests/main.test.ts +96 -0
  34. mcbe_ws_sdk-0.1.0/addon/tests/manifest.test.ts +47 -0
  35. mcbe_ws_sdk-0.1.0/addon/tests/responseSync.test.ts +367 -0
  36. mcbe_ws_sdk-0.1.0/addon/tests/router.test.ts +471 -0
  37. mcbe_ws_sdk-0.1.0/addon/tests/test-baseline.test.ts +12 -0
  38. mcbe_ws_sdk-0.1.0/addon/tsconfig.json +31 -0
  39. mcbe_ws_sdk-0.1.0/addon/tsconfig.test.json +14 -0
  40. mcbe_ws_sdk-0.1.0/addon/vitest.config.ts +17 -0
  41. mcbe_ws_sdk-0.1.0/examples/addon-capability-call/README.md +9 -0
  42. mcbe_ws_sdk-0.1.0/examples/addon-capability-call/capability_call.py +54 -0
  43. mcbe_ws_sdk-0.1.0/examples/addon-server/README.md +175 -0
  44. mcbe_ws_sdk-0.1.0/examples/addon-server/README.zh.md +165 -0
  45. mcbe_ws_sdk-0.1.0/examples/addon-server/server.py +729 -0
  46. mcbe_ws_sdk-0.1.0/examples/basic-server/README.md +68 -0
  47. mcbe_ws_sdk-0.1.0/examples/basic-server/README.zh.md +85 -0
  48. mcbe_ws_sdk-0.1.0/examples/basic-server/server.py +217 -0
  49. mcbe_ws_sdk-0.1.0/pyproject.toml +106 -0
  50. mcbe_ws_sdk-0.1.0/src/mcbe_ws_sdk/__init__.py +126 -0
  51. mcbe_ws_sdk-0.1.0/src/mcbe_ws_sdk/addon/__init__.py +17 -0
  52. mcbe_ws_sdk-0.1.0/src/mcbe_ws_sdk/addon/service.py +239 -0
  53. mcbe_ws_sdk-0.1.0/src/mcbe_ws_sdk/addon/session.py +256 -0
  54. mcbe_ws_sdk-0.1.0/src/mcbe_ws_sdk/command/__init__.py +5 -0
  55. mcbe_ws_sdk-0.1.0/src/mcbe_ws_sdk/command/registry.py +176 -0
  56. mcbe_ws_sdk-0.1.0/src/mcbe_ws_sdk/config.py +119 -0
  57. mcbe_ws_sdk-0.1.0/src/mcbe_ws_sdk/delivery/__init__.py +5 -0
  58. mcbe_ws_sdk-0.1.0/src/mcbe_ws_sdk/delivery/outbound.py +165 -0
  59. mcbe_ws_sdk-0.1.0/src/mcbe_ws_sdk/errors.py +45 -0
  60. mcbe_ws_sdk-0.1.0/src/mcbe_ws_sdk/flow/__init__.py +9 -0
  61. mcbe_ws_sdk-0.1.0/src/mcbe_ws_sdk/flow/flow_control.py +332 -0
  62. mcbe_ws_sdk-0.1.0/src/mcbe_ws_sdk/gateway/__init__.py +49 -0
  63. mcbe_ws_sdk-0.1.0/src/mcbe_ws_sdk/gateway/connection.py +249 -0
  64. mcbe_ws_sdk-0.1.0/src/mcbe_ws_sdk/gateway/events.py +138 -0
  65. mcbe_ws_sdk-0.1.0/src/mcbe_ws_sdk/gateway/handler.py +181 -0
  66. mcbe_ws_sdk-0.1.0/src/mcbe_ws_sdk/gateway/hook.py +107 -0
  67. mcbe_ws_sdk-0.1.0/src/mcbe_ws_sdk/gateway/messages.py +46 -0
  68. mcbe_ws_sdk-0.1.0/src/mcbe_ws_sdk/gateway/server_facade.py +462 -0
  69. mcbe_ws_sdk-0.1.0/src/mcbe_ws_sdk/gateway/sink.py +123 -0
  70. mcbe_ws_sdk-0.1.0/src/mcbe_ws_sdk/logging.py +90 -0
  71. mcbe_ws_sdk-0.1.0/src/mcbe_ws_sdk/profiles/__init__.py +36 -0
  72. mcbe_ws_sdk-0.1.0/src/mcbe_ws_sdk/profiles/mcbews_v1/__init__.py +8 -0
  73. mcbe_ws_sdk-0.1.0/src/mcbe_ws_sdk/profiles/mcbews_v1/codec.py +208 -0
  74. mcbe_ws_sdk-0.1.0/src/mcbe_ws_sdk/profiles/mcbews_v1/delivery.py +48 -0
  75. mcbe_ws_sdk-0.1.0/src/mcbe_ws_sdk/profiles/mcbews_v1/models.py +47 -0
  76. mcbe_ws_sdk-0.1.0/src/mcbe_ws_sdk/profiles/mcbews_v1/profile.py +34 -0
  77. mcbe_ws_sdk-0.1.0/src/mcbe_ws_sdk/protocol/__init__.py +13 -0
  78. mcbe_ws_sdk-0.1.0/src/mcbe_ws_sdk/protocol/minecraft.py +245 -0
  79. mcbe_ws_sdk-0.1.0/src/mcbe_ws_sdk/py.typed +1 -0
  80. mcbe_ws_sdk-0.1.0/tests/conftest.py +13 -0
  81. mcbe_ws_sdk-0.1.0/tests/fixtures/mcbews_v1_vectors.json +14 -0
  82. mcbe_ws_sdk-0.1.0/tests/release/test_distribution.py +251 -0
  83. mcbe_ws_sdk-0.1.0/tests/release/test_release_tag.py +54 -0
  84. mcbe_ws_sdk-0.1.0/tests/release/test_workflows.py +51 -0
  85. mcbe_ws_sdk-0.1.0/tests/smoke/__init__.py +0 -0
  86. mcbe_ws_sdk-0.1.0/tests/smoke/test_examples.py +39 -0
  87. mcbe_ws_sdk-0.1.0/tests/unit/__init__.py +0 -0
  88. mcbe_ws_sdk-0.1.0/tests/unit/test_addon_bridge.py +501 -0
  89. mcbe_ws_sdk-0.1.0/tests/unit/test_addon_request.py +36 -0
  90. mcbe_ws_sdk-0.1.0/tests/unit/test_command.py +70 -0
  91. mcbe_ws_sdk-0.1.0/tests/unit/test_config.py +170 -0
  92. mcbe_ws_sdk-0.1.0/tests/unit/test_connection.py +23 -0
  93. mcbe_ws_sdk-0.1.0/tests/unit/test_connection_manager.py +229 -0
  94. mcbe_ws_sdk-0.1.0/tests/unit/test_delivery.py +109 -0
  95. mcbe_ws_sdk-0.1.0/tests/unit/test_events.py +174 -0
  96. mcbe_ws_sdk-0.1.0/tests/unit/test_flow_control.py +60 -0
  97. mcbe_ws_sdk-0.1.0/tests/unit/test_handler.py +88 -0
  98. mcbe_ws_sdk-0.1.0/tests/unit/test_hook.py +76 -0
  99. mcbe_ws_sdk-0.1.0/tests/unit/test_logging.py +37 -0
  100. mcbe_ws_sdk-0.1.0/tests/unit/test_mcbews_v1.py +162 -0
  101. mcbe_ws_sdk-0.1.0/tests/unit/test_protocol.py +155 -0
  102. mcbe_ws_sdk-0.1.0/tests/unit/test_protocol_names.py +18 -0
  103. mcbe_ws_sdk-0.1.0/tests/unit/test_public_api.py +59 -0
  104. mcbe_ws_sdk-0.1.0/tests/unit/test_server_facade.py +849 -0
  105. mcbe_ws_sdk-0.1.0/tests/unit/test_sink.py +112 -0
@@ -0,0 +1,48 @@
1
+ # Python
2
+ __pycache__/
3
+ *.py[cod]
4
+ *.egg-info/
5
+ .eggs/
6
+ dist/
7
+ build/
8
+ *.whl
9
+
10
+ # Virtual envs
11
+ .venv/
12
+ venv/
13
+ .env
14
+
15
+ # Type check / lint caches
16
+ .mypy_cache/
17
+ .ruff_cache/
18
+ .pyre/
19
+ .pytype/
20
+
21
+ # Test / coverage
22
+ .pytest_cache/
23
+ .pytest_dist_cache/
24
+ .coverage
25
+ coverage.xml
26
+ htmlcov/
27
+ .tox/
28
+ .nox/
29
+
30
+ # IDE / editor
31
+ .vscode/
32
+ .idea/
33
+ *.swp
34
+ *.swo
35
+ *~
36
+
37
+ # OS
38
+ .DS_Store
39
+ Thumbs.db
40
+
41
+ # Logs
42
+ *.log
43
+
44
+ docs/superpowers
45
+ .firecrawl
46
+
47
+ # MkDocs
48
+ /site/
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 mcbe-ws-sdk contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,138 @@
1
+ Metadata-Version: 2.4
2
+ Name: mcbe-ws-sdk
3
+ Version: 0.1.0
4
+ Summary: Generic WebSocket gateway SDK for Minecraft Bedrock Edition
5
+ Author: mcbe-ws-sdk contributors
6
+ License: MIT
7
+ License-File: LICENSE
8
+ Requires-Python: >=3.11
9
+ Requires-Dist: pydantic>=2.0
10
+ Requires-Dist: structlog>=24.0
11
+ Requires-Dist: websockets<17,>=12
12
+ Provides-Extra: dev
13
+ Requires-Dist: build; extra == 'dev'
14
+ Requires-Dist: mypy; extra == 'dev'
15
+ Requires-Dist: pytest; extra == 'dev'
16
+ Requires-Dist: pytest-asyncio; extra == 'dev'
17
+ Requires-Dist: pytest-cov; extra == 'dev'
18
+ Requires-Dist: pyyaml<7,>=6; extra == 'dev'
19
+ Requires-Dist: ruff; extra == 'dev'
20
+ Requires-Dist: types-pyyaml<7,>=6; extra == 'dev'
21
+ Provides-Extra: docs
22
+ Requires-Dist: mkdocs-material>=9.5; extra == 'docs'
23
+ Requires-Dist: mkdocs-static-i18n>=1.2; extra == 'docs'
24
+ Requires-Dist: mkdocs>=1.6; extra == 'docs'
25
+ Requires-Dist: mkdocstrings[python]>=0.27; extra == 'docs'
26
+ Provides-Extra: release
27
+ Requires-Dist: build; extra == 'release'
28
+ Requires-Dist: twine; extra == 'release'
29
+ Description-Content-Type: text/markdown
30
+
31
+ # mcbe-ws-sdk
32
+
33
+ [![Languages](https://img.shields.io/badge/Languages-中文-blue?style=flat-square)](./README.zh.md)
34
+ [![Python](https://img.shields.io/badge/Python-3.11%2B-blue?style=flat-square)](https://www.python.org/)
35
+ [![License](https://img.shields.io/badge/License-MIT-green?style=flat-square)](./LICENSE)
36
+
37
+ Generic **WebSocket gateway SDK** for Minecraft Bedrock Edition.
38
+
39
+ It owns the WS transport, packet protocol, and byte-safe command chunking
40
+ (461-byte hard limit). Your host injects behaviour through `ConnectionHook` and
41
+ `ResponseSink`, and drives the stack with `McbeServerFacade`.
42
+
43
+ There is **no** message broker and **no** LLM worker inside the SDK — those stay
44
+ in the host application.
45
+
46
+ ```text
47
+ Minecraft client ←── /wsserver IP:port ──→ Your Python host (this SDK)
48
+ ```
49
+
50
+ ## Install
51
+
52
+ ```bash
53
+ pip install mcbe-ws-sdk
54
+ ```
55
+
56
+ Editable install for development:
57
+
58
+ ```bash
59
+ pip install -e ".[dev,docs]"
60
+ ```
61
+
62
+ Requires **Python 3.11+**.
63
+
64
+ ## 30-second taste
65
+
66
+ ```python
67
+ import asyncio
68
+ from mcbe_ws_sdk import McbeServerFacade, NoOpHook
69
+
70
+
71
+ class MyHook(NoOpHook):
72
+ async def on_connected(self, state):
73
+ print("connected:", state.id)
74
+
75
+ async def on_player_message(self, state, event, parsed=None):
76
+ print(f"{event.sender}: {event.message}")
77
+
78
+
79
+ async def main() -> None:
80
+ facade = McbeServerFacade(hook=MyHook())
81
+ print(f"ws://{facade.settings.websocket.host}:{facade.settings.websocket.port}")
82
+ await facade.run_lifetime()
83
+
84
+
85
+ if __name__ == "__main__":
86
+ asyncio.run(main())
87
+ ```
88
+
89
+ Then in Minecraft: `/wsserver <this-machine-ip>:8080`
90
+
91
+ For a **reply-with-tellraw** host, run the ready-made example:
92
+
93
+ ```bash
94
+ python examples/basic-server/server.py
95
+ ```
96
+
97
+ ## Documentation
98
+
99
+ Full beginner tutorial, architecture, protocol, and API reference live on the
100
+ docs site (English + 中文):
101
+
102
+ | | |
103
+ |---|---|
104
+ | **Online** | https://rice-awa.github.io/mcbe-ws-sdk/ |
105
+ | **Local** | `pip install -e ".[docs]" && mkdocs serve` → http://127.0.0.1:8000 |
106
+
107
+ | Page | Content |
108
+ |------|---------|
109
+ | [Getting Started](./docs/getting-started.md) | Install, 5-minute walkthrough, minimal echo bot, FAQ |
110
+ | [Architecture](./docs/architecture.md) | Layer stack and dependency inversion |
111
+ | [Protocol](./docs/addon-bridge-protocol.md) | mcbews v1 bridge wire format |
112
+ | [API Reference](./docs/reference.md) | Generated from source |
113
+
114
+ ## Examples
115
+
116
+ | Path | What it shows |
117
+ |------|---------------|
118
+ | [`examples/basic-server/`](./examples/basic-server/) | Echo chat with `tellraw` (start here) |
119
+ | [`examples/addon-server/`](./examples/addon-server/) | Capability calls via the companion addon |
120
+ | [`examples/addon-capability-call/`](./examples/addon-capability-call/) | In-memory bridge round-trip (no game) |
121
+
122
+ Companion TypeScript addon: [`addon/`](./addon/). Worlds that load it must enable
123
+ **Experiments → Beta APIs** (see [addon README](./addon/README.md#enable-in-a-world)).
124
+
125
+ ## Development
126
+
127
+ ```bash
128
+ pip install -e ".[dev,docs]"
129
+ ruff check --no-cache src tests examples
130
+ mypy --no-incremental src
131
+ pytest -p no:cacheprovider -q
132
+ python tools/format.py # ruff format+fix (Python); prettier (Addon if Node)
133
+ python tools/format.py --check # CI-style check
134
+ ```
135
+
136
+ ## License
137
+
138
+ [MIT](./LICENSE)
@@ -0,0 +1,108 @@
1
+ # mcbe-ws-sdk
2
+
3
+ [![Languages](https://img.shields.io/badge/Languages-中文-blue?style=flat-square)](./README.zh.md)
4
+ [![Python](https://img.shields.io/badge/Python-3.11%2B-blue?style=flat-square)](https://www.python.org/)
5
+ [![License](https://img.shields.io/badge/License-MIT-green?style=flat-square)](./LICENSE)
6
+
7
+ Generic **WebSocket gateway SDK** for Minecraft Bedrock Edition.
8
+
9
+ It owns the WS transport, packet protocol, and byte-safe command chunking
10
+ (461-byte hard limit). Your host injects behaviour through `ConnectionHook` and
11
+ `ResponseSink`, and drives the stack with `McbeServerFacade`.
12
+
13
+ There is **no** message broker and **no** LLM worker inside the SDK — those stay
14
+ in the host application.
15
+
16
+ ```text
17
+ Minecraft client ←── /wsserver IP:port ──→ Your Python host (this SDK)
18
+ ```
19
+
20
+ ## Install
21
+
22
+ ```bash
23
+ pip install mcbe-ws-sdk
24
+ ```
25
+
26
+ Editable install for development:
27
+
28
+ ```bash
29
+ pip install -e ".[dev,docs]"
30
+ ```
31
+
32
+ Requires **Python 3.11+**.
33
+
34
+ ## 30-second taste
35
+
36
+ ```python
37
+ import asyncio
38
+ from mcbe_ws_sdk import McbeServerFacade, NoOpHook
39
+
40
+
41
+ class MyHook(NoOpHook):
42
+ async def on_connected(self, state):
43
+ print("connected:", state.id)
44
+
45
+ async def on_player_message(self, state, event, parsed=None):
46
+ print(f"{event.sender}: {event.message}")
47
+
48
+
49
+ async def main() -> None:
50
+ facade = McbeServerFacade(hook=MyHook())
51
+ print(f"ws://{facade.settings.websocket.host}:{facade.settings.websocket.port}")
52
+ await facade.run_lifetime()
53
+
54
+
55
+ if __name__ == "__main__":
56
+ asyncio.run(main())
57
+ ```
58
+
59
+ Then in Minecraft: `/wsserver <this-machine-ip>:8080`
60
+
61
+ For a **reply-with-tellraw** host, run the ready-made example:
62
+
63
+ ```bash
64
+ python examples/basic-server/server.py
65
+ ```
66
+
67
+ ## Documentation
68
+
69
+ Full beginner tutorial, architecture, protocol, and API reference live on the
70
+ docs site (English + 中文):
71
+
72
+ | | |
73
+ |---|---|
74
+ | **Online** | https://rice-awa.github.io/mcbe-ws-sdk/ |
75
+ | **Local** | `pip install -e ".[docs]" && mkdocs serve` → http://127.0.0.1:8000 |
76
+
77
+ | Page | Content |
78
+ |------|---------|
79
+ | [Getting Started](./docs/getting-started.md) | Install, 5-minute walkthrough, minimal echo bot, FAQ |
80
+ | [Architecture](./docs/architecture.md) | Layer stack and dependency inversion |
81
+ | [Protocol](./docs/addon-bridge-protocol.md) | mcbews v1 bridge wire format |
82
+ | [API Reference](./docs/reference.md) | Generated from source |
83
+
84
+ ## Examples
85
+
86
+ | Path | What it shows |
87
+ |------|---------------|
88
+ | [`examples/basic-server/`](./examples/basic-server/) | Echo chat with `tellraw` (start here) |
89
+ | [`examples/addon-server/`](./examples/addon-server/) | Capability calls via the companion addon |
90
+ | [`examples/addon-capability-call/`](./examples/addon-capability-call/) | In-memory bridge round-trip (no game) |
91
+
92
+ Companion TypeScript addon: [`addon/`](./addon/). Worlds that load it must enable
93
+ **Experiments → Beta APIs** (see [addon README](./addon/README.md#enable-in-a-world)).
94
+
95
+ ## Development
96
+
97
+ ```bash
98
+ pip install -e ".[dev,docs]"
99
+ ruff check --no-cache src tests examples
100
+ mypy --no-incremental src
101
+ pytest -p no:cacheprovider -q
102
+ python tools/format.py # ruff format+fix (Python); prettier (Addon if Node)
103
+ python tools/format.py --check # CI-style check
104
+ ```
105
+
106
+ ## License
107
+
108
+ [MIT](./LICENSE)
@@ -0,0 +1,105 @@
1
+ # mcbe-ws-sdk
2
+
3
+ [![Languages](https://img.shields.io/badge/Languages-English-blue?style=flat-square)](./README.md)
4
+ [![Python](https://img.shields.io/badge/Python-3.11%2B-blue?style=flat-square)](https://www.python.org/)
5
+ [![License](https://img.shields.io/badge/License-MIT-green?style=flat-square)](./LICENSE)
6
+
7
+ 面向 **Minecraft 基岩版(Bedrock)** 的通用 **WebSocket 网关 SDK**。
8
+
9
+ 本包拥有 WS 传输、数据包协议与字节安全的命令分片(461 字节硬上限)。宿主通过
10
+ `ConnectionHook` 与 `ResponseSink` 注入行为,并由 `McbeServerFacade` 驱动整条链路。
11
+
12
+ SDK 内部**不包含**消息 broker 或 LLM worker —— 这些关切完全属于宿主应用。
13
+
14
+ ```text
15
+ Minecraft 客户端 ←── /wsserver IP:端口 ──→ 你的 Python 宿主(本 SDK)
16
+ ```
17
+
18
+ ## 安装
19
+
20
+ ```bash
21
+ pip install mcbe-ws-sdk
22
+ ```
23
+
24
+ 开发时的可编辑安装:
25
+
26
+ ```bash
27
+ pip install -e ".[dev,docs]"
28
+ ```
29
+
30
+ 需要 **Python 3.11+**。
31
+
32
+ ## 30 秒体验
33
+
34
+ ```python
35
+ import asyncio
36
+ from mcbe_ws_sdk import McbeServerFacade, NoOpHook
37
+
38
+
39
+ class MyHook(NoOpHook):
40
+ async def on_connected(self, state):
41
+ print("connected:", state.id)
42
+
43
+ async def on_player_message(self, state, event, parsed=None):
44
+ print(f"{event.sender}: {event.message}")
45
+
46
+
47
+ async def main() -> None:
48
+ facade = McbeServerFacade(hook=MyHook())
49
+ print(f"ws://{facade.settings.websocket.host}:{facade.settings.websocket.port}")
50
+ await facade.run_lifetime()
51
+
52
+
53
+ if __name__ == "__main__":
54
+ asyncio.run(main())
55
+ ```
56
+
57
+ 然后在游戏里执行:`/wsserver <本机IP>:8080`
58
+
59
+ 若要「收到消息并用 tellraw 回复」,直接跑现成示例:
60
+
61
+ ```bash
62
+ python examples/basic-server/server.py
63
+ ```
64
+
65
+ ## 文档
66
+
67
+ 完整新手教程、架构、协议与 API 参考在文档站(中英双语):
68
+
69
+ | | |
70
+ |---|---|
71
+ | **在线** | https://rice-awa.github.io/mcbe-ws-sdk/zh/ |
72
+ | **本地** | `pip install -e ".[docs]" && mkdocs serve` → http://127.0.0.1:8000/zh/ |
73
+
74
+ | 页面 | 内容 |
75
+ |------|------|
76
+ | [快速开始](./docs/getting-started.zh.md) | 安装、5 分钟上手、最小回声机器人、FAQ |
77
+ | [架构](./docs/architecture.zh.md) | 分层栈与依赖倒置 |
78
+ | [协议](./docs/addon-bridge-protocol.zh.md) | mcbews v1 桥接线格式 |
79
+ | [API 参考](./docs/reference.zh.md) | 从源码生成(导读见中文站) |
80
+
81
+ ## 示例
82
+
83
+ | 路径 | 说明 |
84
+ |------|------|
85
+ | [`examples/basic-server/`](./examples/basic-server/) | 聊天回声 + `tellraw`(推荐先看) |
86
+ | [`examples/addon-server/`](./examples/addon-server/) | 通过配套 addon 调用能力 |
87
+ | [`examples/addon-capability-call/`](./examples/addon-capability-call/) | 内存中的桥接往返(不连游戏) |
88
+
89
+ 配套 TypeScript addon:[`addon/`](./addon/)。加载该包的世界必须开启
90
+ **实验 → 测试版 API**(详见 [addon README](./addon/README.zh.md#%E5%9C%A8%E4%B8%96%E7%95%8C%E4%B8%AD%E5%90%AF%E7%94%A8))。
91
+
92
+ ## 开发
93
+
94
+ ```bash
95
+ pip install -e ".[dev,docs]"
96
+ ruff check --no-cache src tests examples
97
+ mypy --no-incremental src
98
+ pytest -p no:cacheprovider -q
99
+ python tools/format.py # ruff format+fix(Python);有 Node 时跑 prettier(Addon)
100
+ python tools/format.py --check # CI 风格只检查不写入
101
+ ```
102
+
103
+ ## License
104
+
105
+ [MIT](./LICENSE)
@@ -0,0 +1,116 @@
1
+ [![Languages](https://img.shields.io/badge/Languages-中文-blue?style=flat-square)](./README.zh.md)
2
+
3
+ # MCBE WS Bridge Addon
4
+
5
+ Minimal Minecraft Bedrock WebSocket bridge addon — the TypeScript counterpart of the
6
+ `mcbe-ws-sdk` Python package. This addon handles the protocol layer:
7
+
8
+ - `constants.ts` — wire protocol constants matching Python `McbewsV1Profile`
9
+ - `chunking.ts` — encode/decode for `MCBEWS|BRIDGE` and `MCBEWS|UI_CHAT` fragments
10
+ - `router.ts` — subscribes to `mcbews:bridge_req` scriptevents, dispatches to the
11
+ built-in capability registry, and ships the response back
12
+ - `responseSync.ts` — reassembles `mcbews:text_resp` chunks and invokes a callback
13
+ - `toolPlayer.ts` — marks a player as a towered transport per response delivery (tellraw)
14
+ - `bootstrap.ts` — safe init lifecycle (early init → after-world-load)
15
+
16
+ The addon owns the full capability-handling lifecycle. Capabilities are dispatched
17
+ through the built-in default capability registry in `capabilities/index.ts`.
18
+ The Python SDK has no inbound capability registry — it sends requests and receives
19
+ responses.
20
+
21
+ ## Usage
22
+
23
+ From a Python host, `AddonBridgeService` + `AddonBridgeClient` sends capability
24
+ requests; the addon picks them up and delivers them in-game.
25
+
26
+ From the addon side, capabilities are registered by appending entries to
27
+ the default registry in `capabilities/index.ts`. The router dispatches
28
+ automatically.
29
+
30
+ ### TypeScript host (override mode)
31
+
32
+ When a TypeScript host needs full control, it can override the built-in registry:
33
+
34
+ ```ts
35
+ import { setCapabilityHandler } from "./bridge/router";
36
+
37
+ setCapabilityHandler((capability, payload) => {
38
+ // dispatch by name; return { ok: true, ... } or { ok: false, error: "..." }
39
+ });
40
+ ```
41
+
42
+ Then in `main.ts`:
43
+
44
+ ```ts
45
+ import { initializeEarly, initializeAfterWorldLoad } from "./bootstrap";
46
+
47
+ initializeEarly();
48
+ initializeAfterWorldLoad(() => {
49
+ /* register handlers here */
50
+ });
51
+ ```
52
+
53
+ ## Build
54
+
55
+ ```bash
56
+ npm install
57
+ npm run build # tsc type-check gate (intermediate output to lib/) + esbuild bundle
58
+ npm run mcaddon # assemble .mcaddon on top of build output
59
+ ```
60
+
61
+ The build pipeline has two steps:
62
+
63
+ 1. **`tsc` type-check gate**: type-checks the source, emitting intermediate output to `lib/` (used for type checking only — not the final artifact).
64
+ 2. **esbuild `bundle` task**: produces the real final artifact `dist/scripts/main.js`, then `copyArtifacts` copies `dist/scripts` into the behavior pack, matching the manifest `"entry": "scripts/main.js"`.
65
+
66
+ The artifact that loads in-game is `scripts/main.js` — treat that as authoritative, not the intermediate output under `lib/`.
67
+
68
+ ## Enable in a world
69
+
70
+ 1. Import the generated `.mcaddon` (or copy the behavior / resource packs) into Minecraft.
71
+ 2. Open the **target world** settings (create a new world, or **Edit** an existing one).
72
+ 3. Under **Experiments**, turn on **Beta APIs**.
73
+ 4. Activate this pack in **Behavior Packs** (and the companion resource pack if prompted).
74
+ 5. Enter the world, then connect with `/wsserver <host-ip>:8080`.
75
+
76
+ > **Required: Beta APIs**
77
+ > This addon depends on the Minecraft Script API (`@minecraft/server`,
78
+ > `@minecraft/server-ui`, and a beta `@minecraft/server-gametest` module).
79
+ > If **Experiments → Beta APIs** is off, scripts will not load: capability
80
+ > requests time out, and you will see no bridge activity in-game.
81
+ > Enabling experiments may make the world ineligible for some achievements /
82
+ > features — use a dedicated test world when possible.
83
+
84
+ ## Built-in Capabilities
85
+
86
+ The addon ships a ready-to-use capability registry
87
+ (`scripts/bridge/capabilities/index.ts`) as a runnable reference example.
88
+
89
+ | Capability | File | Description |
90
+ | ------------------------ | ------------------------- | ----------------------------------------------------------------------------- |
91
+ | `get_player_snapshot` | `getPlayerSnapshot.ts` | Get a player snapshot (name, health, tags, coordinates, dimension, game mode) |
92
+ | `get_inventory_snapshot` | `getInventorySnapshot.ts` | Get a player inventory snapshot (slots, item ID, count, custom name) |
93
+ | `run_world_command` | `runWorldCommand.ts` | Run an MC command in the world (guarded by the `commandSafety.ts` blacklist) |
94
+
95
+ Developers add custom capabilities by appending entries to
96
+ the default registry in `capabilities/index.ts`, coexisting with the
97
+ built-in capabilities and still looked up by `router.ts` by capability name.
98
+
99
+ > Note: `find_entities` is not yet bundled. The current protocol's `scriptevent` does not carry the source-player context, while an entity query needs that context to scope the search; once the protocol supports player-sourced scriptevents, this capability will be added.
100
+
101
+ ## Trust boundary
102
+
103
+ The bridge is **not** a security boundary. The host application must authenticate
104
+ and authorize who can call capabilities — the addon only enforces a defensive
105
+ command filter on the world-command path.
106
+
107
+ - `run_world_command` is intentionally **not** in the default Python registry
108
+ (and not in the addon's default capability registry either). Hosts that need
109
+ it must register the handler explicitly.
110
+ - When registered, the default allowlist is `["say"]` only. A denylist of
111
+ dangerous commands (`execute`, `script`, `op`, `setblock`, `fill`, …) is a
112
+ second line of defense and still applies even if a host widens the allowlist.
113
+
114
+ ## License
115
+
116
+ MIT
@@ -0,0 +1,110 @@
1
+ [![Languages](https://img.shields.io/badge/Languages-English-blue?style=flat-square)](./README.md)
2
+
3
+ # MCBE WS Bridge Addon
4
+
5
+ 极简的 Minecraft Bedrock WebSocket 桥接 addon —— `mcbe-ws-sdk` Python 包的 TypeScript 对等实现。本 addon 负责协议层:
6
+
7
+ - `constants.ts` — 与 Python `McbewsV1Profile` 对齐的 wire protocol 常量
8
+ - `chunking.ts` — `MCBEWS|BRIDGE` 与 `MCBEWS|UI_CHAT` 分片的编解码
9
+ - `router.ts` — 订阅 `mcbews:bridge_req` scriptevent,分发到内置能力注册表并将响应回送
10
+ - `responseSync.ts` — 重组 `mcbews:text_resp` 分片并触发回调
11
+ - `toolPlayer.ts` — 为每次响应投递(tellraw)标记一个"塔式传输"玩家
12
+ - `bootstrap.ts` — 安全的初始化生命周期(早期初始化 → 世界加载完成后)
13
+
14
+ Addon 完全拥有能力处理生命周期。能力通过 `capabilities/index.ts` 中的内置
15
+ 能力注册表进行分发。Python SDK 不包含入站能力注册表 —— 它发送请求
16
+ 并接收响应。
17
+
18
+ ## 用法
19
+
20
+ 从 Python 宿主出发,`AddonBridgeService` + `AddonBridgeClient` 发送能力请求;
21
+ addon 接收并在游戏内投递。
22
+
23
+ 从 addon 侧出发,通过在 `capabilities/index.ts` 的能力注册表中
24
+ 追加条目来注册能力。路由器会自动分发。
25
+
26
+ ### TypeScript 宿主(覆盖模式)
27
+
28
+ 当 TypeScript 宿主需要完全控制时,可以覆盖内置注册表:
29
+
30
+ ```ts
31
+ import { setCapabilityHandler } from "./bridge/router";
32
+
33
+ setCapabilityHandler((capability, payload) => {
34
+ // 按名称分发;返回 { ok: true, ... } 或 { ok: false, error: "..." }
35
+ });
36
+ ```
37
+
38
+ 然后在 `main.ts` 中:
39
+
40
+ ```ts
41
+ import { initializeEarly, initializeAfterWorldLoad } from "./bootstrap";
42
+
43
+ initializeEarly();
44
+ initializeAfterWorldLoad(() => {
45
+ /* 在此注册处理器 */
46
+ });
47
+ ```
48
+
49
+ ## 构建
50
+
51
+ ```bash
52
+ npm install
53
+ npm run build # tsc 类型检查门卫(中间产物输出到 lib/)+ esbuild 打包
54
+ npm run mcaddon # 在构建产物基础上组装 .mcaddon
55
+ ```
56
+
57
+ 构建流水线分两步:
58
+
59
+ 1. **`tsc` 类型检查门卫**:对源码做类型校验,中间产物输出到 `lib/`(仅用于类型检查,并非最终产物)。
60
+ 2. **esbuild `bundle` 任务**:产出真正的最终产物 `dist/scripts/main.js`,随后由 `copyArtifacts` 将 `dist/scripts` 复制进 behavior_pack,与 manifest 的 `"entry": "scripts/main.js"` 对应。
61
+
62
+ 最终在游戏内加载的是 `scripts/main.js`,请以此为准,而非 `lib/` 下的中间产物。
63
+
64
+ ## 在世界中启用
65
+
66
+ 1. 将生成的 `.mcaddon` 导入 Minecraft(或手动复制行为包 / 资源包)。
67
+ 2. 打开**目标世界**的设置(新建世界,或对已有世界点**编辑**)。
68
+ 3. 在 **实验**(Experiments)里打开 **测试版 API**(Beta APIs)。
69
+ 4. 在 **行为包** 中启用本包(如提示配套资源包也一并启用)。
70
+ 5. 进入世界后,再执行 `/wsserver <主机IP>:8080` 连接。
71
+
72
+ > **必开:测试版 API**
73
+ > 本 addon 依赖 Minecraft Script API(`@minecraft/server`、
74
+ > `@minecraft/server-ui`,以及 beta 的 `@minecraft/server-gametest`)。
75
+ > 若未开启 **实验 → 测试版 API**,脚本不会加载:能力请求会超时,
76
+ > 游戏内也看不到任何桥接活动。
77
+ > 开启实验性玩法可能导致该世界无法解锁部分成就 / 功能,建议使用专用测试世界。
78
+
79
+ ## 内置能力
80
+
81
+ Addon 内置一套开箱即用的能力注册表(`scripts/bridge/capabilities/index.ts`),
82
+ 作为可运行的参考示例。
83
+
84
+ | 能力名 | 文件 | 说明 |
85
+ | ------------------------ | ------------------------- | ------------------------------------------------------------ |
86
+ | `get_player_snapshot` | `getPlayerSnapshot.ts` | 获取玩家快照(名称、生命值、标签、坐标、维度、游戏模式) |
87
+ | `get_inventory_snapshot` | `getInventorySnapshot.ts` | 获取玩家背包快照(槽位、物品 ID、数量、自定义名称) |
88
+ | `run_world_command` | `runWorldCommand.ts` | 在世界上执行一条 MC 命令(受 `commandSafety.ts` 黑名单保护) |
89
+
90
+ 开发者通过在 `capabilities/index.ts` 的能力注册表中追加新条目来
91
+ 添加自定义能力,与内置能力共存,仍由 `router.ts` 按能力名查找调用。
92
+
93
+ > 注意:`find_entities` 暂未内置。当前协议中的 `scriptevent` 并不携带发起玩家的
94
+ > 来源上下文(source-player),而实体查询需要该上下文来限定范围;一旦协议支持
95
+ > 玩家来源的 scriptevent,该能力即会补充进来。
96
+
97
+ ## 信任边界
98
+
99
+ 桥接层**不是**安全边界。宿主应用必须自行认证 / 授权谁可以调用能力 ——
100
+ addon 仅在世界命令路径上提供防御性命令过滤。
101
+
102
+ - `run_world_command` 故意**不**出现在 Python 默认注册表中(也不在 addon
103
+ 默认能力注册表中)。需要该能力的宿主必须显式注册 handler。
104
+ - 注册后,默认 allowlist 仅为 `["say"]`。危险命令 denylist
105
+ (`execute`、`script`、`op`、`setblock`、`fill` 等)是第二道防线,
106
+ 即便宿主放宽 allowlist 仍然生效。
107
+
108
+ ## 许可证
109
+
110
+ MIT
@@ -0,0 +1,46 @@
1
+ {
2
+ "format_version": 2,
3
+ "header": {
4
+ "name": "MCBE-WS-SDK",
5
+ "description": "Script bridge for MCBE-WS-SDK",
6
+ "uuid": "60411f7f-774b-4269-b1cd-f58ebe702995",
7
+ "version": [
8
+ 1,
9
+ 0,
10
+ 1
11
+ ],
12
+ "min_engine_version": [1, 21, 80]
13
+ },
14
+ "modules": [
15
+ {
16
+ "description": "Script resources",
17
+ "language": "javascript",
18
+ "type": "script",
19
+ "uuid": "6b900207-0c01-4b9f-97a9-f3f170a35768",
20
+ "version": [
21
+ 1,
22
+ 0,
23
+ 1
24
+ ],
25
+ "entry": "scripts/main.js"
26
+ }
27
+ ],
28
+ "dependencies": [
29
+ {
30
+ "module_name": "@minecraft/server",
31
+ "version": "2.0.0"
32
+ },
33
+ {
34
+ "module_name": "@minecraft/server-ui",
35
+ "version": "2.0.0"
36
+ },
37
+ {
38
+ "module_name": "@minecraft/server-gametest",
39
+ "version": "1.0.0-beta"
40
+ },
41
+ {
42
+ "uuid": "450332ea-6755-48b6-ab7f-36843065edd1",
43
+ "version": [1, 0, 1]
44
+ }
45
+ ]
46
+ }