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
| Name | Required | Description | Default |
|---|---|---|---|
| data_store | Yes | ||
| layer | Yes | ||
| source | Yes | ||
| workspace | Yes |
Implementation Reference
- src/geoserver_mcp/main.py:225-259 (handler)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)}")
- src/geoserver_mcp/main.py:224-224 (registration)The @mcp.tool() decorator registers the create_layer function as an MCP tool.@mcp.tool()
- src/geoserver_mcp/main.py:32-45 (helper)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
- src/geoserver_mcp/main.py:225-236 (schema)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 """