mapy-com-mcp 0.2.0__tar.gz → 0.3.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 (57) hide show
  1. {mapy_com_mcp-0.2.0 → mapy_com_mcp-0.3.0}/.claude/agents/review-agent.md +1 -1
  2. mapy_com_mcp-0.3.0/.release-please-manifest.json +3 -0
  3. {mapy_com_mcp-0.2.0 → mapy_com_mcp-0.3.0}/AGENTS.md +6 -3
  4. {mapy_com_mcp-0.2.0 → mapy_com_mcp-0.3.0}/CHANGELOG.md +11 -0
  5. {mapy_com_mcp-0.2.0 → mapy_com_mcp-0.3.0}/PKG-INFO +15 -9
  6. mapy_com_mcp-0.3.0/README.md +59 -0
  7. {mapy_com_mcp-0.2.0 → mapy_com_mcp-0.3.0}/pyproject.toml +3 -2
  8. {mapy_com_mcp-0.2.0 → mapy_com_mcp-0.3.0}/release-please-config.json +3 -1
  9. mapy_com_mcp-0.3.0/src/mapy_com_mcp/links/__init__.py +1 -0
  10. {mapy_com_mcp-0.2.0/src/mapy_com_mcp → mapy_com_mcp-0.3.0/src/mapy_com_mcp/links}/urls.py +20 -42
  11. mapy_com_mcp-0.3.0/src/mapy_com_mcp/mapy_api/__init__.py +1 -0
  12. mapy_com_mcp-0.2.0/src/mapy_com_mcp/mapy_client.py → mapy_com_mcp-0.3.0/src/mapy_com_mcp/mapy_api/client.py +42 -1
  13. {mapy_com_mcp-0.2.0/src/mapy_com_mcp → mapy_com_mcp-0.3.0/src/mapy_com_mcp/mapy_api}/geocoding.py +2 -2
  14. {mapy_com_mcp-0.2.0 → mapy_com_mcp-0.3.0}/src/mapy_com_mcp/server.py +11 -11
  15. mapy_com_mcp-0.3.0/src/mapy_com_mcp/static_map/__init__.py +1 -0
  16. mapy_com_mcp-0.3.0/src/mapy_com_mcp/static_map/render.py +179 -0
  17. mapy_com_mcp-0.3.0/src/mapy_com_mcp/static_map/viewport.py +124 -0
  18. {mapy_com_mcp-0.2.0 → mapy_com_mcp-0.3.0}/src/mapy_com_mcp/tools/find_places.py +4 -4
  19. {mapy_com_mcp-0.2.0 → mapy_com_mcp-0.3.0}/src/mapy_com_mcp/tools/route_url.py +3 -3
  20. mapy_com_mcp-0.3.0/src/mapy_com_mcp/tools/show_places.py +146 -0
  21. mapy_com_mcp-0.3.0/tests/README.md +49 -0
  22. {mapy_com_mcp-0.2.0 → mapy_com_mcp-0.3.0}/tests/test_find_places.py +2 -2
  23. {mapy_com_mcp-0.2.0 → mapy_com_mcp-0.3.0}/tests/test_mapy_client.py +63 -3
  24. mapy_com_mcp-0.3.0/tests/test_render.py +93 -0
  25. mapy_com_mcp-0.3.0/tests/test_show_places.py +298 -0
  26. {mapy_com_mcp-0.2.0 → mapy_com_mcp-0.3.0}/tests/test_uc_encoder.py +2 -2
  27. {mapy_com_mcp-0.2.0 → mapy_com_mcp-0.3.0}/tests/test_urls.py +71 -150
  28. mapy_com_mcp-0.3.0/tests/test_viewport.py +163 -0
  29. {mapy_com_mcp-0.2.0 → mapy_com_mcp-0.3.0}/uv.lock +81 -3
  30. mapy_com_mcp-0.2.0/.release-please-manifest.json +0 -3
  31. mapy_com_mcp-0.2.0/README.md +0 -54
  32. mapy_com_mcp-0.2.0/src/mapy_com_mcp/tools/points_url.py +0 -78
  33. mapy_com_mcp-0.2.0/tests/README.md +0 -43
  34. mapy_com_mcp-0.2.0/tests/test_points_url.py +0 -115
  35. {mapy_com_mcp-0.2.0 → mapy_com_mcp-0.3.0}/.claude/agents/test-agent.md +0 -0
  36. {mapy_com_mcp-0.2.0 → mapy_com_mcp-0.3.0}/.editorconfig +0 -0
  37. {mapy_com_mcp-0.2.0 → mapy_com_mcp-0.3.0}/.github/ISSUE_TEMPLATE/bug_report.md +0 -0
  38. {mapy_com_mcp-0.2.0 → mapy_com_mcp-0.3.0}/.github/ISSUE_TEMPLATE/feature_request.md +0 -0
  39. {mapy_com_mcp-0.2.0 → mapy_com_mcp-0.3.0}/.github/dependabot.yml +0 -0
  40. {mapy_com_mcp-0.2.0 → mapy_com_mcp-0.3.0}/.github/pull_request_template.md +0 -0
  41. {mapy_com_mcp-0.2.0 → mapy_com_mcp-0.3.0}/.github/workflows/ci.yml +0 -0
  42. {mapy_com_mcp-0.2.0 → mapy_com_mcp-0.3.0}/.github/workflows/release-please.yml +0 -0
  43. {mapy_com_mcp-0.2.0 → mapy_com_mcp-0.3.0}/.github/workflows/release.yml +0 -0
  44. {mapy_com_mcp-0.2.0 → mapy_com_mcp-0.3.0}/.gitignore +0 -0
  45. {mapy_com_mcp-0.2.0 → mapy_com_mcp-0.3.0}/.pre-commit-config.yaml +0 -0
  46. {mapy_com_mcp-0.2.0 → mapy_com_mcp-0.3.0}/.python-version +0 -0
  47. {mapy_com_mcp-0.2.0 → mapy_com_mcp-0.3.0}/CLAUDE.md +0 -0
  48. {mapy_com_mcp-0.2.0 → mapy_com_mcp-0.3.0}/CONTRIBUTING.md +0 -0
  49. {mapy_com_mcp-0.2.0 → mapy_com_mcp-0.3.0}/LICENSE +0 -0
  50. {mapy_com_mcp-0.2.0 → mapy_com_mcp-0.3.0}/Makefile +0 -0
  51. {mapy_com_mcp-0.2.0 → mapy_com_mcp-0.3.0}/SECURITY.md +0 -0
  52. {mapy_com_mcp-0.2.0 → mapy_com_mcp-0.3.0}/src/mapy_com_mcp/__init__.py +0 -0
  53. /mapy_com_mcp-0.2.0/src/mapy_com_mcp/_uc_encoder.py → /mapy_com_mcp-0.3.0/src/mapy_com_mcp/links/uc_encoder.py +0 -0
  54. {mapy_com_mcp-0.2.0 → mapy_com_mcp-0.3.0}/src/mapy_com_mcp/tools/__init__.py +0 -0
  55. {mapy_com_mcp-0.2.0 → mapy_com_mcp-0.3.0}/tests/conftest.py +0 -0
  56. {mapy_com_mcp-0.2.0 → mapy_com_mcp-0.3.0}/tests/test_route_url.py +0 -0
  57. {mapy_com_mcp-0.2.0 → mapy_com_mcp-0.3.0}/tests/test_server.py +0 -0
