Skip to main content
Glama
JLKmach

ServiceNow MCP Server

by JLKmach

commit_changeset

Commit a changeset in ServiceNow to finalize and apply configuration changes or updates to the platform.

Instructions

Commit a changeset in ServiceNow

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
changeset_idYesChangeset ID or sys_id
commit_messageNoCommit message

Implementation Reference

  • The main handler function that executes the commit_changeset tool. It validates input parameters, prepares the API request to set the changeset state to 'complete', sends a PATCH request to ServiceNow, and returns success or error response.
    def commit_changeset( auth_manager: AuthManager, server_config: ServerConfig, params: Union[Dict[str, Any], CommitChangesetParams], ) -> Dict[str, Any]: """ Commit a changeset in ServiceNow. Args: auth_manager: The authentication manager. server_config: The server configuration. params: The parameters for committing a changeset. Can be a dictionary or a CommitChangesetParams object. Returns: The committed changeset. """ # Unwrap and validate parameters result = _unwrap_and_validate_params( params, CommitChangesetParams, required_fields=["changeset_id"] ) if not result["success"]: return result validated_params = result["params"] # Prepare the request data data = { "state": "complete", } # Add commit message if provided if validated_params.commit_message: data["description"] = validated_params.commit_message # 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" # 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 committed successfully", "changeset": result["result"], } except requests.exceptions.RequestException as e: logger.error(f"Error committing changeset: {e}") return { "success": False, "message": f"Error committing changeset: {str(e)}", }
  • Pydantic BaseModel defining the input schema for the commit_changeset tool, with required 'changeset_id' and optional 'commit_message'.
    class CommitChangesetParams(BaseModel): """Parameters for committing a changeset.""" changeset_id: str = Field(..., description="Changeset ID or sys_id") commit_message: Optional[str] = Field(None, description="Commit message")
  • Tool registration in the central get_tool_definitions() function, mapping the tool name to its handler, schema, return type, description, and serialization method.
    "commit_changeset": ( commit_changeset_tool, CommitChangesetParams, str, "Commit a changeset in ServiceNow", "str", # Tool returns simple message ),
  • Import of the commit_changeset handler into the tools package __init__.py, making it available for export.
    from servicenow_mcp.tools.changeset_tools import ( add_file_to_changeset, commit_changeset, create_changeset, get_changeset_details, list_changesets, publish_changeset, update_changeset, )
  • Shared helper function used by the handler (and other tools) to unwrap dictionary or Pydantic model parameters, validate against the schema, and check required fields.
    def _unwrap_and_validate_params( params: Union[Dict[str, Any], BaseModel], model_class: Type[T], required_fields: Optional[List[str]] = None ) -> Dict[str, Any]: """ Unwrap and validate parameters. Args: params: The parameters to unwrap and validate. Can be a dictionary or a Pydantic model. model_class: The Pydantic model class to validate against. required_fields: List of fields that must be present. Returns: A dictionary with success status and validated parameters or error message. """ try: # Handle case where params is already a Pydantic model if isinstance(params, BaseModel): # If it's already the correct model class, use it directly if isinstance(params, model_class): model_instance = params # Otherwise, convert to dict and create new instance else: model_instance = model_class(**params.dict()) # Handle dictionary case else: # Create model instance model_instance = model_class(**params) # Check required fields if required_fields: missing_fields = [] for field in required_fields: if getattr(model_instance, field, None) is None: missing_fields.append(field) if missing_fields: return { "success": False, "message": f"Missing required fields: {', '.join(missing_fields)}", } return { "success": True, "params": model_instance, } except Exception as e: return { "success": False, "message": f"Invalid parameters: {str(e)}", }

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/JLKmach/servicenow-mcp'

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