mapnetwork-mcp 1.1.0__tar.gz → 1.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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: mapnetwork-mcp
3
- Version: 1.1.0
3
+ Version: 1.2.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
@@ -2,7 +2,7 @@
2
2
  "manifest_version": "0.4",
3
3
  "name": "mapnetwork-mcp",
4
4
  "display_name": "MapNetwork",
5
- "version": "1.1.0",
5
+ "version": "1.2.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": {
@@ -5,15 +5,71 @@ import os
5
5
  import re
6
6
  from datetime import datetime
7
7
  from pathlib import Path
8
- from typing import Annotated
8
+ from typing import Annotated, Literal
9
9
 
10
10
  import httpx
11
11
  from mcp.server.fastmcp import FastMCP, Image
12
+ from pydantic import BaseModel, ConfigDict, Field
12
13
 
13
14
  BASE_URL = os.environ.get("MAPNETWORK_BASE_URL", "https://mapnetwork.app")
14
15
  POLL_INTERVAL_SEC = 10.0
15
16
  MAX_WAIT_SEC = 600
16
17
 
18
+ # layersは自由な多値配列にすると、モデルが「roadはhighway/driving/walkingの上位互換」
19
+ # といった内部の組み合わせルールを知らないまま組み合わせを選んでしまう。
20
+ # 人間側で意味のある4パターンだけに絞り込み、モデルにはこのプリセット名だけを選ばせる。
21
+ _LAYER_PRESETS: dict[str, list[str]] = {
22
+ "default": ["road", "poi"],
23
+ "road_and_railway": ["road", "railway", "poi"],
24
+ "only_driving_road": ["driving"],
25
+ "fully_detailed": ["road", "railway", "poi", "waterline", "greenarea"],
26
+ }
27
+
28
+
29
+ class Location(BaseModel):
30
+ lat: float
31
+ lng: float
32
+
33
+
34
+ class Marker(BaseModel):
35
+ label: str | None = Field(default=None, description="Place name for geocoding and/or display.")
36
+ location: Location | None = Field(
37
+ default=None,
38
+ description="Explicit coordinates. If provided, geocoding of 'label' is skipped.",
39
+ )
40
+
41
+
42
+ class RouteEndpoint(BaseModel):
43
+ label: str | None = Field(default=None, description="Place name for geocoding and/or display.")
44
+ location: Location | None = Field(default=None, description="Explicit coordinates.")
45
+
46
+
47
+ class RouteInput(BaseModel):
48
+ """generate_mapのrouteパラメータ。compute_routeの戻り値をそのまま渡せる形にする。"""
49
+ model_config = ConfigDict(populate_by_name=True)
50
+
51
+ coords: list[list[float]] | None = Field(
52
+ default=None, description="Ordered list of [lat, lng] pairs along the route."
53
+ )
54
+ mode: Literal["walking", "driving"] | None = None
55
+ from_: RouteEndpoint | None = Field(default=None, alias="from", description="Route start point.")
56
+ to: RouteEndpoint | None = Field(default=None, description="Route end point.")
57
+ color: str | None = Field(default=None, description="Optional line color as a CSS hex color (e.g. '#FF4500').")
58
+
59
+
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
+
17
73
  mcp = FastMCP(
18
74
  "MapNetwork",
19
75
  instructions=(
@@ -29,10 +85,10 @@ mcp = FastMCP(
29
85
  "- **Circular area**: specify `radius` in meters (default 500, max 2500) around the center\n"
30
86
  "- **Rectangular area**: specify `size_ew` (east-west) and `size_ns` (north-south) in meters "
31
87
  "instead of radius — useful when the area of interest is not square\n"
32
- "- **Layers**: choose which features appear. "
33
- "Use EXACTLY these values (singular, no trailing 's'): "
34
- "'road', 'highway', 'driving', 'walking', 'railway', 'waterline', 'greenarea', 'poi'. "
35
- "Wrong: 'roads', 'railways', 'waterlines' — these will be rejected by the server.\n"
88
+ "- **Layers**: choose a preset via `layers` — 'default' (roads + POI), "
89
+ "'only_driving_road' (car-accessible roads only), 'road_and_railway' (roads + railway, no POI), "
90
+ "or 'fully_detailed' (roads + railway + waterline + greenarea + POI; waterline/greenarea only "
91
+ "apply within Japan). Omit for 'default'.\n"
36
92
  "- **Color themes** via `color_set`: "
37
93
  "white (clean, default), darkBlue (navy bg), darkGreen (dark teal bg), "
38
94
  "popArt (blue bg, bold contrast), lightBlue (pale blue bg), lightGreen (pale green bg), "
@@ -105,14 +161,13 @@ async def _download(client: httpx.AsyncClient, data_key: str, format: str,
105
161
  @mcp.tool()
106
162
  async def compute_route(
107
163
  from_location: Annotated[
108
- dict,
109
- "Start point of the route. "
110
- "Use {\"label\": \"place name\"} to geocode server-side, "
111
- "or {\"label\": \"...\", \"location\": {\"lat\": ..., \"lng\": ...}} to supply explicit coordinates. "
112
- "Example: {\"label\": \"赤坂駅\"}",
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\": \"赤坂駅\"}",
113
168
  ],
114
169
  to_location: Annotated[
115
- dict,
170
+ RouteEndpoint,
116
171
  "End point of the route. Same format as from_location. "
117
172
  "Example: {\"label\": \"赤坂氷川神社\"}",
118
173
  ],
@@ -134,7 +189,11 @@ async def compute_route(
134
189
  if mode not in ("walking", "driving"):
135
190
  raise ValueError("mode must be 'walking' or 'driving'")
136
191
 
137
- body = {"from": from_location, "to": to_location, "mode": mode}
192
+ body = {
193
+ "from": from_location.model_dump(exclude_none=True),
194
+ "to": to_location.model_dump(exclude_none=True),
195
+ "mode": mode,
196
+ }
138
197
  async with httpx.AsyncClient() as client:
139
198
  resp = await client.post(f"{BASE_URL}/route", json=body, timeout=180)
140
199
  if resp.status_code == 404:
@@ -177,25 +236,13 @@ async def generate_map(
177
236
  "Omit when using markers-only mode.",
178
237
  ] = None,
179
238
  markers: Annotated[
180
- list[dict] | None,
239
+ list[Marker] | None,
181
240
  "List of locations to pin on the map as blue markers. "
182
- "Each item: {\"label\": \"place name\"} — the server geocodes it automatically. "
183
- "Optionally include explicit coordinates: {\"label\": \"...\", \"location\": {\"lat\": ..., \"lng\": ...}}. "
184
- "Each marker may also include an optional \"icon\" field to override its appearance: "
185
- "{\"label\": \"...\", \"icon\": {\"color\": \"#ff0000\"}}. "
186
- "All icon sub-fields (code/size/color) are optional — omit any to keep the default. "
241
+ "Each item needs only a 'label' (geocoded automatically); explicit 'location' {lat, lng} is optional. "
187
242
  "When markers are provided without place/lat/lng, the server derives the map center from their centroid "
188
243
  "and sets radius automatically. "
189
244
  "Example for two stations: [{\"label\": \"東京駅\"}, {\"label\": \"新宿駅\"}]",
190
245
  ] = None,
191
- place_icon: Annotated[
192
- dict | None,
193
- "Custom icon for the `place` pin (or center pin if no `place`). "
194
- "All fields are optional — specify only what you want to override. "
195
- "Fields: code (FontAwesome \\uXXXX), size (pixels), color (CSS hex). "
196
- "Example (red icon, larger): {\"color\": \"#ff0000\", \"size\": 50}. "
197
- "Omit entirely to use the default icon.",
198
- ] = None,
199
246
  name: Annotated[
200
247
  str | None,
201
248
  "Map name stored in the data file. Used as the default download filename. "
@@ -222,39 +269,24 @@ async def generate_map(
222
269
  "ONLY set this when the user has explicitly requested a rectangular area of specific dimensions.",
223
270
  ] = None,
224
271
  layers: Annotated[
225
- list[str] | None,
226
- "Map layers to render. Default ['road', 'poi']. "
227
- "IMPORTANT: use EXACTLY these singular spellings — never add 's' or change the spelling:\n"
228
- "'road' — all roads (supersedes highway/driving/walking; no need to add them when road is present)\n"
229
- "'highway' — major roads only\n"
230
- "'driving' — car-accessible roads\n"
231
- "'walking' — footpaths and pedestrian walkways\n"
232
- "'railway' — train and subway lines\n"
233
- "'waterline' — rivers, lakes, and coastlines\n"
234
- "'greenarea' — forests and woods\n"
235
- "'poi' — point-of-interest icons (filterable with poi_types)\n"
236
- "Example for road + railway + POI: ['road', 'railway', 'poi']",
237
- ] = None,
238
- poi_types: Annotated[
239
- list[str] | None,
240
- "Filter POI categories when 'poi' is in layers. Omit to include all. "
241
- "Valid values: museum, library, theatre, convenience, supermarket, "
242
- "school, religion, station, park, hospital, cityhall, cafe, restaurant.",
272
+ Literal["default", "road_and_railway", "only_driving_road", "fully_detailed"] | None,
273
+ "Preset combination of map layers. 'default': roads + POI icons. "
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'.",
243
279
  ] = None,
244
280
  route: Annotated[
245
- dict | None,
281
+ RouteInput | None,
246
282
  "Route to overlay on the map. Pass the full response from compute_route() directly — "
247
283
  "the server uses coords and (optionally) color from it. "
248
- "To customise the line color, add a 'color' key: {**route_result, 'color': '#FF4500'}. "
284
+ "To customise the line color, set/override the 'color' field (e.g. '#FF4500'). "
249
285
  "Omit to generate a map without a route overlay.",
250
286
  ] = None,
251
287
  config: Annotated[
252
- dict | None,
288
+ MapConfig | None,
253
289
  "Overrides for automatic layer-visibility defaults. Omit any field to keep the default. "
254
- "Fields (all optional booleans): "
255
- "'patchworked' (auto-color closed areas and building shapes, default true), "
256
- "'withBuilding' (draw building shapes, default true when building data is available), "
257
- "'withSeaRibbon' (draw a band representing the sea along the coastline, default true when coastline data is available). "
258
290
  "Example to turn off buildings: {\"withBuilding\": false}.",
259
291
  ] = None,
260
292
  color_set: Annotated[
@@ -269,12 +301,7 @@ async def generate_map(
269
301
  "Output file format: 'png' (default, raster image) or 'svg' (vector, scalable to any size).",
270
302
  ] = "png",
271
303
  canvas_width: Annotated[int | None, "Canvas width in pixels. Omit to use server default (1000)."] = None,
272
- canvas_height: Annotated[int | None, "Canvas height in pixels. Omit to use server default (700)."] = None,
273
- edge_weight: Annotated[
274
- int | None,
275
- "Road and line width adjustment. Positive values thicken lines, negative values thin them. "
276
- "Default 0 (no adjustment). Example: 2 to make roads slightly thicker, -1 to make them thinner.",
277
- ] = None,
304
+ canvas_height: Annotated[int | None, "Canvas height in pixels. Omit to use server default (600)."] = None,
278
305
  ) -> list:
279
306
  """Generate a styled map image for a given location and save it to Downloads.
280
307
 
@@ -288,8 +315,9 @@ async def generate_map(
288
315
  without waiting for regeneration.
289
316
  """
290
317
  has_center = place or (lat is not None and lng is not None)
291
- if not has_center and not markers:
292
- raise ValueError("Specify 'place', both 'lat'+'lng', or 'markers'.")
318
+ has_route_coords = route is not None and route.coords is not None and len(route.coords) >= 2
319
+ if not has_center and not markers and not has_route_coords:
320
+ raise ValueError("Specify 'place', both 'lat'+'lng', 'markers', or a 'route' with coords.")
293
321
  if radius is not None and (size_ew is not None or size_ns is not None):
294
322
  raise ValueError("Specify either 'radius' or 'size_ew'+'size_ns', not both.")
295
323
  if (size_ew is None) != (size_ns is None):
@@ -297,15 +325,13 @@ async def generate_map(
297
325
 
298
326
  body: dict = {}
299
327
  if layers is not None:
300
- body["layers"] = layers
328
+ body["layers"] = _LAYER_PRESETS[layers]
301
329
  if place:
302
330
  body["place"] = place
303
331
  elif lat is not None and lng is not None:
304
332
  body["center"] = {"lat": lat, "lng": lng}
305
333
  if markers is not None:
306
- body["markers"] = markers
307
- if place_icon is not None:
308
- body["icon"] = place_icon
334
+ body["markers"] = [m.model_dump(exclude_none=True) for m in markers]
309
335
  if name is not None:
310
336
  body["name"] = name
311
337
  if color_set is not None:
@@ -314,12 +340,10 @@ async def generate_map(
314
340
  body["radius"] = radius
315
341
  elif size_ew is not None:
316
342
  body["size"] = {"ew": size_ew, "ns": size_ns}
317
- if poi_types:
318
- body["poiTypes"] = poi_types
319
343
  if route is not None:
320
- body["route"] = route
344
+ body["route"] = route.model_dump(by_alias=True, exclude_none=True)
321
345
  if config is not None:
322
- body["config"] = config
346
+ body["config"] = config.model_dump(exclude_none=True)
323
347
 
324
348
  async with httpx.AsyncClient() as client:
325
349
  # 1. Enqueue
@@ -353,14 +377,16 @@ async def generate_map(
353
377
 
354
378
  # 3. Download
355
379
  image_bytes = await _download(client, data_key, format, color_set,
356
- canvas_width, canvas_height, edge_weight)
380
+ canvas_width, canvas_height)
357
381
 
358
382
  if place:
359
383
  label = place
360
384
  elif lat is not None and lng is not None:
361
385
  label = f"{lat}_{lng}"
386
+ elif markers:
387
+ label = "_".join(m.label or "" for m in markers)[:40]
362
388
  else:
363
- label = "_".join(m.get("label", "") for m in (markers or []))[:40]
389
+ label = "route"
364
390
  out_path = _make_filename(label, format)
365
391
  out_path.write_bytes(image_bytes)
366
392
 
@@ -397,7 +423,7 @@ async def redownload_map(
397
423
  "'png' (raster) or 'svg' (vector, infinitely scalable).",
398
424
  ] = "png",
399
425
  canvas_width: Annotated[int | None, "Canvas width in pixels. Omit to use server default (1000)."] = None,
400
- canvas_height: Annotated[int | None, "Canvas height in pixels. Omit to use server default (700)."] = None,
426
+ canvas_height: Annotated[int | None, "Canvas height in pixels. Omit to use server default (600)."] = None,
401
427
  edge_weight: Annotated[
402
428
  int | None,
403
429
  "Road and line width adjustment. Positive values thicken lines, negative values thin them. "
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "mapnetwork-mcp"
3
- version = "1.1.0"
3
+ version = "1.2.0"
4
4
  description = "MCP server — generate styled map images via mapnetwork.app"
5
5
  readme = "README.md"
6
6
  requires-python = ">=3.11"
File without changes
File without changes