Skip to main content
Glama
mahdin75

GeoServer MCP Server

get_layer_info

Retrieve comprehensive metadata for a specific layer in GeoServer by providing the workspace and layer name. Returns a dictionary with detailed layer information for analysis or integration.

Instructions

Get detailed information about a layer.

Args:
    workspace: The workspace containing the layer
    layer: The name of the layer

Returns:
    Dict with layer metadata

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
layerYes
workspaceYes

Implementation Reference

  • The primary handler function implementing the logic for the 'get_layer_info' tool. It connects to GeoServer, validates inputs, and fetches layer metadata using the Geoserver client library.
    @mcp.tool()
    def get_layer_info(workspace: str, layer: str) -> Dict[str, Any]:
        """Get detailed information about a layer.
        
        Args:
            workspace: The workspace containing the layer
            layer: The name of the layer
        
        Returns:
            Dict with layer metadata
        """
        geo = get_geoserver()
        if geo is None:
            raise ValueError("Not connected to GeoServer")
        
        if not workspace or not layer:
            raise ValueError("Both workspace and layer name are required")
        
        try:
            # Use the actual GeoServer REST API to get layer information
            layer_info = geo.get_layer(layer, workspace)
            return layer_info
        except Exception as e:
            logger.error(f"Error getting layer info: {str(e)}")
            raise ValueError(f"Failed to get layer info: {str(e)}")
  • Helper utility function that initializes and returns the GeoServer client connection, used by the get_layer_info handler and other tools.
    def get_geoserver():
        """Get the GeoServer connection using environment variables or command-line arguments."""
        url = os.environ.get("GEOSERVER_URL", "http://localhost:8080/geoserver")
        username = os.environ.get("GEOSERVER_USER", "admin")
        password = os.environ.get("GEOSERVER_PASSWORD", "geoserver")
        
        try:
            geo = Geoserver(url, username=username, password=password)
            logger.info(f"Connected to GeoServer at {url}")
            return geo
        except Exception as e:
            logger.error(f"Failed to connect to GeoServer: {str(e)}")
            return None
  • The @mcp.tool() decorator registers the get_layer_info function as an MCP tool.
    @mcp.tool()
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