@@ -33,7 +33,7 @@ range the main agent's brief specifies) and check, in roughly this order:
33
33
  Flag immediately if found.
34
34
 
35
35
  2. **Architectural boundaries (per `.context/architecture.md`).**
36
- - Tools call `mapy_client.py`, not `httpx` directly.
36
+ - Tools call `mapy_api/`, not `httpx` directly.
37
37
  - One file per tool in `src/mapy_com_mcp/tools/`.
38
38
  - `src/` layout respected; nothing leaks outside it.
39
39
  - No new top-level dependency without an entry in
@@ -0,0 +1,3 @@
1
+ {
2
+ ".": "0.3.0"
3
+ }
@@ -18,8 +18,11 @@ For the public pitch and quickstart, read `README.md`.
18
18
  src/mapy_com_mcp/
19
19
  __init__.py
20
20
  server.py # FastMCP entry, main(), tool auto-registration
21
- mapy_client.py # the only place that talks to mapy.com over HTTP
22
- tools/ # one file per MCP tool
21
+ tools/ # one file per MCP tool — thin MCP wrappers
22
+ mapy_api/ # the only place that talks to mapy.com over HTTP
23
+ client.py # HTTP client (auth, timeouts, error mapping)
24
+ geocoding.py # geocoding request/response models
25
+ links/ # pure mapy.com URL builders (no HTTP, no key)
23
26
  tests/ # pytest, mocked HTTP via respx
