pymviewer¶
pymviewer generates mviewer XML configuration files from QGIS Server
projects and WMS GetCapabilities documents.
Install¶
python -m pip install pymviewer
For local development:
python -m pip install -e .
CLI¶
Generate from a QGIS project:
pymviewer from-qgs \
--project /path/to/project.qgs \
--output /path/to/config.xml \
--service-url http://localhost:90/ogc/data
Generate from a WMS GetCapabilities file:
pymviewer from-capabilities \
--capabilities /path/to/GetCapabilities.xml \
--output /path/to/config.xml \
--service-url http://localhost:90/ogc/data
Python API¶
from pathlib import Path
from pymviewer.qgisxmviewer import create_mviewer_config_from_wms_capabilities
create_mviewer_config_from_wms_capabilities(
Path("data_getcapabilities.xml"),
Path("data.xml"),
"http://localhost:90/ogc/data",
)
How to use it with an MCP?¶
pymviewer now ships a dedicated tool-friendly API in
tools.python. It is designed for MCP usage: string inputs,
serializable outputs, optional inline XML, and plain dictionaries for layer
inspection.
Available entry points:
generate_mviewer_from_qgs_toolgenerate_mviewer_from_capabilities_toolinspect_qgs_layers_toolinspect_wms_capabilities_tool
Example:
from tools.python import (
generate_mviewer_from_capabilities_tool,
generate_mviewer_from_qgs_tool,
inspect_qgs_layers_tool,
inspect_wms_capabilities_tool,
)
result = generate_mviewer_from_qgs_tool(
project_path="/data/project.qgs",
service_url="http://localhost:90/ogc/data",
)
inspection = inspect_wms_capabilities_tool("/data/GetCapabilities.xml")
When output_path is omitted, generation tools return inline XML:
{
"mode": "inline",
"project_path": "/data/project.qgs",
"service_url": "http://localhost:90/ogc/data",
"xml": "<?xml version='1.0' ...",
}
When output_path is provided, they return the generated file path:
{
"mode": "file",
"output_path": "/tmp/config.xml",
}
Recommended MCP exposure:
- one tool for
.qgsto mviewer XML generation; - one tool for WMS GetCapabilities to mviewer XML generation;
- optional read-only tools for inspecting layers before generating XML.
Practical notes:
- return file paths or XML content as plain strings;
- let
pymviewerraise explicit errors instead of swallowing exceptions; - keep file-system paths configurable from the MCP layer;
- avoid coupling the conversion logic to the transport layer.
Publish library¶
The repository publishes the package to PyPI from GitHub Actions when a GitHub release is published.
PyPI project page: https://pypi.org/project/pymviewer/
Prerequisites¶
- The workflow file is
.github/workflows/publish-pypi.yml. - PyPI Trusted Publishing must be configured for this GitHub repository.
- The version in
pyproject.tomlis used as the base version. - The workflow publishes a derived version in the form
X.Y.Z.post<GITHUB_RUN_NUMBER>to guarantee uniqueness on PyPI. - Build-time tooling is listed in
requirements.txt.
Local build check¶
Before creating a release, build the package locally:
python -m pip install --upgrade pip
python -m pip install -r requirements.txt
python -m build
This produces the source distribution and wheel in dist/.
Release flow¶
- Update
versioninpyproject.tomlif needed. - Commit and push the changes to GitHub.
- Create a GitHub release from the tag you want to publish.
- Publish the release in the GitHub UI.
- GitHub Actions builds the package and uploads it to PyPI automatically.
What the workflow does¶
At release publication time, GitHub Actions:
- checks out the repository;
- installs Python 3.12 and the
buildpackage; - rewrites
pyproject.tomltemporarily to append.post<GITHUB_RUN_NUMBER>to the configured version; - runs
python -m build; - publishes the generated artifacts to PyPI with
pypa/gh-action-pypi-publish.
Build docs¶
Build and documentation dependencies are centralized in requirements.txt.
Install the documentation and build dependencies:
python -m pip install --upgrade pip
python -m pip install -r requirements.txt
The shared requirements.txt currently includes build, mkdocs-material,
and black.
Format the codebase with:
black .
Run the local documentation server:
mkdocs serve
Build the static site:
mkdocs build