publish_changeset
Publish a changeset in ServiceNow by specifying the changeset ID and optional notes to update and deploy changes effectively.
Instructions
Publish a changeset in ServiceNow
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| changeset_id | Yes | Changeset ID or sys_id | |
| publish_notes | No | Notes for publishing |
Implementation Reference
- Core handler function that validates parameters, constructs the ServiceNow API request to update the changeset state to 'published', handles the PATCH request, and returns success/error responses.def publish_changeset( auth_manager: AuthManager, server_config: ServerConfig, params: Union[Dict[str, Any], PublishChangesetParams], ) -> Dict[str, Any]: """ Publish a changeset in ServiceNow. Args: auth_manager: The authentication manager. server_config: The server configuration. params: The parameters for publishing a changeset. Can be a dictionary or a PublishChangesetParams object. Returns: The published changeset. """ # Unwrap and validate parameters result = _unwrap_and_validate_params( params, PublishChangesetParams, required_fields=["changeset_id"] ) if not result["success"]: return result validated_params = result["params"] # Get the instance URL instance_url = _get_instance_url(auth_manager, server_config) if not instance_url: return { "success": False, "message": "Cannot find instance_url in either server_config or auth_manager", } # Get the headers headers = _get_headers(auth_manager, server_config) if not headers: return { "success": False, "message": "Cannot find get_headers method in either auth_manager or server_config", } # Add Content-Type header headers["Content-Type"] = "application/json" # Prepare the request data for the publish action data = { "state": "published", } # Add publish notes if provided if validated_params.publish_notes: data["description"] = validated_params.publish_notes # Make the API request url = f"{instance_url}/api/now/table/sys_update_set/{validated_params.changeset_id}" try: response = requests.patch(url, json=data, headers=headers) response.raise_for_status() result = response.json() return { "success": True, "message": "Changeset published successfully", "changeset": result["result"], } except requests.exceptions.RequestException as e: logger.error(f"Error publishing changeset: {e}") return { "success": False, "message": f"Error publishing changeset: {str(e)}", }
- Pydantic model defining the input schema for the publish_changeset tool, including required changeset_id and optional publish_notes.class PublishChangesetParams(BaseModel): """Parameters for publishing a changeset.""" changeset_id: str = Field(..., description="Changeset ID or sys_id") publish_notes: Optional[str] = Field(None, description="Notes for publishing")
- src/servicenow_mcp/utils/tool_utils.py:610-616 (registration)Registers the 'publish_changeset' tool in the tool definitions dictionary used by the MCP server, specifying the aliased handler function, input schema, return type, description, and serialization method."publish_changeset": ( publish_changeset_tool, PublishChangesetParams, str, "Publish a changeset in ServiceNow", "str", # Tool returns simple message ),
- src/servicenow_mcp/tools/__init__.py:39-40 (registration)Imports the publish_changeset function from changeset_tools.py, making it available for use and export via __all__.publish_changeset, update_changeset,
- Alias import of the publish_changeset handler as publish_changeset_tool for use in tool registration.publish_changeset as publish_changeset_tool, )