24
27
  ```
25
28
 
@@ -28,7 +31,7 @@ Conventions tied to this layout:
28
31
  - `src/` layout, not flat. Tests must import the installed package, not the
29
32
  working directory.
30
33
  - One file per tool in `tools/`. Auto-registered in `server.py`.
31
- - `mapy_client.py` is the only HTTP boundary. Tools never make raw `httpx`
34
+ - `mapy_api/` is the only HTTP boundary. Tools never make raw `httpx`
32
35
  calls — auth, retries, and error mapping live in one place.
33
36
  - `tests/` lives outside `src/`. Coverage targets `src/mapy_com_mcp`.
34
37
 
@@ -1,5 +1,16 @@
1
1
  # Changelog
2
2
 
3
+ ## [0.3.0](https://github.com/kostejnv/mapy-com-mcp/compare/mapy-com-mcp-v0.2.0...mapy-com-mcp-v0.3.0) (2026-10-30)
4
+
5
+
6
+ ### ⚠ BREAKING CHANGES
7
+
8
+ * **tools:** replace build_points_url with show_places ([#28](https://github.com/kostejnv/mapy-com-mcp/issues/28))
9
+
10
+ ### Features
11
+
12
+ * **tools:** replace build_points_url with show_places ([#28](https://github.com/kostejnv/mapy-com-mcp/issues/28)) ([a6770a1](https://github.com/kostejnv/mapy-com-mcp/commit/a6770a10ec651c48e9ae4ab6afbbb81c6e7d4000))
13
+
3
14
  ## [0.2.0](https://github.com/kostejnv/mapy-com-mcp/compare/mapy-com-mcp-v0.1.0...mapy-com-mcp-v0.2.0) (2026-10-29)
4
15
 
5
16
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: mapy-com-mcp
3
- Version: 0.2.0
3
+ Version: 0.3.0
4
4
  Summary: Unofficial MCP server for mapy.com. Not affiliated with, endorsed by, or supported by Seznam.cz a.s., operators of mapy.com.
5
5
  Project-URL: Homepage, https://github.com/kostejnv/mapy-com-mcp
6
6
  Project-URL: Source, https://github.com/kostejnv/mapy-com-mcp
@@ -19,15 +19,16 @@ Classifier: Programming Language :: Python :: 3.13
19
19
  Classifier: Topic :: Scientific/Engineering :: GIS
20
20
  Classifier: Topic :: Software Development :: Libraries
21
21
  Requires-Python: >=3.12
22
- Requires-Dist: fastmcp>=2.0
22
+ Requires-Dist: fastmcp>=2.8
23
23
  Requires-Dist: httpx>=0.27
24
+ Requires-Dist: pillow>=10.1
24
25
  Description-Content-Type: text/markdown
25
26
 
26
27
  <div align="center">
27
28
 
28
29
  # mapy-com-mcp
29
30
 
30
- MCP server that gives LLM clients first-class access to [mapy.com](https://mapy.com) — a Czech mapping service with strong route planning and static map rendering.
31
+ MCP server that lets LLMs find places, look at them on a real map, and hand the user a [mapy.com](https://mapy.com) link to the same view.
31
32
 
32
33
  [![PyPI version](https://img.shields.io/pypi/v/mapy-com-mcp?style=flat-square&include_prereleases)](https://pypi.org/project/mapy-com-mcp/)
33
34
  [![Python versions](https://img.shields.io/pypi/pyversions/mapy-com-mcp?style=flat-square&include_prereleases)](https://pypi.org/project/mapy-com-mcp/)
@@ -38,28 +39,33 @@ MCP server that gives LLM clients first-class access to [mapy.com](https://mapy.
38
39
  </div>
39
40
 
40
41
  > [!WARNING]
41
- > **Early preview.** URL-builder tools and the first REST-API tool (`find_places`) have shipped (see below); more REST tools and hosted deployment land in later milestones. Expect the public surface to grow.
42
+ > **Preview.** Place search, places on a map and route links work today (see below). Route planning with a map image is next, so tool names and parameters may still change.
42
43
 
43
44
  > [!NOTE]
44
45
  > **Unofficial.** Not affiliated with, endorsed by, or supported by Seznam.cz a.s., operators of mapy.com. Trademarks belong to their respective owners.
45
46
 
46
47
  ## Why
47
48
 
48
- LLMs are good at recommending places and itineraries, but bad at anything requiring real spatial understanding — distances, walkability, what's near what. This MCP closes that gap by letting LLMs surface a clickable mapy.com link the user can open to *see* the recommendation on a real map.
49
+ LLMs are good at recommending places and itineraries, but bad at anything requiring real spatial understanding — distances, walkability, what's near what. This server closes that gap from both sides:
50
+
51
+ - **The model checks its work.** With a mapy.com API key, `find_places` turns names into real coordinates, so suggestions are grounded in actual places. `show_places` then returns a map image with numbered markers and a coordinate grid, so the model can *see* how the places relate before it answers.
52
+ - **The user gets a map, not just text.** `show_places` hands the user a mapy.com link that opens the same places at the same zoom.
53
+
54
+ Built on [mapy.com](https://mapy.com), the Czech mapping service from Seznam.cz — especially strong in the Czech Republic and the surrounding region.
49
55
 
50
56
  ## Available tools
51
57
 
52
58
  | Tool | What it does | Needs API key |
53
59
  |---|---|---|
54
- | `build_points_url` | Builds a mapy.com URL that opens the map showing one or more labeled points. The general-purpose "show me on the map" tool — single place or many, the operation is the same. Auto-fits the zoom to the points. | No |
60
+ | `show_places` | Shows one or more labeled points on a map. Returns a mapy.com link for the user and — with an API key — a map image the model can look at: numbered markers and a coordinate grid for reading positions and distances. `output` picks `url`, `map` or `both`. Area and zoom are fitted to the points automatically. | Image only |
55
61
  | `build_route_url` | Builds a mapy.com URL that opens a planned route between two points (with optional waypoints). Map style is auto-derived from the chosen transport mode (car / foot / bike). | No |
56
- | `find_places` | Resolves human-readable place references (names, addresses, POIs) to WGS84 coordinates via the mapy.com REST API. Accepts a batch of queries and an optional `near` hint for disambiguation. Feed the result into `build_points_url` / `build_route_url`. | Yes |
62
+ | `find_places` | Resolves human-readable place references (names, addresses, POIs) to WGS84 coordinates via the mapy.com REST API. Accepts a batch of queries and an optional `near` hint for disambiguation. Feed the result into `show_places` / `build_route_url`. | Yes |
57
63
 
58
- URL-builder tools are pure — no HTTP calls, no key. `find_places` calls the mapy.com REST API and is only registered when `MAPY_API_KEY` is set in the environment.
64
+ Links need no key. Map images and `find_places` call the mapy.com REST API, so they are only available when `MAPY_API_KEY` is set in the environment; without it, `show_places` returns just the link.
59
65
 
60
66
  ## Configuration
61
67
 
62
- Set `MAPY_API_KEY` in the environment when you want the REST tools. Get a free key from the [mapy.com developer portal](https://developer.mapy.com/account/). With the key unset, the server runs with only the URL-builder tools.
68
+ Set `MAPY_API_KEY` in the environment when you want map images and `find_places`. Get a free key from the [mapy.com developer portal](https://developer.mapy.com/account/). With the key unset, the server still runs and returns mapy.com links.
63
69
 
64
70
  ```jsonc
