Skip to main content
Glama
mahdin75

GeoServer MCP Server

create_layer

Add a new layer to GeoServer by specifying workspace, layer name, data store, and source. Integrates with AI assistants for geospatial data management via natural language commands.

Instructions

Create a new layer in GeoServer.

Args: workspace: The workspace for the new layer layer: The name of the layer to create data_store: The data store to use source: The source data (file, table name, etc.) Returns: Dict with status and layer information

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
data_storeYes
layerYes
sourceYes
workspaceYes

Implementation Reference

  • The handler function implementing the 'create_layer' tool logic. It validates parameters, connects to GeoServer, calls the underlying Geoserver.create_layer method, handles errors, and returns a status dictionary.
    def create_layer(workspace: str, layer: str, data_store: str, source: str) -> Dict[str, Any]: """Create a new layer in GeoServer. Args: workspace: The workspace for the new layer layer: The name of the layer to create data_store: The data store to use source: The source data (file, table name, etc.) Returns: Dict with status and layer information """ geo = get_geoserver() if geo is None: raise ValueError("Not connected to GeoServer") if not workspace or not layer or not data_store: raise ValueError("Workspace, layer name, and data store are required") try: # Use the actual GeoServer REST API to create a layer geo.create_layer(layer, workspace, data_store, source) return { "status": "success", "name": layer, "workspace": workspace, "data_store": data_store, "source": source, "message": f"Layer '{layer}' created successfully in workspace '{workspace}'" } except Exception as e: logger.error(f"Error creating layer: {str(e)}") raise ValueError(f"Failed to create layer: {str(e)}")
  • The @mcp.tool() decorator registers the create_layer function as an MCP tool.
    @mcp.tool()
  • Helper function to initialize and return the GeoServer connection instance, used by the create_layer handler.
    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
  • Input parameters and return type defined in function signature and docstring, serving as the tool schema.
    def create_layer(workspace: str, layer: str, data_store: str, source: str) -> Dict[str, Any]: """Create a new layer in GeoServer. Args: workspace: The workspace for the new layer layer: The name of the layer to create data_store: The data store to use source: The source data (file, table name, etc.) Returns: Dict with status and layer information """

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