Skip to main content
Glama
javerthl

ServiceNow MCP Server

by javerthl

create_changeset

Create a new changeset in ServiceNow to organize and track application modifications, requiring a name and application identifier for configuration management.

Instructions

Create a new changeset in ServiceNow

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
applicationYesApplication the changeset belongs to
descriptionNoDescription of the changeset
developerNoDeveloper responsible for the changeset
nameYesName of the changeset

Implementation Reference

  • Main handler function implementing the create_changeset tool. Validates input parameters using Pydantic model, constructs the ServiceNow API request to create a new changeset in the sys_update_set table, handles authentication and errors, and returns the result.
    def create_changeset( auth_manager: AuthManager, server_config: ServerConfig, params: Union[Dict[str, Any], CreateChangesetParams], ) -> Dict[str, Any]: """ Create a new changeset in ServiceNow. Args: auth_manager: The authentication manager. server_config: The server configuration. params: The parameters for creating a changeset. Can be a dictionary or a CreateChangesetParams object. Returns: The created changeset. """ # Unwrap and validate parameters result = _unwrap_and_validate_params( params, CreateChangesetParams, required_fields=["name", "application"] ) if not result["success"]: return result validated_params = result["params"] # Prepare the request data data = { "name": validated_params.name, "application": validated_params.application, } # Add optional fields if provided if validated_params.description: data["description"] = validated_params.description if validated_params.developer: data["developer"] = validated_params.developer # 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" try: response = requests.post(url, json=data, headers=headers) response.raise_for_status() result = response.json() return { "success": True, "message": "Changeset created successfully", "changeset": result["result"], } except requests.exceptions.RequestException as e: logger.error(f"Error creating changeset: {e}") return { "success": False, "message": f"Error creating changeset: {str(e)}", }
  • Pydantic BaseModel defining the input schema for the create_changeset tool, including required fields name and application, and optional description and developer.
    class CreateChangesetParams(BaseModel): """Parameters for creating a changeset.""" name: str = Field(..., description="Name of the changeset") description: Optional[str] = Field(None, description="Description of the changeset") application: str = Field(..., description="Application the changeset belongs to") developer: Optional[str] = Field(None, description="Developer responsible for the changeset")
  • Tool registration entry in get_tool_definitions() function, mapping 'create_changeset' to its handler, input schema, description, and serialization details for use in the MCP server.
    "create_changeset": ( create_changeset_tool, CreateChangesetParams, str, # Expects JSON string "Create a new changeset in ServiceNow", "json_dict", # Tool returns Pydantic model ),
  • Export of create_changeset function from tools package, making it available for import in tool_utils.py.
    create_changeset,
  • Helper function used by create_changeset (and other tools) to unwrap dictionary or Pydantic model parameters, validate against the schema, check required fields, and return validated params or error.
    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/javerthl/servicenow-mcp'

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