mapnetwork-mcp 1.2.2__tar.gz → 2.0.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.
- mapnetwork_mcp-2.0.0/.github/workflows/workflow.yml +33 -0
- {mapnetwork_mcp-1.2.2 → mapnetwork_mcp-2.0.0}/PKG-INFO +2 -1
- {mapnetwork_mcp-1.2.2 → mapnetwork_mcp-2.0.0}/RELEASING.md +88 -86
- {mapnetwork_mcp-1.2.2 → mapnetwork_mcp-2.0.0}/manifest.json +1 -1
- {mapnetwork_mcp-1.2.2 → mapnetwork_mcp-2.0.0}/mapnetwork_mcp/server.py +158 -184
- {mapnetwork_mcp-1.2.2 → mapnetwork_mcp-2.0.0}/pyproject.toml +6 -2
- {mapnetwork_mcp-1.2.2 → mapnetwork_mcp-2.0.0}/.gitignore +0 -0
- {mapnetwork_mcp-1.2.2 → mapnetwork_mcp-2.0.0}/.mcpbignore +0 -0
- {mapnetwork_mcp-1.2.2 → mapnetwork_mcp-2.0.0}/LICENSE +0 -0
- {mapnetwork_mcp-1.2.2 → mapnetwork_mcp-2.0.0}/README.md +0 -0
- {mapnetwork_mcp-1.2.2 → mapnetwork_mcp-2.0.0}/images/Kanazawa21Museum-black.png +0 -0
- {mapnetwork_mcp-1.2.2 → mapnetwork_mcp-2.0.0}/images/Kanazawa21Museum-darkGreen.png +0 -0
- {mapnetwork_mcp-1.2.2 → mapnetwork_mcp-2.0.0}/images/Kanazawa21Museum-grey.png +0 -0
- {mapnetwork_mcp-1.2.2 → mapnetwork_mcp-2.0.0}/images/Kanazawa21Museum-lightGreen.png +0 -0
- {mapnetwork_mcp-1.2.2 → mapnetwork_mcp-2.0.0}/images/Kanazawa21Museum-popArt.png +0 -0
- {mapnetwork_mcp-1.2.2 → mapnetwork_mcp-2.0.0}/images/Kanazawa21Museum-white.png +0 -0
- {mapnetwork_mcp-1.2.2 → mapnetwork_mcp-2.0.0}/mapnetwork_mcp/__init__.py +0 -0
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
name: Publish to PyPI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
tags:
|
|
6
|
+
- "v*"
|
|
7
|
+
|
|
8
|
+
permissions:
|
|
9
|
+
contents: read
|
|
10
|
+
id-token: write
|
|
11
|
+
|
|
12
|
+
jobs:
|
|
13
|
+
build-and-publish:
|
|
14
|
+
runs-on: ubuntu-latest
|
|
15
|
+
steps:
|
|
16
|
+
- uses: actions/checkout@v4
|
|
17
|
+
|
|
18
|
+
- uses: actions/setup-python@v5
|
|
19
|
+
with:
|
|
20
|
+
python-version: "3.x"
|
|
21
|
+
|
|
22
|
+
- name: Build package
|
|
23
|
+
run: |
|
|
24
|
+
python -m pip install --upgrade build
|
|
25
|
+
python -m build
|
|
26
|
+
|
|
27
|
+
- name: Check package
|
|
28
|
+
run: |
|
|
29
|
+
python -m pip install --upgrade twine
|
|
30
|
+
twine check dist/*
|
|
31
|
+
|
|
32
|
+
- name: Publish to PyPI
|
|
33
|
+
uses: pypa/gh-action-pypi-publish@release/v1
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: mapnetwork-mcp
|
|
3
|
-
Version:
|
|
3
|
+
Version: 2.0.0
|
|
4
4
|
Summary: MCP server — generate styled map images via mapnetwork.app
|
|
5
5
|
Project-URL: Homepage, https://mapnetwork.app
|
|
6
6
|
Project-URL: Repository, https://github.com/toruproject/mapnetwork-mcp
|
|
7
|
+
License-Expression: MIT
|
|
7
8
|
License-File: LICENSE
|
|
8
9
|
Requires-Python: >=3.11
|
|
9
10
|
Requires-Dist: httpx>=0.27.0
|
|
@@ -1,87 +1,89 @@
|
|
|
1
|
-
# Releasing a new version
|
|
2
|
-
|
|
3
|
-
This project's version number is declared in **three places** that must stay in sync:
|
|
4
|
-
|
|
5
|
-
| File | Field(s) |
|
|
6
|
-
|---|---|
|
|
7
|
-
| `pyproject.toml` | `[project] version` |
|
|
8
|
-
| `server.json` | `version`, `packages[0].version` |
|
|
9
|
-
| `manifest.json` | `version` |
|
|
10
|
-
|
|
11
|
-
## Steps
|
|
12
|
-
|
|
13
|
-
1. **Bump the version** in all three files above (same value).
|
|
14
|
-
|
|
15
|
-
2. **
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
```
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
```
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
1
|
+
# Releasing a new version
|
|
2
|
+
|
|
3
|
+
This project's version number is declared in **three places** that must stay in sync:
|
|
4
|
+
|
|
5
|
+
| File | Field(s) |
|
|
6
|
+
|---|---|
|
|
7
|
+
| `pyproject.toml` | `[project] version` |
|
|
8
|
+
| `server.json` | `version`, `packages[0].version` |
|
|
9
|
+
| `manifest.json` | `version` |
|
|
10
|
+
|
|
11
|
+
## Steps
|
|
12
|
+
|
|
13
|
+
1. **Bump the version** in all three files above (same value).
|
|
14
|
+
|
|
15
|
+
2. **(Optional) Local build sanity check** — the real publish now happens
|
|
16
|
+
unattended in CI (see step 3), so this is just a pre-flight check to catch
|
|
17
|
+
build errors before tagging:
|
|
18
|
+
```bash
|
|
19
|
+
rm -f dist/*.whl dist/*.tar.gz
|
|
20
|
+
.venv/Scripts/python -m build
|
|
21
|
+
.venv/Scripts/python -m twine check dist/mapnetwork_mcp-<version>*
|
|
22
|
+
```
|
|
23
|
+
Use the version-specific glob, not `dist/*` — a leftover `.mcpb` from a
|
|
24
|
+
previous release sits in the same `dist/` folder and `twine check` errors
|
|
25
|
+
out on it ("Unknown distribution format") even though the actual wheel/
|
|
26
|
+
sdist are fine.
|
|
27
|
+
|
|
28
|
+
3. **Commit, tag, and push** (moved up — pushing the tag is what triggers the release)
|
|
29
|
+
```bash
|
|
30
|
+
git add pyproject.toml server.json manifest.json mapnetwork_mcp/server.py # plus any other source files changed for this release
|
|
31
|
+
git commit -m "Bump version to <version>"
|
|
32
|
+
git push origin main
|
|
33
|
+
git tag -a v<version> -m "v<version>"
|
|
34
|
+
git push origin v<version>
|
|
35
|
+
```
|
|
36
|
+
Pushing the `v<version>` tag triggers `.github/workflows/workflow.yml`,
|
|
37
|
+
which builds the package and publishes it to PyPI via [Trusted
|
|
38
|
+
Publishing](https://docs.pypi.org/trusted-publishers/) (OIDC) —
|
|
39
|
+
**no `twine upload`, no PyPI API token needed anymore.** The trusted
|
|
40
|
+
publisher is registered on PyPI's project settings (repo:
|
|
41
|
+
`toruproject/mapnetwork-mcp`, workflow: `workflow.yml`); if the workflow
|
|
42
|
+
filename ever changes, that registration must be updated to match.
|
|
43
|
+
|
|
44
|
+
4. **Confirm the release landed**
|
|
45
|
+
Watch the workflow run in the repo's Actions tab, then verify PyPI has it:
|
|
46
|
+
```bash
|
|
47
|
+
curl -s https://pypi.org/pypi/mapnetwork-mcp/json | grep -o '"<version>"'
|
|
48
|
+
```
|
|
49
|
+
If the workflow fails after the tag was already pushed, fix the issue and
|
|
50
|
+
push a new patch version — PyPI rejects re-uploading a version that
|
|
51
|
+
already exists, and tags shouldn't be deleted/reused once pushed.
|
|
52
|
+
|
|
53
|
+
5. **Publish to the MCP registry**
|
|
54
|
+
```bash
|
|
55
|
+
./mcp-publisher.exe validate server.json
|
|
56
|
+
./mcp-publisher.exe login github # only needed if the session expired
|
|
57
|
+
./mcp-publisher.exe publish server.json
|
|
58
|
+
```
|
|
59
|
+
The registry entry's `packages[0].version` must match the version actually live on PyPI (the registry does not host the code itself).
|
|
60
|
+
|
|
61
|
+
⚠️ `login github` opens an interactive device-confirmation flow in the
|
|
62
|
+
browser — it cannot be automated or run on someone's behalf. Run it
|
|
63
|
+
yourself in your own terminal (not delegated to an agent) and confirm
|
|
64
|
+
it's done before continuing to `publish`.
|
|
65
|
+
|
|
66
|
+
6. **Rebuild the MCPB bundle**
|
|
67
|
+
```bash
|
|
68
|
+
npx --yes @anthropic-ai/mcpb validate manifest.json
|
|
69
|
+
npx --yes @anthropic-ai/mcpb pack . dist/mapnetwork-mcp.mcpb
|
|
70
|
+
```
|
|
71
|
+
The output filename is literally `mapnetwork-mcp.mcpb` — **not**
|
|
72
|
+
version-suffixed (the `mcpb pack` tool's own summary output shows a
|
|
73
|
+
version-suffixed "Archive Details > filename" field, which is just a
|
|
74
|
+
display label and does not match the actual file written to disk). Use
|
|
75
|
+
`dist/mapnetwork-mcp.mcpb` verbatim in step 7, not a guessed
|
|
76
|
+
`mapnetwork-mcp-<version>.mcpb`.
|
|
77
|
+
|
|
78
|
+
7. **Create the GitHub Release** with the `.mcpb` bundle attached
|
|
79
|
+
```bash
|
|
80
|
+
gh release create v<version> dist/mapnetwork-mcp.mcpb --title "v<version>" --notes "..."
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
## Notes
|
|
84
|
+
|
|
85
|
+
- `.mcpregistry_github_token` / `.mcpregistry_registry_token` hold the `mcp-publisher` login session — they are git-ignored and must never be committed.
|
|
86
|
+
- `dist/` is git-ignored; build artifacts and the `.mcpb` bundle are distributed only via PyPI / the GitHub Release, not via the repository. Old files from a
|
|
87
|
+
previous release aren't cleaned up automatically (step 2 only removes
|
|
88
|
+
`*.whl`/`*.tar.gz`) — the stray `.mcpb` from the last run stays there, which
|
|
87
89
|
is exactly what trips up the `twine check dist/*` glob above.
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"manifest_version": "0.4",
|
|
3
3
|
"name": "mapnetwork-mcp",
|
|
4
4
|
"display_name": "MapNetwork",
|
|
5
|
-
"version": "
|
|
5
|
+
"version": "2.0.0",
|
|
6
6
|
"description": "Generate styled PNG/SVG map images of any location with 11 customizable color themes.",
|
|
7
7
|
"long_description": "MCP server for MapNetwork — generate styled map images (PNG / SVG) for any location on Earth, directly from Claude.\n\n- Generate maps from a place name, coordinates, or a list of markers\n- 11 color themes (white, darkBlue, darkGreen, popArt, lightBlue, lightGreen, beige, magenta, gray, black, brawn)\n- Overlay walking / driving routes on the map\n- PNG or SVG output, saved to your Downloads folder\n- Re-download a previously generated map in a different theme or format without regenerating\n- Open any generated map in the MapNetwork web editor for manual customization",
|
|
8
8
|
"author": {
|
|
@@ -14,6 +14,13 @@ from pydantic import BaseModel, ConfigDict, Field
|
|
|
14
14
|
BASE_URL = os.environ.get("MAPNETWORK_BASE_URL", "https://mapnetwork.app")
|
|
15
15
|
POLL_INTERVAL_SEC = 10.0
|
|
16
16
|
MAX_WAIT_SEC = 600
|
|
17
|
+
# MCPクライアントによっては、report_progressで進捗通知を送ってもtools/call自体の
|
|
18
|
+
# クライアント側タイムアウトを延長してくれない(60秒固定のクライアントで実測確認済み)。
|
|
19
|
+
# そのため generate_map は内部ポーリングをこの秒数までに打ち切り、まだ終わっていなければ
|
|
20
|
+
# dataKeyを返してcheck_map_statusでの確認をモデルに促す。60秒に対して十分な余裕を残す値にする。
|
|
21
|
+
INITIAL_WAIT_SEC = 40.0
|
|
22
|
+
# check_map_statusをモデルが連打しても機械的に間隔が空くようにする最低待機時間
|
|
23
|
+
CHECK_THROTTLE_SEC = 5.0
|
|
17
24
|
|
|
18
25
|
# layersは自由な多値配列にすると、モデルが「roadはhighway/driving/walkingの上位互換」
|
|
19
26
|
# といった内部の組み合わせルールを知らないまま組み合わせを選んでしまう。
|
|
@@ -27,8 +34,8 @@ _LAYER_PRESETS: dict[str, list[str]] = {
|
|
|
27
34
|
|
|
28
35
|
|
|
29
36
|
class Location(BaseModel):
|
|
30
|
-
lat: float
|
|
31
|
-
lng: float
|
|
37
|
+
lat: float = Field(description="Latitude.")
|
|
38
|
+
lng: float = Field(description="Longitude.")
|
|
32
39
|
|
|
33
40
|
|
|
34
41
|
class Marker(BaseModel):
|
|
@@ -51,25 +58,12 @@ class RouteInput(BaseModel):
|
|
|
51
58
|
coords: list[list[float]] | None = Field(
|
|
52
59
|
default=None, description="Ordered list of [lat, lng] pairs along the route."
|
|
53
60
|
)
|
|
54
|
-
mode: Literal["walking", "driving"] | None = None
|
|
61
|
+
mode: Literal["walking", "driving"] | None = Field(default=None, description="'walking' or 'driving'.")
|
|
55
62
|
from_: RouteEndpoint | None = Field(default=None, alias="from", description="Route start point.")
|
|
56
63
|
to: RouteEndpoint | None = Field(default=None, description="Route end point.")
|
|
57
64
|
color: str | None = Field(default=None, description="Optional line color as a CSS hex color (e.g. '#FF4500').")
|
|
58
65
|
|
|
59
66
|
|
|
60
|
-
class MapConfig(BaseModel):
|
|
61
|
-
patchworked: bool | None = Field(
|
|
62
|
-
default=None, description="Auto-color closed areas and building shapes on the drawing. Default true."
|
|
63
|
-
)
|
|
64
|
-
withBuilding: bool | None = Field(
|
|
65
|
-
default=None, description="Draw building shapes. Default true when building data is available."
|
|
66
|
-
)
|
|
67
|
-
withSeaRibbon: bool | None = Field(
|
|
68
|
-
default=None,
|
|
69
|
-
description="Draw a band representing the sea along the coastline. Default true when coastline data is available.",
|
|
70
|
-
)
|
|
71
|
-
|
|
72
|
-
|
|
73
67
|
mcp = FastMCP(
|
|
74
68
|
"MapNetwork",
|
|
75
69
|
instructions=(
|
|
@@ -101,6 +95,12 @@ mcp = FastMCP(
|
|
|
101
95
|
"2. Call `generate_map` with `route=<result>` and `markers=[result['from'], result['to']]`\n"
|
|
102
96
|
"The route is drawn on top of all other layers. "
|
|
103
97
|
"Add `'color': '#RRGGBB'` to the route dict to customise the line color.\n\n"
|
|
98
|
+
"## If generation is still in progress\n"
|
|
99
|
+
"For busy areas, `generate_map` may return before the map is ready, with a `dataKey` "
|
|
100
|
+
"and a message asking you to check back. In that case, wait about 20-30 seconds and "
|
|
101
|
+
"call `check_map_status(dataKey=...)` — do not call `generate_map` again for the same "
|
|
102
|
+
"location, that only starts a redundant duplicate job. Repeat `check_map_status` "
|
|
103
|
+
"(with the same wait between calls) until it returns the image.\n\n"
|
|
104
104
|
"## Important: re-download without regenerating\n"
|
|
105
105
|
"After generating a map, `generate_map` returns a `dataKey`. "
|
|
106
106
|
"You can call `redownload_map` with that `dataKey` to get the same map in a different "
|
|
@@ -137,8 +137,7 @@ def _make_filename(label: str, format: str) -> Path:
|
|
|
137
137
|
|
|
138
138
|
|
|
139
139
|
async def _download(client: httpx.AsyncClient, data_key: str, format: str,
|
|
140
|
-
color_set: str | None, canvas_width: int | None, canvas_height: int | None
|
|
141
|
-
edge_weight: int | None = None) -> bytes:
|
|
140
|
+
color_set: str | None, canvas_width: int | None, canvas_height: int | None) -> bytes:
|
|
142
141
|
params: dict = {"dataKey": data_key, "format": format}
|
|
143
142
|
if color_set is not None:
|
|
144
143
|
params["colorSet"] = color_set
|
|
@@ -146,14 +145,62 @@ async def _download(client: httpx.AsyncClient, data_key: str, format: str,
|
|
|
146
145
|
params["canvasWidth"] = canvas_width
|
|
147
146
|
if canvas_height is not None:
|
|
148
147
|
params["canvasHeight"] = canvas_height
|
|
149
|
-
if edge_weight is not None:
|
|
150
|
-
params["edgeWeight"] = edge_weight
|
|
151
148
|
resp = await client.get(f"{BASE_URL}/download", params=params, timeout=60)
|
|
152
149
|
if resp.status_code != 200:
|
|
153
150
|
raise RuntimeError(f"Download failed ({resp.status_code}): {resp.text}")
|
|
154
151
|
return resp.content
|
|
155
152
|
|
|
156
153
|
|
|
154
|
+
async def _poll_with_budget(
|
|
155
|
+
client: httpx.AsyncClient, data_key: str, budget_sec: float, ctx: Context | None,
|
|
156
|
+
) -> str:
|
|
157
|
+
"""dataKeyの状態をPOLL_INTERVAL_SEC間隔でbudget_sec以内までポーリングする。
|
|
158
|
+
"ready"/"failed"になればその時点で返す。budget_sec内に決着しなければ"pending"を
|
|
159
|
+
返す(例外は投げない、呼び出し側で分岐する)。"""
|
|
160
|
+
if ctx is not None:
|
|
161
|
+
await ctx.report_progress(0, budget_sec, "Map generation queued...")
|
|
162
|
+
elapsed = 0.0
|
|
163
|
+
while elapsed < budget_sec:
|
|
164
|
+
await asyncio.sleep(POLL_INTERVAL_SEC)
|
|
165
|
+
elapsed += POLL_INTERVAL_SEC
|
|
166
|
+
status_resp = await client.get(
|
|
167
|
+
f"{BASE_URL}/status", params={"dataKey": data_key}, timeout=10
|
|
168
|
+
)
|
|
169
|
+
status = status_resp.json().get("status")
|
|
170
|
+
if status in ("ready", "failed"):
|
|
171
|
+
return status
|
|
172
|
+
if ctx is not None:
|
|
173
|
+
await ctx.report_progress(
|
|
174
|
+
elapsed, budget_sec, f"Map generation in progress... ({elapsed:.0f}s elapsed)"
|
|
175
|
+
)
|
|
176
|
+
return "pending"
|
|
177
|
+
|
|
178
|
+
|
|
179
|
+
def _build_success_result(image_bytes: bytes, out_path: Path, data_key: str) -> list:
|
|
180
|
+
out_path.write_bytes(image_bytes)
|
|
181
|
+
return [
|
|
182
|
+
Image(data=image_bytes, format="png"),
|
|
183
|
+
(
|
|
184
|
+
f"Map saved: {out_path}\n"
|
|
185
|
+
f"dataKey: {data_key}\n\n"
|
|
186
|
+
f"Open in editor: https://mapnetwork.app/generate?dataKey={data_key}\n\n"
|
|
187
|
+
f"Tip: call redownload_map(data_key='{data_key}', ...) to get this map "
|
|
188
|
+
f"in a different color_set or format (svg/png) without regenerating."
|
|
189
|
+
),
|
|
190
|
+
]
|
|
191
|
+
|
|
192
|
+
|
|
193
|
+
def _still_in_progress_result(data_key: str) -> list:
|
|
194
|
+
return [(
|
|
195
|
+
f"Map generation is still in progress (dataKey={data_key}). This can take a few "
|
|
196
|
+
"minutes for busy areas. Wait about 20-30 seconds, then call "
|
|
197
|
+
f"check_map_status(data_key='{data_key}') to check again — pass the same format/"
|
|
198
|
+
"color_set/canvas_width/canvas_height you used with generate_map, if any. "
|
|
199
|
+
"Do NOT call generate_map again for the same location — that starts a redundant "
|
|
200
|
+
"duplicate job and wastes time."
|
|
201
|
+
)]
|
|
202
|
+
|
|
203
|
+
|
|
157
204
|
# ---------------------------------------------------------------------------
|
|
158
205
|
# Tool: compute_route
|
|
159
206
|
# ---------------------------------------------------------------------------
|
|
@@ -161,34 +208,15 @@ async def _download(client: httpx.AsyncClient, data_key: str, format: str,
|
|
|
161
208
|
@mcp.tool()
|
|
162
209
|
async def compute_route(
|
|
163
210
|
from_location: Annotated[
|
|
164
|
-
RouteEndpoint,
|
|
165
|
-
"Start point of the route. Provide 'location' for explicit coordinates (no geocoding), "
|
|
166
|
-
"or only 'label' to geocode server-side. Both may be provided — 'location' takes precedence, "
|
|
167
|
-
"'label' is used for display. Example: {\"label\": \"赤坂駅\"}",
|
|
211
|
+
RouteEndpoint, Field(description="Route start. 'location' for coordinates, or 'label' to geocode.")
|
|
168
212
|
],
|
|
169
|
-
to_location: Annotated[
|
|
170
|
-
|
|
171
|
-
"End point of the route. Same format as from_location. "
|
|
172
|
-
"Example: {\"label\": \"赤坂氷川神社\"}",
|
|
173
|
-
],
|
|
174
|
-
mode: Annotated[
|
|
175
|
-
str,
|
|
176
|
-
"Routing mode: 'walking' (default, footpaths and streets) or 'driving' (car-accessible roads).",
|
|
177
|
-
] = "walking",
|
|
213
|
+
to_location: Annotated[RouteEndpoint, Field(description="Route end. Same format as from_location.")],
|
|
214
|
+
mode: Annotated[Literal["walking", "driving"], Field(description="Default 'walking'.")] = "walking",
|
|
178
215
|
) -> dict:
|
|
179
|
-
"""Compute a
|
|
180
|
-
|
|
181
|
-
Returns the route as an ordered list of coordinates, plus the resolved from/to locations.
|
|
182
|
-
Pass the result directly to generate_map's `route` parameter to overlay it on a map image.
|
|
183
|
-
Use from/to as `markers` in generate_map to place pins at the start and end points.
|
|
216
|
+
"""Compute a route. Returns {coords, from, to} — pass directly to generate_map(route=...).
|
|
184
217
|
|
|
185
|
-
|
|
186
|
-
1. route = compute_route(from_location={"label": "A"}, to_location={"label": "B"})
|
|
187
|
-
2. generate_map(route=route, markers=[route["from"], route["to"]], ...)
|
|
218
|
+
Example: compute_route(from_location={"label": "Tokyo Station"}, to_location={"label": "Tokyo Tower"})
|
|
188
219
|
"""
|
|
189
|
-
if mode not in ("walking", "driving"):
|
|
190
|
-
raise ValueError("mode must be 'walking' or 'driving'")
|
|
191
|
-
|
|
192
220
|
body = {
|
|
193
221
|
"from": from_location.model_dump(exclude_none=True),
|
|
194
222
|
"to": to_location.model_dump(exclude_none=True),
|
|
@@ -216,104 +244,47 @@ async def compute_route(
|
|
|
216
244
|
@mcp.tool()
|
|
217
245
|
async def generate_map(
|
|
218
246
|
place: Annotated[
|
|
219
|
-
str | None,
|
|
220
|
-
"Place name to center the map on (e.g. 'Shibuya Station', '東京駅', 'Eiffel Tower'). "
|
|
221
|
-
"A red pin is placed at the resolved location. Use this OR lat/lng, not both. "
|
|
222
|
-
"Omit when using markers-only mode.",
|
|
223
|
-
] = None,
|
|
224
|
-
lat: Annotated[
|
|
225
|
-
float | None,
|
|
226
|
-
"Latitude of the map center. Must be combined with lng. "
|
|
227
|
-
"ONLY set this when you have a precise, verified coordinate value — never guess or estimate. "
|
|
228
|
-
"If the location is known only by name, use `place` instead and let the server geocode it. "
|
|
229
|
-
"Omit when using markers-only mode.",
|
|
230
|
-
] = None,
|
|
231
|
-
lng: Annotated[
|
|
232
|
-
float | None,
|
|
233
|
-
"Longitude of the map center. Must be combined with lat. "
|
|
234
|
-
"ONLY set this when you have a precise, verified coordinate value — never guess or estimate. "
|
|
235
|
-
"If the location is known only by name, use `place` instead and let the server geocode it. "
|
|
236
|
-
"Omit when using markers-only mode.",
|
|
237
|
-
] = None,
|
|
238
|
-
markers: Annotated[
|
|
239
|
-
list[Marker] | None,
|
|
240
|
-
"List of locations to pin on the map as blue markers. "
|
|
241
|
-
"Each item needs only a 'label' (geocoded automatically); explicit 'location' {lat, lng} is optional. "
|
|
242
|
-
"When markers are provided without place/lat/lng, the server derives the map center from their centroid "
|
|
243
|
-
"and sets radius automatically. "
|
|
244
|
-
"Example for two stations: [{\"label\": \"東京駅\"}, {\"label\": \"新宿駅\"}]",
|
|
245
|
-
] = None,
|
|
246
|
-
name: Annotated[
|
|
247
|
-
str | None,
|
|
248
|
-
"Map name stored in the data file. Used as the default download filename. "
|
|
249
|
-
"Omit to leave unnamed.",
|
|
247
|
+
str | None, Field(description="Place name to center the map on. Use this OR lat/lng, not both.")
|
|
250
248
|
] = None,
|
|
249
|
+
lat: Annotated[float | None, Field(description="Latitude of the map center. Must be combined with lng.")] = None,
|
|
250
|
+
lng: Annotated[float | None, Field(description="Longitude of the map center. Must be combined with lat.")] = None,
|
|
251
|
+
markers: Annotated[list[Marker] | None, Field(description="Locations to pin on the map.")] = None,
|
|
252
|
+
name: Annotated[str | None, Field(description="Map name stored in the data file.")] = None,
|
|
251
253
|
radius: Annotated[
|
|
252
254
|
int | None,
|
|
253
|
-
"Circular
|
|
254
|
-
"Mutually exclusive with size_ew/size_ns. "
|
|
255
|
-
"ONLY set this when the user has explicitly requested a specific coverage range. "
|
|
256
|
-
"If the user has not specified a range, omit it — the server applies a sensible default (500 m).",
|
|
255
|
+
Field(description="Circular radius in meters (default 500, max 2500). Exclusive with size_ew/size_ns."),
|
|
257
256
|
] = None,
|
|
258
257
|
size_ew: Annotated[
|
|
259
258
|
float | None,
|
|
260
|
-
"
|
|
261
|
-
"Must be combined with size_ns. Mutually exclusive with radius. "
|
|
262
|
-
"ONLY set this when the user has explicitly requested a rectangular area of specific dimensions. "
|
|
263
|
-
"Do not infer dimensions — omit and let the server use its default if the user has not specified.",
|
|
259
|
+
Field(description="Rectangular area width (east-west), meters. Must pair with size_ns; exclusive with radius."),
|
|
264
260
|
] = None,
|
|
265
261
|
size_ns: Annotated[
|
|
266
262
|
float | None,
|
|
267
|
-
"
|
|
268
|
-
"Must be combined with size_ew. Mutually exclusive with radius. "
|
|
269
|
-
"ONLY set this when the user has explicitly requested a rectangular area of specific dimensions.",
|
|
263
|
+
Field(description="Rectangular area height (north-south), meters. Must pair with size_ew."),
|
|
270
264
|
] = None,
|
|
271
265
|
layers: Annotated[
|
|
272
266
|
Literal["default", "road_and_railway", "only_driving_road", "fully_detailed"] | None,
|
|
273
|
-
"
|
|
274
|
-
"'only_driving_road': car-accessible roads only, nothing else. "
|
|
275
|
-
"'road_and_railway': roads + railway lines, no POI. "
|
|
276
|
-
"'fully_detailed': roads + railway + waterline + greenarea + POI "
|
|
277
|
-
"(waterline/greenarea only apply within Japan; ignored elsewhere). "
|
|
278
|
-
"Omit for 'default'.",
|
|
267
|
+
Field(description="Layer preset — see server instructions for what each preset includes. Omit for 'default'."),
|
|
279
268
|
] = None,
|
|
280
269
|
route: Annotated[
|
|
281
270
|
RouteInput | None,
|
|
282
|
-
"Route to overlay
|
|
283
|
-
"the server uses coords and (optionally) color from it. "
|
|
284
|
-
"To customise the line color, set/override the 'color' field (e.g. '#FF4500'). "
|
|
285
|
-
"Omit to generate a map without a route overlay.",
|
|
286
|
-
] = None,
|
|
287
|
-
config: Annotated[
|
|
288
|
-
MapConfig | None,
|
|
289
|
-
"Overrides for automatic layer-visibility defaults. Omit any field to keep the default. "
|
|
290
|
-
"Example to turn off buildings: {\"withBuilding\": false}.",
|
|
271
|
+
Field(description="Route to overlay — pass compute_route()'s result directly. Add/override 'color' (hex) to customize."),
|
|
291
272
|
] = None,
|
|
292
273
|
color_set: Annotated[
|
|
293
274
|
str | None,
|
|
294
|
-
"Color theme for the
|
|
295
|
-
"Baked into the stored map data so redownload_map uses the same theme by default. "
|
|
296
|
-
"Can be overridden per-download by passing color_set to redownload_map. "
|
|
297
|
-
"Available themes: white, darkBlue, darkGreen, popArt, lightBlue, lightGreen, beige, magenta, gray, black, brawn.",
|
|
275
|
+
Field(description="Color theme name — see server instructions for the list. Only set when explicitly requested."),
|
|
298
276
|
] = None,
|
|
299
|
-
format: Annotated[
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
] = "png",
|
|
303
|
-
canvas_width: Annotated[int | None, "Canvas width in pixels. Omit to use server default (1000)."] = None,
|
|
304
|
-
canvas_height: Annotated[int | None, "Canvas height in pixels. Omit to use server default (600)."] = None,
|
|
277
|
+
format: Annotated[Literal["png", "svg"], Field(description="'png' (default) or 'svg'.")] = "png",
|
|
278
|
+
canvas_width: Annotated[int | None, Field(description="Canvas width in pixels (default 1000).")] = None,
|
|
279
|
+
canvas_height: Annotated[int | None, Field(description="Canvas height in pixels (default 600).")] = None,
|
|
305
280
|
ctx: Context = None,
|
|
306
281
|
) -> list:
|
|
307
|
-
"""Generate a styled map image
|
|
282
|
+
"""Generate a styled map image and save it to Downloads.
|
|
308
283
|
|
|
309
|
-
|
|
310
|
-
-
|
|
311
|
-
- radius=N: circular, N meters
|
|
312
|
-
- size_ew + size_ns: rectangular bounding box
|
|
284
|
+
May return a pending dataKey instead of the image — see server instructions for the
|
|
285
|
+
check_map_status follow-up flow.
|
|
313
286
|
|
|
314
|
-
|
|
315
|
-
Use redownload_map(dataKey=...) to get the same map in a different color or format
|
|
316
|
-
without waiting for regeneration.
|
|
287
|
+
Example: generate_map(place="Tokyo Station")
|
|
317
288
|
"""
|
|
318
289
|
has_center = place or (lat is not None and lng is not None)
|
|
319
290
|
has_route_coords = route is not None and route.coords is not None and len(route.coords) >= 2
|
|
@@ -343,8 +314,6 @@ async def generate_map(
|
|
|
343
314
|
body["size"] = {"ew": size_ew, "ns": size_ns}
|
|
344
315
|
if route is not None:
|
|
345
316
|
body["route"] = route.model_dump(by_alias=True, exclude_none=True)
|
|
346
|
-
if config is not None:
|
|
347
|
-
body["config"] = config.model_dump(exclude_none=True)
|
|
348
317
|
|
|
349
318
|
async with httpx.AsyncClient() as client:
|
|
350
319
|
# 1. Enqueue
|
|
@@ -357,34 +326,20 @@ async def generate_map(
|
|
|
357
326
|
raise RuntimeError(f"Request rejected ({resp.status_code}): {detail}")
|
|
358
327
|
data_key = resp.json()["dataKey"]
|
|
359
328
|
|
|
360
|
-
# 2. Poll
|
|
361
|
-
#
|
|
362
|
-
#
|
|
363
|
-
#
|
|
364
|
-
#
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
status_resp = await client.get(
|
|
372
|
-
f"{BASE_URL}/status", params={"dataKey": data_key}, timeout=10
|
|
329
|
+
# 2. Poll, but only up to INITIAL_WAIT_SEC (安全のためMCPクライアントの典型的な
|
|
330
|
+
# 60秒タイムアウトより十分短くしてある)。多くの地図生成はこの範囲で終わるため、
|
|
331
|
+
# その場合はこの1回の呼び出しだけで完結する。間に合わなければ、ここで打ち切って
|
|
332
|
+
# dataKeyを返し、check_map_statusでの確認をモデルに促す(生成自体はバックエンドで
|
|
333
|
+
# 継続しているので、ここで諦めても失敗にはならない)。
|
|
334
|
+
status = await _poll_with_budget(client, data_key, INITIAL_WAIT_SEC, ctx)
|
|
335
|
+
|
|
336
|
+
if status == "failed":
|
|
337
|
+
raise RuntimeError(
|
|
338
|
+
f"Map generation failed (dataKey={data_key}). "
|
|
339
|
+
"Try a different location or smaller radius."
|
|
373
340
|
)
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
break
|
|
377
|
-
if status == "failed":
|
|
378
|
-
raise RuntimeError(
|
|
379
|
-
f"Map generation failed (dataKey={data_key}). "
|
|
380
|
-
"Try a different location or smaller radius."
|
|
381
|
-
)
|
|
382
|
-
if ctx is not None:
|
|
383
|
-
await ctx.report_progress(
|
|
384
|
-
elapsed, MAX_WAIT_SEC, f"Map generation in progress... ({elapsed:.0f}s elapsed)"
|
|
385
|
-
)
|
|
386
|
-
else:
|
|
387
|
-
raise TimeoutError(f"Map generation timed out after {MAX_WAIT_SEC}s.")
|
|
341
|
+
if status == "pending":
|
|
342
|
+
return _still_in_progress_result(data_key)
|
|
388
343
|
|
|
389
344
|
# 3. Download
|
|
390
345
|
image_bytes = await _download(client, data_key, format, color_set,
|
|
@@ -398,60 +353,79 @@ async def generate_map(
|
|
|
398
353
|
label = "_".join(m.label or "" for m in markers)[:40]
|
|
399
354
|
else:
|
|
400
355
|
label = "route"
|
|
401
|
-
|
|
402
|
-
out_path.write_bytes(image_bytes)
|
|
403
|
-
|
|
404
|
-
return [
|
|
405
|
-
Image(data=image_bytes, format="png" if format == "png" else "png"),
|
|
406
|
-
(
|
|
407
|
-
f"Map saved: {out_path}\n"
|
|
408
|
-
f"dataKey: {data_key}\n\n"
|
|
409
|
-
f"Open in editor: https://mapnetwork.app/generate?dataKey={data_key}\n\n"
|
|
410
|
-
f"Tip: call redownload_map(data_key='{data_key}', ...) to get this map "
|
|
411
|
-
f"in a different color_set or format (svg/png) without regenerating."
|
|
412
|
-
),
|
|
413
|
-
]
|
|
356
|
+
return _build_success_result(image_bytes, _make_filename(label, format), data_key)
|
|
414
357
|
|
|
415
358
|
|
|
416
359
|
# ---------------------------------------------------------------------------
|
|
417
|
-
# Tool:
|
|
360
|
+
# Tool: check_map_status
|
|
418
361
|
# ---------------------------------------------------------------------------
|
|
419
362
|
|
|
420
363
|
@mcp.tool()
|
|
421
|
-
async def
|
|
364
|
+
async def check_map_status(
|
|
422
365
|
data_key: Annotated[
|
|
423
366
|
str,
|
|
424
|
-
"The dataKey returned by a
|
|
425
|
-
"The map data is reused — no regeneration occurs.",
|
|
367
|
+
Field(description="The dataKey returned by a generate_map call that reported it was still in progress."),
|
|
426
368
|
],
|
|
427
369
|
color_set: Annotated[
|
|
428
370
|
str | None,
|
|
429
|
-
"Color theme
|
|
430
|
-
"Available: white, darkBlue, darkGreen, popArt, lightBlue, lightGreen, beige, magenta, gray, black, brawn.",
|
|
371
|
+
Field(description="Color theme, matching what generate_map was called with, if any."),
|
|
431
372
|
] = None,
|
|
432
|
-
format: Annotated[
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
] =
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
373
|
+
format: Annotated[Literal["png", "svg"], Field(description="Matching what generate_map was called with.")] = "png",
|
|
374
|
+
canvas_width: Annotated[
|
|
375
|
+
int | None, Field(description="Canvas width, matching what generate_map was called with, if any.")
|
|
376
|
+
] = None,
|
|
377
|
+
canvas_height: Annotated[
|
|
378
|
+
int | None, Field(description="Canvas height, matching what generate_map was called with, if any.")
|
|
379
|
+
] = None,
|
|
380
|
+
ctx: Context = None,
|
|
381
|
+
) -> list:
|
|
382
|
+
"""Poll a pending generate_map job and download it once ready. Wait ~20-30s between calls.
|
|
383
|
+
|
|
384
|
+
Example: check_map_status(data_key="20260618aBcDeFgHiJ")
|
|
385
|
+
"""
|
|
386
|
+
async with httpx.AsyncClient() as client:
|
|
387
|
+
# 連打されても機械的に間隔が空くようにする最低限のスロットル
|
|
388
|
+
await asyncio.sleep(CHECK_THROTTLE_SEC)
|
|
389
|
+
status_resp = await client.get(f"{BASE_URL}/status", params={"dataKey": data_key}, timeout=10)
|
|
390
|
+
status = status_resp.json().get("status")
|
|
391
|
+
if status == "failed":
|
|
392
|
+
raise RuntimeError(
|
|
393
|
+
f"Map generation failed (dataKey={data_key}). "
|
|
394
|
+
"Try a different location or smaller radius."
|
|
395
|
+
)
|
|
396
|
+
if status != "ready":
|
|
397
|
+
if ctx is not None:
|
|
398
|
+
await ctx.report_progress(0, 1, "Map generation still in progress...")
|
|
399
|
+
return _still_in_progress_result(data_key)
|
|
400
|
+
|
|
401
|
+
image_bytes = await _download(client, data_key, format, color_set,
|
|
402
|
+
canvas_width, canvas_height)
|
|
403
|
+
|
|
404
|
+
return _build_success_result(image_bytes, _make_filename(data_key, format), data_key)
|
|
405
|
+
|
|
406
|
+
|
|
407
|
+
# ---------------------------------------------------------------------------
|
|
408
|
+
# Tool: redownload_map
|
|
409
|
+
# ---------------------------------------------------------------------------
|
|
410
|
+
|
|
411
|
+
@mcp.tool()
|
|
412
|
+
async def redownload_map(
|
|
413
|
+
data_key: Annotated[str, Field(description="The dataKey returned by a previous generate_map call.")],
|
|
414
|
+
color_set: Annotated[
|
|
415
|
+
str | None,
|
|
416
|
+
Field(description="Color theme — see server instructions for the list. Only set when explicitly requested."),
|
|
442
417
|
] = None,
|
|
418
|
+
format: Annotated[Literal["png", "svg"], Field(description="'png' (raster) or 'svg' (vector).")] = "png",
|
|
419
|
+
canvas_width: Annotated[int | None, Field(description="Canvas width in pixels (default 1000).")] = None,
|
|
420
|
+
canvas_height: Annotated[int | None, Field(description="Canvas height in pixels (default 600).")] = None,
|
|
443
421
|
) -> list:
|
|
444
|
-
"""Re-download a
|
|
422
|
+
"""Re-download a prior map in a different color theme, format, or size — instant, no regeneration.
|
|
445
423
|
|
|
446
|
-
|
|
447
|
-
so this is instant. Use this when the user wants to:
|
|
448
|
-
- Try a different color theme (e.g. 'black' for dark mode, 'lightBlue', 'popArt')
|
|
449
|
-
- Get an SVG version of a map already generated as PNG
|
|
450
|
-
- Get a larger or smaller canvas size
|
|
424
|
+
Example: redownload_map(data_key="20260618aBcDeFgHiJ", color_set="black")
|
|
451
425
|
"""
|
|
452
426
|
async with httpx.AsyncClient() as client:
|
|
453
427
|
image_bytes = await _download(client, data_key, format, color_set,
|
|
454
|
-
canvas_width, canvas_height
|
|
428
|
+
canvas_width, canvas_height)
|
|
455
429
|
|
|
456
430
|
out_path = _make_filename(data_key, format)
|
|
457
431
|
out_path.write_bytes(image_bytes)
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "mapnetwork-mcp"
|
|
3
|
-
version = "
|
|
3
|
+
version = "2.0.0"
|
|
4
4
|
description = "MCP server — generate styled map images via mapnetwork.app"
|
|
5
5
|
readme = "README.md"
|
|
6
|
+
license = "MIT"
|
|
7
|
+
license-files = ["LICENSE"]
|
|
6
8
|
requires-python = ">=3.11"
|
|
7
9
|
dependencies = [
|
|
8
10
|
# mcp 2.0.0はmcp.server.fastmcp(Context/FastMCP/Image)を含む破壊的変更が入っており、
|
|
@@ -26,5 +28,7 @@ exclude = ["/.idea", "/dist", "__pycache__", "/mcp-publisher*.exe", "/server.jso
|
|
|
26
28
|
exclude = ["/.idea", "__pycache__"]
|
|
27
29
|
|
|
28
30
|
[build-system]
|
|
29
|
-
|
|
31
|
+
# hatchling>=1.32はMetadata-Version 2.5を出力するが、現行のpackaging/twineが
|
|
32
|
+
# まだ認識せず"twine check"が壊れる(2.4を出力する1.31系に固定して回避)
|
|
33
|
+
requires = ["hatchling<1.32"]
|
|
30
34
|
build-backend = "hatchling.build"
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|