65
71
  // Example: Claude Desktop / Claude Code MCP config
@@ -0,0 +1,59 @@
1
+ <div align="center">
2
+
3
+ # mapy-com-mcp
4
+
5
+ MCP server that lets LLMs find places, look at them on a real map, and hand the user a [mapy.com](https://mapy.com) link to the same view.
6
+
7
+ [![PyPI version](https://img.shields.io/pypi/v/mapy-com-mcp?style=flat-square&include_prereleases)](https://pypi.org/project/mapy-com-mcp/)
8
+ [![Python versions](https://img.shields.io/pypi/pyversions/mapy-com-mcp?style=flat-square&include_prereleases)](https://pypi.org/project/mapy-com-mcp/)
9
+ [![License: MIT](https://img.shields.io/badge/license-MIT-green?style=flat-square)](LICENSE)
10
+ [![Code style: Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json&style=flat-square)](https://github.com/astral-sh/ruff)
11
+ [![MCP-compatible](https://img.shields.io/badge/MCP-compatible-blue?style=flat-square)](https://modelcontextprotocol.io)
12
+
13
+ </div>
14
+
15
+ > [!WARNING]
16
+ > **Preview.** Place search, places on a map and route links work today (see below). Route planning with a map image is next, so tool names and parameters may still change.
17
+
18
+ > [!NOTE]
19
+ > **Unofficial.** Not affiliated with, endorsed by, or supported by Seznam.cz a.s., operators of mapy.com. Trademarks belong to their respective owners.
20
+
21
+ ## Why
22
+
23
+ LLMs are good at recommending places and itineraries, but bad at anything requiring real spatial understanding — distances, walkability, what's near what. This server closes that gap from both sides:
24
+
25
+ - **The model checks its work.** With a mapy.com API key, `find_places` turns names into real coordinates, so suggestions are grounded in actual places. `show_places` then returns a map image with numbered markers and a coordinate grid, so the model can *see* how the places relate before it answers.
26
+ - **The user gets a map, not just text.** `show_places` hands the user a mapy.com link that opens the same places at the same zoom.
27
+
28
+ Built on [mapy.com](https://mapy.com), the Czech mapping service from Seznam.cz — especially strong in the Czech Republic and the surrounding region.
29
+
30
+ ## Available tools
31
+
32
+ | Tool | What it does | Needs API key |
33
+ |---|---|---|
34
+ | `show_places` | Shows one or more labeled points on a map. Returns a mapy.com link for the user and — with an API key — a map image the model can look at: numbered markers and a coordinate grid for reading positions and distances. `output` picks `url`, `map` or `both`. Area and zoom are fitted to the points automatically. | Image only |
35
+ | `build_route_url` | Builds a mapy.com URL that opens a planned route between two points (with optional waypoints). Map style is auto-derived from the chosen transport mode (car / foot / bike). | No |
36
+ | `find_places` | Resolves human-readable place references (names, addresses, POIs) to WGS84 coordinates via the mapy.com REST API. Accepts a batch of queries and an optional `near` hint for disambiguation. Feed the result into `show_places` / `build_route_url`. | Yes |
37
+
38
+ Links need no key. Map images and `find_places` call the mapy.com REST API, so they are only available when `MAPY_API_KEY` is set in the environment; without it, `show_places` returns just the link.
39
+
40
+ ## Configuration
41
+
42
+ Set `MAPY_API_KEY` in the environment when you want map images and `find_places`. Get a free key from the [mapy.com developer portal](https://developer.mapy.com/account/). With the key unset, the server still runs and returns mapy.com links.
43
+
44
+ ```jsonc
45
+ // Example: Claude Desktop / Claude Code MCP config
46
+ {
47
+ "mcpServers": {
48
+ "mapy-com": {
49
+ "command": "uvx",
50
+ "args": ["mapy-com-mcp"],
51
+ "env": { "MAPY_API_KEY": "your-key-here" }
52
+ }
53
+ }
54
+ }
55
+ ```
56
+
57
+ ## License
58
+
59
+ MIT — see [LICENSE](LICENSE).
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "mapy-com-mcp"
7
- version = "0.2.0"
7
+ version = "0.3.0"
8
8
  description = "Unofficial MCP server for mapy.com. Not affiliated with, endorsed by, or supported by Seznam.cz a.s., operators of mapy.com."
9
9
  readme = "README.md"
10
10
  license = "MIT"
@@ -26,8 +26,9 @@ classifiers = [
26
26
  "Topic :: Software Development :: Libraries",
27
27
  ]
28
28
  dependencies = [
29
- "fastmcp>=2.0",
29
+ "fastmcp>=2.8",
30
30
  "httpx>=0.27",
31
+ "pillow>=10.1",
31
32
  ]
32
33
 
33
34
  [project.scripts]
@@ -3,7 +3,9 @@
3
3
  "packages": {
4
4
  ".": {
5
5
  "release-type": "python",
6
- "package-name": "mapy-com-mcp"
6
+ "package-name": "mapy-com-mcp",
7
+ "bump-minor-pre-major": true,
8
+ "bump-patch-for-minor-pre-major": true
7
9
  }
8
10
  }
9
11
  }
@@ -0,0 +1 @@
1
+ """Pure mapy.com URL builders — no HTTP, no API key."""
@@ -8,7 +8,8 @@ from urllib.parse import quote
8
8
  from fastmcp.exceptions import ToolError
9
9
  from pydantic import BaseModel, Field
10
10
 
11
- from ._uc_encoder import encode_uc
11
+ from ..static_map.viewport import Viewport
12
+ from .uc_encoder import encode_uc
12
13
 
13
14
  Language = Literal["en", "cs", "sk", "de", "pl"]
14
15
  PointsMapset = Literal["outdoor", "traffic", "winter", "aerial", "basic"]
@@ -55,52 +56,28 @@ class Point(BaseModel):
55
56
  )
56
57
 
57
58
 
58
- def _auto_fit_zoom(points: list[Point]) -> int:
59
- """Pick a zoom level that fits all points with margin.
60
-
61
- Single point falls back to 13 (neighborhood-level), the default for
62
- 'show me where this is'. Multiple points use the larger of lon/lat
63
- bounding-box span to drop into the right zoom bucket.
64
- """
65
- if len(points) == 1:
66
- return 13
67
- lon_span = max(p.lon for p in points) - min(p.lon for p in points)
68
- lat_span = max(p.lat for p in points) - min(p.lat for p in points)
69
- span = max(lon_span, lat_span)
70
- if span > 20:
71
- return 5
72
- if span > 5:
73
- return 8
74
- if span > 1:
75
- return 11
76
- if span > 0.1:
77
- return 13
78
- if span > 0.02:
79
- return 15
80
- if span > 0.005:
81
- return 17
82
- return 19
83
-
84
-
85
59
  def build_points_url(
86
60
  points: list[Point],
61
+ viewport: Viewport,
87
62
  mapset: PointsMapset = "outdoor",
88
63
  language: Language = "en",
89
64
  ) -> str:
90
65
  """Compose a mapy.com URL that opens the map showing labeled points.
91
66
 
92
- Pure function — no HTTP, no API key. Map zoom is chosen automatically
93
- so all points fit. Raises ToolError on empty input.
67
+ Pure function — no HTTP, no API key. Center and zoom come from
68
+ `viewport`, the same one the static map image uses. Raises ToolError on
69
+ empty input.
94
70
  """
95
71
  if not points:
96
72
  raise ToolError("points must contain at least one point.")
97
73
  if len(points) == 1:
98
- return _build_single_point_url(points[0], mapset, language)
99
- return _build_multi_point_url(points, mapset, language)
74
+ return _build_single_point_url(points[0], viewport, mapset, language)
75
+ return _build_multi_point_url(points, viewport, mapset, language)
100
76
 
101
77
 
102
78
  def _build_single_point_url(
103
79
  point: Point,
80
+ viewport: Viewport,
104
81
  mapset: PointsMapset,
105
82
  language: Language,
106
83
  ) -> str:
@@ -111,9 +88,11 @@ def _build_single_point_url(
111
88
  `point.description` are not rendered — they still serve as inputs the
112
89
  LLM is forced to think about.
113
90
  """
91
+ # showmap draws its marker at the map center, so center stays on the
92
+ # point; only the zoom comes from the shared viewport.
114
93
  parts = [
115
94
  f"center={point.lon},{point.lat}",
116
- f"zoom={_auto_fit_zoom([point])}",
95
+ f"zoom={viewport.zoom}",
117
96
  "marker=true",
118
97
  f"mapset={mapset}",
119
98
  f"lang={language}",
@@ -123,28 +102,27 @@ def _build_single_point_url(
123
102
 
124
103
  def _build_multi_point_url(
125
104
  points: list[Point],
105
+ viewport: Viewport,
126
106
  mapset: PointsMapset,
127
107
  language: Language,
128
108
  ) -> str:
129
109
  """Compose the legacy `vlastni-body` URL for two or more points.
130
110
 
131
111
  Undocumented but the only mapy.com URL pattern that renders multiple
132
- custom markers with labels and descriptions.
112
+ custom markers with labels and descriptions. Marker titles are numbered
113
+ to match the markers in the static map image.
133
114
  """
134
- center_lon = round(sum(p.lon for p in points) / len(points), 6)
135
- center_lat = round(sum(p.lat for p in points) / len(points), 6)
136
- zoom = _auto_fit_zoom(points)
137
115
  uc = encode_uc([(p.lon, p.lat) for p in points])
138
116
 
139
117
  parts: list[str] = ["vlastni-body"]
140
- for p in points:
141
- parts.append("ut=" + quote(p.label))
118
+ for number, p in enumerate(points, start=1):
119
+ parts.append("ut=" + quote(f"{number}. {p.label}"))
142
120
  parts.append("uc=" + quote(uc))
143
121
  for p in points:
144
122
  parts.append("ud=" + quote(p.description or ""))
145
- parts.append(f"x={center_lon}")
146
- parts.append(f"y={center_lat}")
147
- parts.append(f"z={zoom}")
123
+ parts.append(f"x={round(viewport.center_lon, 6)}")
124
+ parts.append(f"y={round(viewport.center_lat, 6)}")
125
+ parts.append(f"z={viewport.zoom}")
148
126
  return f"https://mapy.com/{language}/{_LEGACY_PATH[mapset]}?" + "&".join(parts)
149
127
 
150
128
 
@@ -0,0 +1 @@
1
+ """Everything that talks to the mapy.com REST API — the only HTTP boundary."""
@@ -7,7 +7,7 @@ call httpx directly — auth, timeouts, error mapping live here.
7
7
  from __future__ import annotations
8
8
 
9
9
  from importlib.metadata import PackageNotFoundError, version
10
- from typing import Any
10
+ from typing import Any, Literal
11
11
 
12
12
  import httpx
13
13
 
@@ -16,6 +16,8 @@ from .geocoding import GeocodeMatch
16
16
  _DEFAULT_BASE_URL = "https://api.mapy.com"
17
17
  _DEFAULT_TIMEOUT_SECONDS = 10.0
18
18
 
19
+ StaticMapset = Literal["basic", "outdoor", "winter", "aerial"]
20
+
19
21
 
20
22
  def _get_user_agent() -> str:
21
23
  try:
@@ -89,6 +91,45 @@ class MapyClient:
89
91
 
90
92
  return [_parse_match(item) for item in resp.json().get("items", [])]
91
93
 
94
+ async def static_map(
95
+ self,
96
+ *,
97
+ lon: float,
98
+ lat: float,
99
+ zoom: int,
100
+ width: int,
101
+ height: int,
102
+ mapset: StaticMapset,
103
+ lang: str,
104
+ ) -> bytes:
105
+ """Fetch a PNG map image centered on (lon, lat) at the given zoom.
106
+
107
+ Raises MapyAPIError on 4xx/5xx responses. httpx exceptions (timeout,
108
+ connection error) propagate to the caller.
109
+ """
110
+ params: dict[str, Any] = {
111
+ "apikey": self._api_key,
112
+ "lon": lon,
113
+ "lat": lat,
114
+ "zoom": zoom,
115
+ "width": width,
116
+ "height": height,
117
+ "mapset": mapset,
118
+ "lang": lang,
119
+ "format": "png",
120
+ }
121
+
122
+ resp = await self._client.get("/v1/static/map", params=params)
123
+
124
+ if resp.status_code in (401, 403):
125
+ raise MapyAPIError(resp.status_code, "API key invalid or unauthorized")
126
+ if resp.status_code >= 500:
127
+ raise MapyAPIError(resp.status_code, "mapy.com static map service error")
128
+ if resp.status_code >= 400:
129
+ raise MapyAPIError(resp.status_code, resp.text[:200])
130
+
131
+ return resp.content
132
+
92
133
  async def aclose(self) -> None:
93
134
  await self._client.aclose()
94
135
 
@@ -1,6 +1,6 @@
1
1
  """Pydantic models for the mapy.com forward-geocoding API.
2
2
 
3
- Used by both `mapy_client.MapyClient.geocode` and the `find_places` tool.
3
+ Used by both `mapy_api.client.MapyClient.geocode` and the `find_places` tool.
4
4
  Field descriptions are written for LLM consumption — FastMCP surfaces them
5
5
  in the tool schema.
6
6
  """
@@ -48,7 +48,7 @@ class GeocodeMatch(BaseModel):
48
48
  description=(
49
49
  "Matched entity name as returned by mapy.com (e.g. 'Karlův most', "
50
50
  "'Týnská ulička 610/7'). Suitable as a marker label when feeding "
51
- "into build_points_url."
51
+ "into show_places."
52
52
  ),
53
53
  )
54
54
  label: str = Field(
@@ -10,23 +10,23 @@ from contextlib import AbstractAsyncContextManager, asynccontextmanager
10
10
  from fastmcp import FastMCP
11
11
 
12
12
  from . import tools
13
- from .mapy_client import MapyClient
13
+ from .mapy_api.client import MapyClient
14
14
 
15
15
  _LOG = logging.getLogger(__name__)
16
16
 
17
17
  _BASE_INSTRUCTIONS = (
18
18
  "First-class access to mapy.com, the Czech mapping service from "
19
- "Seznam.cz. URL-builder tools compose mapy.com links the user can "
20
- "click — show one or more points on a map, or plan a route between "
21
- "two locations. Use these whenever the user asks to see a place on a "
22
- "map or get directions, especially in the Czech Republic and "
23
- "surrounding region."
19
+ "Seznam.cz. show_places puts one or more points on a map and "
20
+ "build_route_url plans a route between two locations; both give the "
21
+ "user a mapy.com link to click. Use these whenever the user asks to "
22
+ "see a place on a map or get directions, especially in the Czech "
23
+ "Republic and surrounding region."
24
24
  )
25
25
  _HTTP_INSTRUCTIONS = (
26
- " When MAPY_API_KEY is configured, the server also exposes a "
27
- "find_places tool that resolves human-readable place names to "
28
- "coordinates via the mapy.com REST API — feed its output into the "
29
- "URL-builder tools."
26
+ " When MAPY_API_KEY is configured, show_places also returns a map "
27
+ "image with numbered markers and a coordinate grid so you can see "
28
+ "where places are, and a find_places tool resolves human-readable "
29
+ "place names to coordinates — feed its output into the map tools."
30
30
  )
31
31
 
32
32
 
@@ -34,7 +34,7 @@ def create_app() -> FastMCP:
34
34
  api_key = os.environ.get("MAPY_API_KEY")
35
35
  client = MapyClient(api_key) if api_key else None
36
36
  if client is None:
37
- _LOG.info("MAPY_API_KEY not set; HTTP-backed tools will not be registered.")
37
+ _LOG.info("MAPY_API_KEY not set; map images and find_places are unavailable.")
38
38
 
39
39
  mcp = FastMCP(
40
40
  "mapy-com-mcp",
@@ -0,0 +1 @@
1
+ """Static map viewport and rendering — no HTTP, the image bytes come in."""
@@ -0,0 +1,179 @@
1
+ """Draw the coordinate grid and numbered markers onto a static map image.
2
+
3
+ The grid lets the model read coordinates and distances straight off the
4
+ picture. Markers are drawn here, above the grid, rather than by mapy.com,
5
+ whose markers would end up underneath the grid lines.
6
+ """
7
+
8
+ from __future__ import annotations
9
+
10
+ import io
11
+ import math
12
+
13
+ from PIL import Image, ImageDraw, ImageFont
14
+
15
+ from .viewport import Viewport
16
+
17
+ _METERS_PER_DEG_LAT = 111_320.0
18
+ _JPEG_QUALITY = 85
19
+
20
+ _GRID_STEP_MULTIPLIERS = (1, 2, 3, 5)
21
+ _TARGET_GRID_LINES = 6
22
+ _MAX_GRID_LINES = 7
23
+ _GRID_COLOR = (0, 0, 0, 200)
24
+ _GRID_WIDTH = 3
25
+ # A white halo keeps the black line visible on dark aerial imagery.
26
+ _HALO_COLOR = (255, 255, 255, 160)
27
+ _HALO_WIDTH = 5
28
+
29
+ _LABEL_W_PX, _LABEL_H_PX = 60, 18
30
+ _FOOTER_H_PX = 28 # mapy.com logo and attribution — must stay visible
31
+
32
+ _MARKER_COLOR = (215, 25, 32, 255)
33
+ _MARKER_RADIUS_PX = 14
34
+ _MARKER_SUPERSAMPLE = 4 # smooth edges
35
+
36
+
37
+ def format_distance(meters: float) -> str:
38
+ return f"{meters / 1000:g} km" if meters >= 1000 else f"{round(meters)} m"
39
+
40
+
41
+ def grid_step_m(viewport: Viewport) -> float:
42
+ """Round step (1/2/3/5 x 10^n m) giving ~6 lines on the longer side."""
43
+ span_m = max(viewport.width, viewport.height) * viewport.meters_per_px
44
+ candidates = [
45
+ mult * 10**exponent
46
+ for exponent in range(8)
47
+ for mult in _GRID_STEP_MULTIPLIERS
48
+ if 3 <= span_m // (mult * 10**exponent) <= _MAX_GRID_LINES
49
+ ]
50
+ return min(candidates, key=lambda step: abs(span_m // step - _TARGET_GRID_LINES))
51
+
52
+
53
+ def render(
54
+ base_image: bytes, viewport: Viewport, points: list[tuple[float, float]]
55
+ ) -> bytes:
56
+ """Overlay grid, legend and numbered markers; return JPEG bytes."""
57
+ img = Image.open(io.BytesIO(base_image)).convert("RGBA")
58
+ img = _draw_grid(img, viewport)
59
+ for number, (lon, lat) in enumerate(points, start=1):
60
+ _draw_marker(img, viewport.to_pixel(lon, lat), str(number))
61
+ buf = io.BytesIO()
62
+ img.convert("RGB").save(buf, format="JPEG", quality=_JPEG_QUALITY)
63
+ return buf.getvalue()
64
+
65
+
66
+ def _draw_grid(img: Image.Image, viewport: Viewport) -> Image.Image:
67
+ w, h = img.size
68
+ step_m = grid_step_m(viewport)
69
+ m_per_px = viewport.meters_per_px
70
+ # Enough decimals that neighbouring lines get distinct labels.
71
+ decimals = max(2, min(6, math.ceil(-math.log10(step_m / _METERS_PER_DEG_LAT)) + 1))
72
+ font = ImageFont.load_default(size=12)
73
+
74
+ # Separate layers so each line composites over its halo instead of
75
+ # replacing it: halo → line → labels.
76
+ halo, lines, labels = (Image.new("RGBA", (w, h), (0, 0, 0, 0)) for _ in range(3))
77
+ halo_draw, line_draw, label_draw = (
78
+ ImageDraw.Draw(layer) for layer in (halo, lines, labels)
79
+ )
80
+
81
+ def grid_line(start: tuple[int, int], end: tuple[int, int]) -> None:
82
+ halo_draw.line([start, end], fill=_HALO_COLOR, width=_HALO_WIDTH)
83
+ line_draw.line([start, end], fill=_GRID_COLOR, width=_GRID_WIDTH)
84
+
85
+ # The grid stops above the footer so the logo and attribution stay clear.
86
+ grid_bottom = h - _FOOTER_H_PX
87
+
88
+ # Vertical lines: metric offsets along the center parallel.
89
+ k_max = math.ceil(w / 2 * m_per_px / step_m)
90
+ for k in range(-k_max, k_max + 1):
91
+ x = round(w / 2 + k * step_m / m_per_px)
92
+ if not 0 <= x < w:
93
+ continue
94
+ grid_line((x, 0), (x, grid_bottom))
95
+ lon, _ = viewport.to_lon_lat(x, h / 2)
96
+ label_x = max(2, min(w - _LABEL_W_PX - 2, x - _LABEL_W_PX // 2))
97
+ _draw_label(label_draw, (label_x, 2), f"{lon:.{decimals}f}", font)
98
+
99
+ # Horizontal lines: metric offsets along the meridian give latitudes
100
+ # (linear on the ground); Mercator then places them, unevenly spaced.
101
+ k_max = math.ceil(h * m_per_px / step_m)
102
+ for k in range(-k_max, k_max + 1):
103
+ lat = viewport.center_lat + k * step_m / _METERS_PER_DEG_LAT
104
+ if not -85 < lat < 85:
105
+ continue
106
+ y = round(viewport.to_pixel(viewport.center_lon, lat)[1])
107
+ if not 0 <= y < grid_bottom:
108
+ continue
109
+ grid_line((0, y), (w - 1, y))
110
+ lowest = grid_bottom - _LABEL_H_PX
111
+ label_y = max(_LABEL_H_PX + 4, min(lowest, y - _LABEL_H_PX // 2))
112
+ _draw_label(label_draw, (2, label_y), f"{lat:.{decimals}f}", font)
113
+
114
+ _draw_legend(label_draw, (w, h), f"grid {format_distance(step_m)}")
115
+
116
+ for layer in (halo, lines, labels):
117
+ img = Image.alpha_composite(img, layer)
118
+ return img
119
+
120
+
121
+ def _draw_label(
122
+ draw: ImageDraw.ImageDraw,
123
+ xy: tuple[int, int],
124
+ text: str,
125
+ font: ImageFont.FreeTypeFont | ImageFont.ImageFont,
126
+ ) -> None:
127
+ x, y = xy
128
+ draw.rectangle((x, y, x + _LABEL_W_PX, y + _LABEL_H_PX), fill=(255, 255, 255, 220))
129
+ draw.text((x + 4, y + 3), text, fill="black", font=font)
130
+
131
+
132
+ def _draw_legend(draw: ImageDraw.ImageDraw, size: tuple[int, int], text: str) -> None:
133
+ w, h = size
134
+ font = ImageFont.load_default(size=16)
135
+ box_w = int(draw.textlength(text, font=font)) + 16
136
+ top = h - _FOOTER_H_PX - 30
137
+ draw.rectangle(
138
+ (w - box_w - 6, top, w - 6, top + 26), fill=(20, 20, 20, 235), outline="white"
139
+ )
140
+ draw.text((w - box_w + 2, top + 4), text, fill="white", font=font)
141
+
142
+
143
+ def _draw_marker(img: Image.Image, tip: tuple[float, float], label: str) -> None:
144
+ """Red pin with a white number and outline, its tip on the point."""
145
+ ss = _MARKER_SUPERSAMPLE
146
+ r = _MARKER_RADIUS_PX * ss
147
+ w, h = 2 * r + 4 * ss, 2 * r + 22 * ss
148
+ sprite = Image.new("RGBA", (w, h), (0, 0, 0, 0))
149
+ draw = ImageDraw.Draw(sprite)
150
+ cx, cy = w / 2, r + 2 * ss
151
+ # White outline first (slightly bigger), then the red body on top.
152
+ for grow, color, tip_y in (
153
+ (2 * ss, (255, 255, 255, 255), h - 1),
154
+ (0, _MARKER_COLOR, h - 1 - 2 * ss),
155
+ ):
156
+ draw.ellipse(
157
+ (cx - r - grow, cy - r - grow, cx + r + grow, cy + r + grow), fill=color
158
+ )
159
+ draw.polygon(
160
+ [
161
+ (cx - r * 0.7 - grow, cy + r * 0.6),
162
+ (cx + r * 0.7 + grow, cy + r * 0.6),
163
+ (cx, tip_y),
164
+ ],
165
+ fill=color,
166
+ )
167
+ draw.text(
168
+ (cx, cy),
169
+ label,
170
+ fill="white",
171
+ font=ImageFont.load_default(size=16 * ss),
172
+ anchor="mm",
173
+ )
174
+ sprite = sprite.reduce(ss)
175
+ img.paste(
176
+ sprite,
177
+ (round(tip[0] - sprite.width / 2), round(tip[1] - sprite.height)),
178
+ sprite,
179
+ )