Skip to main content
Glama
javerthl

ServiceNow MCP Server

by javerthl

reorder_workflow_activities

Change the execution sequence of activities within a ServiceNow workflow by specifying the new order of activity IDs.

Instructions

Reorder activities in a workflow

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
activity_idsYesList of activity IDs in the desired order
workflow_idYesWorkflow ID or sys_id

Implementation Reference

  • The main handler function that implements the reorder_workflow_activities tool logic. It updates the 'order' field of each wf_activity record via ServiceNow REST API PATCH requests.
    def reorder_workflow_activities(
        auth_manager: AuthManager,
        server_config: ServerConfig,
        params: Dict[str, Any],
    ) -> Dict[str, Any]:
        """
        Reorder activities in a workflow.
        
        Args:
            auth_manager: Authentication manager
            server_config: Server configuration
            params: Parameters for reordering workflow activities
            
        Returns:
            Dict[str, Any]: Result of the reordering operation
        """
        # Unwrap parameters if needed
        params = _unwrap_params(params, ReorderWorkflowActivitiesParams)
        
        # Get the correct auth_manager and server_config
        try:
            auth_manager, server_config = _get_auth_and_config(auth_manager, server_config)
        except ValueError as e:
            logger.error(f"Error getting auth and config: {e}")
            return {"error": str(e)}
        
        workflow_id = params.get("workflow_id")
        if not workflow_id:
            return {"error": "Workflow ID is required"}
        
        activity_ids = params.get("activity_ids")
        if not activity_ids:
            return {"error": "Activity IDs are required"}
        
        # Make the API requests to update the order of each activity
        try:
            headers = auth_manager.get_headers()
            results = []
            
            for i, activity_id in enumerate(activity_ids):
                # Calculate the new order value (100, 200, 300, etc.)
                new_order = (i + 1) * 100
                
                url = f"{server_config.instance_url}/api/now/table/wf_activity/{activity_id}"
                data = {"order": new_order}
                
                try:
                    response = requests.patch(url, headers=headers, json=data)
                    response.raise_for_status()
                    
                    results.append({
                        "activity_id": activity_id,
                        "new_order": new_order,
                        "success": True,
                    })
                except requests.RequestException as e:
                    logger.error(f"Error updating activity order: {e}")
                    results.append({
                        "activity_id": activity_id,
                        "error": str(e),
                        "success": False,
                    })
            
            return {
                "message": "Activities reordered",
                "workflow_id": workflow_id,
                "results": results,
            }
        except Exception as e:
            logger.error(f"Unexpected error reordering workflow activities: {e}")
            return {"error": str(e)}
  • Pydantic model defining the input parameters for the reorder_workflow_activities tool: workflow_id and list of activity_ids.
    class ReorderWorkflowActivitiesParams(BaseModel):
        """Parameters for reordering workflow activities."""
        
        workflow_id: str = Field(..., description="Workflow ID or sys_id")
        activity_ids: List[str] = Field(..., description="List of activity IDs in the desired order")
  • Registration of the tool in the get_tool_definitions dictionary, mapping the tool name to its handler, schema, description, etc., for MCP server integration.
    "reorder_workflow_activities": (
        reorder_workflow_activities_tool,
        ReorderWorkflowActivitiesParams,
        str,
        "Reorder activities in a workflow",
        "str",  # Tool returns simple message
    ),
  • Re-export of the reorder_workflow_activities function from workflow_tools in the tools package __init__.
        reorder_workflow_activities,
        update_workflow,
        update_workflow_activity,
    )
    from servicenow_mcp.tools.story_tools import (
        create_story,
        update_story,
        list_stories,
        list_story_dependencies,
        create_story_dependency,
        delete_story_dependency,
    )
    from servicenow_mcp.tools.epic_tools import (
        create_epic,
        update_epic,
        list_epics,
    )
    from servicenow_mcp.tools.scrum_task_tools import (
        create_scrum_task,
        update_scrum_task,
        list_scrum_tasks,
    )
    from servicenow_mcp.tools.project_tools import (
        create_project,
        update_project,
        list_projects,
    )
    # from servicenow_mcp.tools.problem_tools import create_problem, update_problem
    # from servicenow_mcp.tools.request_tools import create_request, update_request
    
    __all__ = [
        # Incident tools
        "create_incident",
        "update_incident",
        "add_comment",
        "resolve_incident",
        "list_incidents",
        
        # Catalog tools
        "list_catalog_items",
        "get_catalog_item",
        "list_catalog_categories",
        "create_catalog_category",
        "update_catalog_category",
        "move_catalog_items",
        "get_optimization_recommendations",
        "update_catalog_item",
        "create_catalog_item_variable",
        "list_catalog_item_variables",
        "update_catalog_item_variable",
        
        # Change management tools
        "create_change_request",
        "update_change_request",
        "list_change_requests",
        "get_change_request_details",
        "add_change_task",
        "submit_change_for_approval",
        "approve_change",
        "reject_change",
        
        # Workflow management tools
        "list_workflows",
        "get_workflow_details",
        "list_workflow_versions",
        "get_workflow_activities",
        "create_workflow",
        "update_workflow",
        "activate_workflow",
        "deactivate_workflow",
        "add_workflow_activity",
        "update_workflow_activity",
        "delete_workflow_activity",
        "reorder_workflow_activities",
  • Import alias used for the tool handler in tool_utils.py registration.
    reorder_workflow_activities as reorder_workflow_activities_tool,
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the full burden of behavioral disclosure. It states the action is 'reorder,' implying a mutation, but does not specify if this requires specific permissions, whether the order change is immediate or requires saving, or what happens to activities not listed in the input. This leaves critical behavioral aspects unclear.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, direct sentence with no unnecessary words, making it highly concise and front-loaded. Every word contributes to stating the tool's purpose efficiently.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the complexity of a mutation tool with no annotations and no output schema, the description is insufficient. It lacks details on behavioral traits (e.g., side effects, error conditions), usage context, and expected outcomes, leaving the agent with incomplete information for proper invocation.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The schema description coverage is 100%, with both parameters clearly documented in the schema (e.g., 'activity_ids' as a list of IDs in desired order). The description does not add any additional meaning beyond what the schema provides, such as format examples or constraints, so it meets the baseline for high schema coverage.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the action ('reorder') and resource ('activities in a workflow'), making the purpose immediately understandable. However, it does not differentiate from sibling tools like 'update_workflow_activity' or 'add_workflow_activity', which could involve similar resources but different operations.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

No guidance is provided on when to use this tool versus alternatives. For example, it does not specify if this should be used after adding activities or as part of workflow editing, nor does it mention prerequisites like needing an existing workflow with activities.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

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

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