Skip to main content
Glama
mahdin75

GeoServer MCP Server

generate_map

Create custom map images by specifying layers, styles, bounding box, dimensions, and format using WMS GetMap functionality in the GeoServer MCP Server.

Instructions

Generate a map image using WMS GetMap.

Args:
    layers: List of layers to include (format: workspace:layer)
    styles: Optional styles to apply (one per layer)
    bbox: Bounding box [minx, miny, maxx, maxy]
    width: Image width in pixels
    height: Image height in pixels
    format: Image format (png, jpeg, etc.)

Returns:
    Dict with map information and URL

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
bboxNo
formatNopng
heightNo
layersYes
stylesNo
widthNo

Implementation Reference

  • The core handler function for the 'generate_map' MCP tool. Decorated with @mcp.tool() for registration. Constructs a WMS GetMap request URL using the provided layers, styles, bounding box, and rendering parameters, returning a dictionary with the map URL and parameters.
    @mcp.tool()
    def generate_map(
        layers: List[str],
        styles: Optional[List[str]] = None,
        bbox: Optional[List[float]] = None,
        width: int = 800,
        height: int = 600,
        format: str = "png"
    ) -> Dict[str, Any]:
        """Generate a map image using WMS GetMap.
        
        Args:
            layers: List of layers to include (format: workspace:layer)
            styles: Optional styles to apply (one per layer)
            bbox: Bounding box [minx, miny, maxx, maxy]
            width: Image width in pixels
            height: Image height in pixels
            format: Image format (png, jpeg, etc.)
        
        Returns:
            Dict with map information and URL
        """
        geo = get_geoserver()
        if geo is None:
            raise ValueError("Not connected to GeoServer")
        
        if not layers:
            raise ValueError("At least one layer must be specified")
        
        # Validate parameters
        if styles and len(styles) != len(layers):
            raise ValueError("Number of styles must match number of layers")
        
        if not bbox:
            bbox = [-180, -90, 180, 90]  # Default to global extent
        
        if len(bbox) != 4:
            raise ValueError("Bounding box must have 4 coordinates: [minx, miny, maxx, maxy]")
        
        # Valid formats
        valid_formats = ["png", "jpeg", "gif", "tiff", "pdf"]
        if format.lower() not in valid_formats:
            raise ValueError(f"Invalid format. Must be one of: {', '.join(valid_formats)}")
        
        try:
            # Construct WMS GetMap URL
            url = f"{geo.service_url}/wms"
            params = {
                "service": "WMS",
                "version": "1.3.0",
                "request": "GetMap",
                "format": f"image/{format}",
                "layers": ",".join(layers),
                "width": width,
                "height": height,
                "crs": "EPSG:4326",
                "bbox": ",".join(map(str, bbox))
            }
            
            # Add styles if provided
            if styles:
                params["styles"] = ",".join(styles)
                
            # Construct the full URL
            import urllib.parse
            query_string = urllib.parse.urlencode(params)
            map_url = f"{url}?{query_string}"
            
            return {
                "url": map_url,
                "width": width,
                "height": height,
                "format": format,
                "layers": layers,
                "styles": styles,
                "bbox": bbox
            }
        except Exception as e:
            logger.error(f"Error generating map: {str(e)}")
            raise ValueError(f"Failed to generate map: {str(e)}")
Install Server

Other Tools

Related Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/mahdin75/geoserver-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server