worldmap-mcp 0.2.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.
- worldmap_mcp-0.2.0/LICENSE +21 -0
- worldmap_mcp-0.2.0/NOTICE.md +15 -0
- worldmap_mcp-0.2.0/PKG-INFO +72 -0
- worldmap_mcp-0.2.0/README.md +47 -0
- worldmap_mcp-0.2.0/hatch_build.py +34 -0
- worldmap_mcp-0.2.0/pyproject.toml +65 -0
- worldmap_mcp-0.2.0/worldmap_mcp/__init__.py +1 -0
- worldmap_mcp-0.2.0/worldmap_mcp/__main__.py +5 -0
- worldmap_mcp-0.2.0/worldmap_mcp/bridge_client.py +220 -0
- worldmap_mcp-0.2.0/worldmap_mcp/bridge_payload/icon.png +0 -0
- worldmap_mcp-0.2.0/worldmap_mcp/bridge_payload/mod.json +13 -0
- worldmap_mcp-0.2.0/worldmap_mcp/bridge_payload/worldmap_mcp_bridge.gd +8261 -0
- worldmap_mcp-0.2.0/worldmap_mcp/captures.py +66 -0
- worldmap_mcp-0.2.0/worldmap_mcp/cli.py +109 -0
- worldmap_mcp-0.2.0/worldmap_mcp/client_config.py +258 -0
- worldmap_mcp-0.2.0/worldmap_mcp/coast.py +205 -0
- worldmap_mcp-0.2.0/worldmap_mcp/errors.py +121 -0
- worldmap_mcp-0.2.0/worldmap_mcp/forests.py +309 -0
- worldmap_mcp-0.2.0/worldmap_mcp/handshake.py +101 -0
- worldmap_mcp-0.2.0/worldmap_mcp/installer.py +341 -0
- worldmap_mcp-0.2.0/worldmap_mcp/landread.py +439 -0
- worldmap_mcp-0.2.0/worldmap_mcp/layout.py +208 -0
- worldmap_mcp-0.2.0/worldmap_mcp/lifecycle.py +182 -0
- worldmap_mcp-0.2.0/worldmap_mcp/mapcheck.py +362 -0
- worldmap_mcp-0.2.0/worldmap_mcp/maplayers.py +152 -0
- worldmap_mcp-0.2.0/worldmap_mcp/ranges.py +200 -0
- worldmap_mcp-0.2.0/worldmap_mcp/roads.py +240 -0
- worldmap_mcp-0.2.0/worldmap_mcp/server.py +4684 -0
- worldmap_mcp-0.2.0/worldmap_mcp/skills.py +123 -0
- worldmap_mcp-0.2.0/worldmap_mcp/skills_payload/_shared/build-loop.md +100 -0
- worldmap_mcp-0.2.0/worldmap_mcp/skills_payload/_shared/review-rubric.md +91 -0
- worldmap_mcp-0.2.0/worldmap_mcp/skills_payload/_shared/style-bible.md +72 -0
- worldmap_mcp-0.2.0/worldmap_mcp/skills_payload/skill-index.json +61 -0
- worldmap_mcp-0.2.0/worldmap_mcp/skills_payload/worldmap-art-direction/SKILL.md +119 -0
- worldmap_mcp-0.2.0/worldmap_mcp/skills_payload/worldmap-finishing/SKILL.md +130 -0
- worldmap_mcp-0.2.0/worldmap_mcp/skills_payload/worldmap-labels/SKILL.md +122 -0
- worldmap_mcp-0.2.0/worldmap_mcp/skills_payload/worldmap-landmass/SKILL.md +170 -0
- worldmap_mcp-0.2.0/worldmap_mcp/skills_payload/worldmap-settlements/SKILL.md +121 -0
- worldmap_mcp-0.2.0/worldmap_mcp/skills_payload/worldmap-terrain/SKILL.md +207 -0
- worldmap_mcp-0.2.0/worldmap_mcp/skills_payload/worldmap-visual-review/SKILL.md +71 -0
- worldmap_mcp-0.2.0/worldmap_mcp/state_paths.py +53 -0
- worldmap_mcp-0.2.0/worldmap_mcp/terrain.py +353 -0
- worldmap_mcp-0.2.0/worldmap_mcp/timing.py +85 -0
- worldmap_mcp-0.2.0/worldmap_mcp/updates.py +191 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 thekannen
|
|
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,15 @@
|
|
|
1
|
+
# Notices
|
|
2
|
+
|
|
3
|
+
This project's license is in [LICENSE](LICENSE).
|
|
4
|
+
|
|
5
|
+
Much of its code is derived from **Battlemap MCP**
|
|
6
|
+
(https://github.com/thekannen/battlemap-mcp), by the same author, under the
|
|
7
|
+
MIT license: the bridge protocol and client, error types, lifecycle, timing,
|
|
8
|
+
client registration, the offline gate and the release tooling's shape.
|
|
9
|
+
|
|
10
|
+
No code was copied from GPL or unlicensed projects. Nothing in this
|
|
11
|
+
repository comes from Wonderdraft or Tailwind Games, LLC: no program files,
|
|
12
|
+
scripts, art or asset packs. Worldmap MCP is unofficial and is not sponsored
|
|
13
|
+
or endorsed by Megasploot or Tailwind Games, LLC. "Wonderdraft" is a
|
|
14
|
+
trademark of Tailwind Games, LLC, used only to describe what this tool works
|
|
15
|
+
with.
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: worldmap-mcp
|
|
3
|
+
Version: 0.2.0
|
|
4
|
+
Summary: Unofficial MCP server for Wonderdraft: drives a running Wonderdraft from an AI assistant
|
|
5
|
+
Project-URL: Homepage, https://github.com/thekannen/worldmap-mcp
|
|
6
|
+
Project-URL: Documentation, https://knownframe.com/worldmap-mcp/docs/
|
|
7
|
+
Project-URL: Repository, https://github.com/thekannen/worldmap-mcp
|
|
8
|
+
Project-URL: Issues, https://github.com/thekannen/worldmap-mcp/issues
|
|
9
|
+
Project-URL: Releases, https://github.com/thekannen/worldmap-mcp/releases
|
|
10
|
+
Author: thekannen
|
|
11
|
+
License-Expression: MIT
|
|
12
|
+
License-File: LICENSE
|
|
13
|
+
License-File: NOTICE.md
|
|
14
|
+
Keywords: Wonderdraft,fantasy-map,mcp,model-context-protocol,worldbuilding
|
|
15
|
+
Classifier: Environment :: Console
|
|
16
|
+
Classifier: Intended Audience :: End Users/Desktop
|
|
17
|
+
Classifier: Operating System :: Microsoft :: Windows
|
|
18
|
+
Classifier: Programming Language :: Python :: 3
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
21
|
+
Classifier: Topic :: Games/Entertainment :: Role-Playing
|
|
22
|
+
Requires-Python: >=3.11
|
|
23
|
+
Requires-Dist: mcp<3,>=2.1
|
|
24
|
+
Description-Content-Type: text/markdown
|
|
25
|
+
|
|
26
|
+
# worldmap-mcp
|
|
27
|
+
|
|
28
|
+
Worldmap MCP is an unofficial, free MCP server for Wonderdraft. It lets your
|
|
29
|
+
AI assistant (Claude Desktop, Claude Code, Codex or any other MCP client)
|
|
30
|
+
build fantasy world maps in the Wonderdraft map you have open: coastlines,
|
|
31
|
+
mountains, rivers, forests, towns, borders, labels and the finished export,
|
|
32
|
+
with Wonderdraft's own tools and the assets you already have. It generates
|
|
33
|
+
no art.
|
|
34
|
+
|
|
35
|
+
This package is the **server** your AI app runs. Wonderdraft also needs the
|
|
36
|
+
**bridge**, a mod for [Cartouche](https://github.com/thekannen/cartouche), the
|
|
37
|
+
mod loader for Wonderdraft. The package carries the bridge, and its `install`
|
|
38
|
+
command adds it to Cartouche.
|
|
39
|
+
|
|
40
|
+
You need your own copy of **Wonderdraft 1.1.8.2** with Cartouche, on the same
|
|
41
|
+
Windows computer.
|
|
42
|
+
|
|
43
|
+
## Install
|
|
44
|
+
|
|
45
|
+
```text
|
|
46
|
+
uv tool install worldmap-mcp
|
|
47
|
+
worldmap-mcp install
|
|
48
|
+
worldmap-mcp register claude-code
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
Close Wonderdraft before `install`. `register` also takes `codex`. Then start
|
|
52
|
+
Wonderdraft, open a map and check with `worldmap-mcp ping`.
|
|
53
|
+
|
|
54
|
+
No uv? The [releases](https://github.com/thekannen/worldmap-mcp/releases)
|
|
55
|
+
also have a Windows program that needs no Python, and a Claude desktop
|
|
56
|
+
extension (`.mcpb`).
|
|
57
|
+
|
|
58
|
+
## Privacy
|
|
59
|
+
|
|
60
|
+
The bridge listens on 127.0.0.1 only and answers only requests signed with a
|
|
61
|
+
per-install token. No outgoing connections, no telemetry. It writes only to
|
|
62
|
+
`%USERPROFILE%\.worldmap-mcp`.
|
|
63
|
+
|
|
64
|
+
## Links
|
|
65
|
+
|
|
66
|
+
- Documentation: https://knownframe.com/worldmap-mcp/docs/
|
|
67
|
+
- Source and issues: https://github.com/thekannen/worldmap-mcp
|
|
68
|
+
|
|
69
|
+
Worldmap MCP is not made, sponsored or endorsed by Megasploot or Tailwind
|
|
70
|
+
Games, LLC, and includes no Wonderdraft software, maps or art. "Wonderdraft"
|
|
71
|
+
is a trademark of Tailwind Games, LLC, used here only to say what this tool
|
|
72
|
+
works with. MIT license.
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
# worldmap-mcp
|
|
2
|
+
|
|
3
|
+
Worldmap MCP is an unofficial, free MCP server for Wonderdraft. It lets your
|
|
4
|
+
AI assistant (Claude Desktop, Claude Code, Codex or any other MCP client)
|
|
5
|
+
build fantasy world maps in the Wonderdraft map you have open: coastlines,
|
|
6
|
+
mountains, rivers, forests, towns, borders, labels and the finished export,
|
|
7
|
+
with Wonderdraft's own tools and the assets you already have. It generates
|
|
8
|
+
no art.
|
|
9
|
+
|
|
10
|
+
This package is the **server** your AI app runs. Wonderdraft also needs the
|
|
11
|
+
**bridge**, a mod for [Cartouche](https://github.com/thekannen/cartouche), the
|
|
12
|
+
mod loader for Wonderdraft. The package carries the bridge, and its `install`
|
|
13
|
+
command adds it to Cartouche.
|
|
14
|
+
|
|
15
|
+
You need your own copy of **Wonderdraft 1.1.8.2** with Cartouche, on the same
|
|
16
|
+
Windows computer.
|
|
17
|
+
|
|
18
|
+
## Install
|
|
19
|
+
|
|
20
|
+
```text
|
|
21
|
+
uv tool install worldmap-mcp
|
|
22
|
+
worldmap-mcp install
|
|
23
|
+
worldmap-mcp register claude-code
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
Close Wonderdraft before `install`. `register` also takes `codex`. Then start
|
|
27
|
+
Wonderdraft, open a map and check with `worldmap-mcp ping`.
|
|
28
|
+
|
|
29
|
+
No uv? The [releases](https://github.com/thekannen/worldmap-mcp/releases)
|
|
30
|
+
also have a Windows program that needs no Python, and a Claude desktop
|
|
31
|
+
extension (`.mcpb`).
|
|
32
|
+
|
|
33
|
+
## Privacy
|
|
34
|
+
|
|
35
|
+
The bridge listens on 127.0.0.1 only and answers only requests signed with a
|
|
36
|
+
per-install token. No outgoing connections, no telemetry. It writes only to
|
|
37
|
+
`%USERPROFILE%\.worldmap-mcp`.
|
|
38
|
+
|
|
39
|
+
## Links
|
|
40
|
+
|
|
41
|
+
- Documentation: https://knownframe.com/worldmap-mcp/docs/
|
|
42
|
+
- Source and issues: https://github.com/thekannen/worldmap-mcp
|
|
43
|
+
|
|
44
|
+
Worldmap MCP is not made, sponsored or endorsed by Megasploot or Tailwind
|
|
45
|
+
Games, LLC, and includes no Wonderdraft software, maps or art. "Wonderdraft"
|
|
46
|
+
is a trademark of Tailwind Games, LLC, used here only to say what this tool
|
|
47
|
+
works with. MIT license.
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"""Pack the repository's bridge mod and skills into source and wheel builds."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from pathlib import Path
|
|
6
|
+
from typing import Any
|
|
7
|
+
|
|
8
|
+
from hatchling.builders.hooks.plugin.interface import BuildHookInterface
|
|
9
|
+
|
|
10
|
+
PAYLOAD = "worldmap_mcp/bridge_payload"
|
|
11
|
+
SKILLS = "worldmap_mcp/skills_payload"
|
|
12
|
+
BRIDGE_FILES = ("worldmap_mcp_bridge.gd", "mod.json", "icon.png")
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
class CustomBuildHook(BuildHookInterface):
|
|
16
|
+
"""Bundle the bridge and skills; the repository's copies stay canonical."""
|
|
17
|
+
|
|
18
|
+
def initialize(self, version: str, build_data: dict[str, Any]) -> None:
|
|
19
|
+
if version == "editable":
|
|
20
|
+
return
|
|
21
|
+
root = Path(self.root)
|
|
22
|
+
if (root / PAYLOAD).is_dir():
|
|
23
|
+
return
|
|
24
|
+
bridge = root.parent / "bridge"
|
|
25
|
+
skills = root.parent / "skills"
|
|
26
|
+
missing = [
|
|
27
|
+
str(path) for path in (*(bridge / n for n in BRIDGE_FILES), skills) if not path.exists()
|
|
28
|
+
]
|
|
29
|
+
if missing:
|
|
30
|
+
raise RuntimeError(f"bridge or skills missing from the checkout: {missing}")
|
|
31
|
+
include = build_data.setdefault("force_include", {})
|
|
32
|
+
for name in BRIDGE_FILES:
|
|
33
|
+
include[str(bridge / name)] = f"{PAYLOAD}/{name}"
|
|
34
|
+
include[str(skills)] = SKILLS
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "worldmap-mcp"
|
|
3
|
+
version = "0.2.0"
|
|
4
|
+
description = "Unofficial MCP server for Wonderdraft: drives a running Wonderdraft from an AI assistant"
|
|
5
|
+
# The package index page. License texts must sit beside this file to be
|
|
6
|
+
# packaged, so LICENSE and NOTICE.md here are copies of the repository's.
|
|
7
|
+
readme = "README.md"
|
|
8
|
+
license = "MIT"
|
|
9
|
+
license-files = ["LICENSE", "NOTICE.md"]
|
|
10
|
+
authors = [{ name = "thekannen" }]
|
|
11
|
+
# Capitalised so the export's rename leaves the word people search for.
|
|
12
|
+
keywords = ["Wonderdraft", "mcp", "model-context-protocol", "fantasy-map", "worldbuilding"]
|
|
13
|
+
classifiers = [
|
|
14
|
+
"Environment :: Console",
|
|
15
|
+
"Intended Audience :: End Users/Desktop",
|
|
16
|
+
"Operating System :: Microsoft :: Windows",
|
|
17
|
+
"Programming Language :: Python :: 3",
|
|
18
|
+
"Programming Language :: Python :: 3.11",
|
|
19
|
+
"Programming Language :: Python :: 3.12",
|
|
20
|
+
"Topic :: Games/Entertainment :: Role-Playing",
|
|
21
|
+
]
|
|
22
|
+
requires-python = ">=3.11"
|
|
23
|
+
dependencies = ["mcp>=2.1,<3"]
|
|
24
|
+
|
|
25
|
+
[project.urls]
|
|
26
|
+
Homepage = "https://github.com/thekannen/worldmap-mcp"
|
|
27
|
+
Documentation = "https://knownframe.com/worldmap-mcp/docs/"
|
|
28
|
+
Repository = "https://github.com/thekannen/worldmap-mcp"
|
|
29
|
+
Issues = "https://github.com/thekannen/worldmap-mcp/issues"
|
|
30
|
+
Releases = "https://github.com/thekannen/worldmap-mcp/releases"
|
|
31
|
+
|
|
32
|
+
[project.scripts]
|
|
33
|
+
worldmap-mcp = "worldmap_mcp.cli:main"
|
|
34
|
+
|
|
35
|
+
[build-system]
|
|
36
|
+
requires = ["hatchling"]
|
|
37
|
+
build-backend = "hatchling.build"
|
|
38
|
+
|
|
39
|
+
# The source archive is published too. Without this list, one built from a
|
|
40
|
+
# checkout carries the tests and development tools along.
|
|
41
|
+
[tool.hatch.build.targets.sdist]
|
|
42
|
+
only-include = ["worldmap_mcp", "hatch_build.py"]
|
|
43
|
+
|
|
44
|
+
[tool.hatch.build.targets.wheel]
|
|
45
|
+
packages = ["worldmap_mcp"]
|
|
46
|
+
|
|
47
|
+
# hatch_build.py packs the bridge mod (mod.json, the bridge, its icon) into
|
|
48
|
+
# worldmap_mcp/bridge_payload, for the installer, and the map-making skills
|
|
49
|
+
# into worldmap_mcp/skills_payload, for get_skill.
|
|
50
|
+
[tool.hatch.build.hooks.custom]
|
|
51
|
+
path = "hatch_build.py"
|
|
52
|
+
|
|
53
|
+
[dependency-groups]
|
|
54
|
+
dev = ["pytest>=8.0", "ruff>=0.6"]
|
|
55
|
+
|
|
56
|
+
[tool.pytest.ini_options]
|
|
57
|
+
testpaths = ["tests"]
|
|
58
|
+
pythonpath = ["."]
|
|
59
|
+
|
|
60
|
+
[tool.ruff]
|
|
61
|
+
line-length = 100
|
|
62
|
+
target-version = "py311"
|
|
63
|
+
|
|
64
|
+
[tool.ruff.lint]
|
|
65
|
+
select = ["E", "F", "I", "UP", "B"]
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "0.2.0"
|
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import hashlib
|
|
4
|
+
import hmac
|
|
5
|
+
import json
|
|
6
|
+
import os
|
|
7
|
+
import secrets
|
|
8
|
+
import socket
|
|
9
|
+
import time
|
|
10
|
+
from typing import Any
|
|
11
|
+
|
|
12
|
+
from . import timing
|
|
13
|
+
from .errors import (
|
|
14
|
+
BridgeCommandError,
|
|
15
|
+
BridgeError,
|
|
16
|
+
BridgeHandshakeUntrustedError,
|
|
17
|
+
BridgePeerUntrustedError,
|
|
18
|
+
BridgeProtocolError,
|
|
19
|
+
BridgeUnavailableError,
|
|
20
|
+
BridgeUntrustedError,
|
|
21
|
+
ValidationError,
|
|
22
|
+
)
|
|
23
|
+
from .state_paths import STATE_DIR_ENV, token_path
|
|
24
|
+
|
|
25
|
+
MAX_REQUEST_BYTES = 16384 # the bridge's MAX_LINE_BYTES
|
|
26
|
+
|
|
27
|
+
PROTOCOL_VERSION = 2
|
|
28
|
+
DEFAULT_PORT = 8797
|
|
29
|
+
MAX_LINE_BYTES = 1024 * 1024
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
WIRE_ERRORS = "surrogatepass"
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def _mac(token: str, message: str) -> str:
|
|
36
|
+
return hmac.new(
|
|
37
|
+
token.encode(), message.encode("utf-8", WIRE_ERRORS), hashlib.sha256
|
|
38
|
+
).hexdigest()
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def _join_surrogates(value: Any) -> Any:
|
|
42
|
+
if isinstance(value, str):
|
|
43
|
+
return value.encode("utf-16", WIRE_ERRORS).decode("utf-16", "replace")
|
|
44
|
+
if isinstance(value, list):
|
|
45
|
+
return [_join_surrogates(item) for item in value]
|
|
46
|
+
if isinstance(value, dict):
|
|
47
|
+
return {_join_surrogates(k): _join_surrogates(v) for k, v in value.items()}
|
|
48
|
+
return value
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
def hello_proof(token: str, client_nonce: str, server_nonce: str) -> str:
|
|
52
|
+
return _mac(token, f"wd-mcp/{PROTOCOL_VERSION}|server|{client_nonce}|{server_nonce}")
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
def message_proof(token: str, role: str, client_nonce: str, server_nonce: str, payload: str) -> str:
|
|
56
|
+
return _mac(
|
|
57
|
+
token, f"wd-mcp/{PROTOCOL_VERSION}|{role}|{client_nonce}|{server_nonce}|1|{payload}"
|
|
58
|
+
)
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
def _is_nonce(value: object) -> bool:
|
|
62
|
+
return (
|
|
63
|
+
isinstance(value, str) and len(value) == 32 and all(c in "0123456789abcdef" for c in value)
|
|
64
|
+
)
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
class BridgeClient:
|
|
68
|
+
def __init__(
|
|
69
|
+
self,
|
|
70
|
+
host: str = "127.0.0.1",
|
|
71
|
+
port: int | None = None,
|
|
72
|
+
timeout: float = 5.0,
|
|
73
|
+
token: str | None = None,
|
|
74
|
+
):
|
|
75
|
+
self.host = host
|
|
76
|
+
self.port = port or int(os.environ.get("WORLDMAP_MCP_PORT", DEFAULT_PORT))
|
|
77
|
+
self.timeout = timeout
|
|
78
|
+
self._token = token
|
|
79
|
+
|
|
80
|
+
def token(self) -> str:
|
|
81
|
+
"""Read on every request, so a regenerated token needs no restart."""
|
|
82
|
+
if self._token is not None:
|
|
83
|
+
return self._token
|
|
84
|
+
path = token_path()
|
|
85
|
+
try:
|
|
86
|
+
value = path.read_text(encoding="utf-8").strip()
|
|
87
|
+
except OSError as exc:
|
|
88
|
+
raise BridgeUnavailableError(
|
|
89
|
+
f"No bridge token at {path}. Run `worldmap-mcp token`, then restart "
|
|
90
|
+
f"Wonderdraft so the bridge reads it. If Wonderdraft or the installer ran from "
|
|
91
|
+
f"a different kind of terminal, set {STATE_DIR_ENV} to the same absolute "
|
|
92
|
+
f"folder for both. ({exc})"
|
|
93
|
+
) from exc
|
|
94
|
+
if not value:
|
|
95
|
+
raise BridgeUnavailableError(f"Bridge token file is empty: {path}")
|
|
96
|
+
return value
|
|
97
|
+
|
|
98
|
+
def request(self, cmd: str, **params: Any) -> dict:
|
|
99
|
+
payload = json.dumps({"cmd": cmd, **params})
|
|
100
|
+
size = len(json.dumps({"seq": 1, "payload": payload, "auth": "0" * 64}).encode()) + 1
|
|
101
|
+
if size > MAX_REQUEST_BYTES:
|
|
102
|
+
raise ValidationError(
|
|
103
|
+
f"request too large: {size} bytes, the bridge takes at most {MAX_REQUEST_BYTES}; "
|
|
104
|
+
"send fewer points or symbols per call"
|
|
105
|
+
)
|
|
106
|
+
token = self.token()
|
|
107
|
+
started = time.perf_counter()
|
|
108
|
+
deadline = time.monotonic() + self.timeout
|
|
109
|
+
try:
|
|
110
|
+
sock = socket.create_connection((self.host, self.port), timeout=self.timeout)
|
|
111
|
+
except OSError as exc:
|
|
112
|
+
raise BridgeUnavailableError(
|
|
113
|
+
f"Nothing answered on {self.host}:{self.port}. Is Wonderdraft running with "
|
|
114
|
+
f"the bridge loaded? ({exc})"
|
|
115
|
+
) from exc
|
|
116
|
+
with sock:
|
|
117
|
+
client_nonce = secrets.token_hex(16)
|
|
118
|
+
self._send(sock, {"cmd": "hello", "protocol": PROTOCOL_VERSION, "nonce": client_nonce})
|
|
119
|
+
answer = self._read(sock, deadline)
|
|
120
|
+
result = answer.get("result")
|
|
121
|
+
if not answer.get("ok") or not isinstance(result, dict):
|
|
122
|
+
raise BridgeProtocolError(
|
|
123
|
+
f"The bridge refused the protocol {PROTOCOL_VERSION} handshake: "
|
|
124
|
+
f"{answer.get('error', answer)}"
|
|
125
|
+
)
|
|
126
|
+
server_nonce = result.get("nonce")
|
|
127
|
+
proof = result.get("proof")
|
|
128
|
+
if (
|
|
129
|
+
result.get("protocol") != PROTOCOL_VERSION
|
|
130
|
+
or not _is_nonce(server_nonce)
|
|
131
|
+
or not isinstance(proof, str)
|
|
132
|
+
or not proof.isascii()
|
|
133
|
+
or not hmac.compare_digest(proof, hello_proof(token, client_nonce, server_nonce))
|
|
134
|
+
):
|
|
135
|
+
raise BridgeHandshakeUntrustedError(
|
|
136
|
+
"The peer could not prove it knows the bridge token; nothing was sent. "
|
|
137
|
+
"Was the token regenerated after Wonderdraft started?"
|
|
138
|
+
)
|
|
139
|
+
self._send(
|
|
140
|
+
sock,
|
|
141
|
+
{
|
|
142
|
+
"seq": 1,
|
|
143
|
+
"payload": payload,
|
|
144
|
+
"auth": message_proof(token, "request", client_nonce, server_nonce, payload),
|
|
145
|
+
},
|
|
146
|
+
)
|
|
147
|
+
envelope = self._read(sock, deadline)
|
|
148
|
+
body = envelope.get("payload")
|
|
149
|
+
auth = envelope.get("auth")
|
|
150
|
+
if isinstance(body, str):
|
|
151
|
+
timing.bridge_request(
|
|
152
|
+
time.perf_counter() - started, len(body.encode("utf-8", WIRE_ERRORS))
|
|
153
|
+
)
|
|
154
|
+
if (
|
|
155
|
+
envelope.get("seq") != 1
|
|
156
|
+
or not isinstance(body, str)
|
|
157
|
+
or not isinstance(auth, str)
|
|
158
|
+
or not auth.isascii()
|
|
159
|
+
or not hmac.compare_digest(
|
|
160
|
+
auth, message_proof(token, "response", client_nonce, server_nonce, body)
|
|
161
|
+
)
|
|
162
|
+
):
|
|
163
|
+
detail = envelope.get("error") if "error" in envelope else "response not authenticated"
|
|
164
|
+
raise BridgePeerUntrustedError(
|
|
165
|
+
f"Bridge response rejected: {detail}. Do not retry: the command may have run."
|
|
166
|
+
)
|
|
167
|
+
try:
|
|
168
|
+
response = json.loads(body)
|
|
169
|
+
except ValueError as exc:
|
|
170
|
+
raise BridgeProtocolError("Authenticated response is not JSON") from exc
|
|
171
|
+
if not isinstance(response, dict):
|
|
172
|
+
raise BridgeProtocolError("Authenticated response must be an object")
|
|
173
|
+
response = _join_surrogates(response)
|
|
174
|
+
if not response.get("ok"):
|
|
175
|
+
raise BridgeCommandError(
|
|
176
|
+
str(response.get("error", "bridge refused the command")), cmd=cmd, params=params
|
|
177
|
+
)
|
|
178
|
+
return response.get("result", {})
|
|
179
|
+
|
|
180
|
+
@staticmethod
|
|
181
|
+
def _send(sock: socket.socket, value: dict) -> None:
|
|
182
|
+
sock.sendall((json.dumps(value) + "\n").encode())
|
|
183
|
+
|
|
184
|
+
@staticmethod
|
|
185
|
+
def _read(sock: socket.socket, deadline: float) -> dict:
|
|
186
|
+
buf = bytearray()
|
|
187
|
+
while b"\n" not in buf:
|
|
188
|
+
remaining = deadline - time.monotonic()
|
|
189
|
+
if remaining <= 0:
|
|
190
|
+
raise BridgeProtocolError("Bridge did not answer in time")
|
|
191
|
+
sock.settimeout(remaining)
|
|
192
|
+
try:
|
|
193
|
+
chunk = sock.recv(65536)
|
|
194
|
+
except TimeoutError as exc:
|
|
195
|
+
raise BridgeProtocolError("Bridge did not answer in time") from exc
|
|
196
|
+
if not chunk:
|
|
197
|
+
raise BridgeProtocolError("Bridge closed the connection without a full line")
|
|
198
|
+
buf.extend(chunk)
|
|
199
|
+
if len(buf) > MAX_LINE_BYTES:
|
|
200
|
+
raise BridgeProtocolError("Bridge line exceeded the byte limit")
|
|
201
|
+
line = bytes(buf[: buf.index(b"\n")])
|
|
202
|
+
try:
|
|
203
|
+
value = json.loads(line.decode("utf-8", WIRE_ERRORS))
|
|
204
|
+
except (ValueError, UnicodeDecodeError) as exc:
|
|
205
|
+
raise BridgeProtocolError("Unparseable line from bridge") from exc
|
|
206
|
+
if not isinstance(value, dict):
|
|
207
|
+
raise BridgeProtocolError("Bridge line must be a JSON object")
|
|
208
|
+
return value
|
|
209
|
+
|
|
210
|
+
|
|
211
|
+
__all__ = [
|
|
212
|
+
"BridgeClient",
|
|
213
|
+
"BridgeCommandError",
|
|
214
|
+
"BridgeError",
|
|
215
|
+
"BridgeHandshakeUntrustedError",
|
|
216
|
+
"BridgePeerUntrustedError",
|
|
217
|
+
"BridgeProtocolError",
|
|
218
|
+
"BridgeUnavailableError",
|
|
219
|
+
"BridgeUntrustedError",
|
|
220
|
+
]
|
|
Binary file
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
{
|
|
2
|
+
"app": "wonderdraft",
|
|
3
|
+
"id": "worldmap-mcp",
|
|
4
|
+
"name": "Worldmap MCP bridge",
|
|
5
|
+
"version": "0.2.0",
|
|
6
|
+
"entry": "worldmap_mcp_bridge.gd",
|
|
7
|
+
"icon": "icon.png",
|
|
8
|
+
"supported_wonderdraft": [
|
|
9
|
+
"1.1.8.2"
|
|
10
|
+
],
|
|
11
|
+
"repo": "thekannen/worldmap-mcp",
|
|
12
|
+
"docs": "https://github.com/thekannen/worldmap-mcp#readme"
|
|
13
|
+
}
|