Skip to main content
Glama
vparlapalli490

ServiceNow MCP Server

get_workflow_activities

Retrieve activities for a specific ServiceNow workflow to analyze process steps and track workflow execution status.

Instructions

Get activities for a specific workflow

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
workflow_idYesWorkflow ID or sys_id
versionNoSpecific version to get activities for

Implementation Reference

  • Main handler function that retrieves workflow activities from ServiceNow API. Automatically fetches the latest published version if none specified, queries wf_activity table ordered by order.
    def get_workflow_activities(
        auth_manager: AuthManager,
        server_config: ServerConfig,
        params: Dict[str, Any],
    ) -> Dict[str, Any]:
        """
        Get activities for a specific workflow.
        
        Args:
            auth_manager: Authentication manager
            server_config: Server configuration
            params: Parameters for getting workflow activities
            
        Returns:
            Dict[str, Any]: List of workflow activities
        """
        # Unwrap parameters if needed
        params = _unwrap_params(params, GetWorkflowActivitiesParams)
        
        # 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"}
        
        version_id = params.get("version")
        
        # If no version specified, get the latest published version
        if not version_id:
            try:
                headers = auth_manager.get_headers()
                version_url = f"{server_config.instance_url}/api/now/table/wf_workflow_version"
                version_params = {
                    "sysparm_query": f"workflow={workflow_id}^published=true",
                    "sysparm_limit": 1,
                    "sysparm_orderby": "version DESC",
                }
                
                version_response = requests.get(version_url, headers=headers, params=version_params)
                version_response.raise_for_status()
                
                version_result = version_response.json()
                versions = version_result.get("result", [])
                
                if not versions:
                    return {
                        "error": f"No published versions found for workflow {workflow_id}",
                        "workflow_id": workflow_id,
                    }
                
                version_id = versions[0]["sys_id"]
            except requests.RequestException as e:
                logger.error(f"Error getting workflow version: {e}")
                return {"error": str(e)}
            except Exception as e:
                logger.error(f"Unexpected error getting workflow version: {e}")
                return {"error": str(e)}
        
        # Get activities for the version
        try:
            headers = auth_manager.get_headers()
            activities_url = f"{server_config.instance_url}/api/now/table/wf_activity"
            activities_params = {
                "sysparm_query": f"workflow_version={version_id}",
                "sysparm_orderby": "order",
            }
            
            activities_response = requests.get(activities_url, headers=headers, params=activities_params)
            activities_response.raise_for_status()
            
            activities_result = activities_response.json()
            return {
                "activities": activities_result.get("result", []),
                "count": len(activities_result.get("result", [])),
                "workflow_id": workflow_id,
                "version_id": version_id,
            }
        except requests.RequestException as e:
            logger.error(f"Error getting workflow activities: {e}")
            return {"error": str(e)}
        except Exception as e:
            logger.error(f"Unexpected error getting workflow activities: {e}")
            return {"error": str(e)}
  • Pydantic model for input parameters: workflow_id (required str), version (optional str).
    class GetWorkflowActivitiesParams(BaseModel):
        """Parameters for getting workflow activities."""
        
        workflow_id: str = Field(..., description="Workflow ID or sys_id")
        version: Optional[str] = Field(None, description="Specific version to get activities for")
  • Registers the 'get_workflow_activities' tool in the MCP server, linking the handler function, input schema, description, and output serialization as JSON.
    "get_workflow_activities": (
        get_workflow_activities_tool,
        GetWorkflowActivitiesParams,
        str,  # Expects JSON string
        "Get activities for a specific workflow",
        "json",  # Tool returns list/dict
    ),
  • Imports and aliases the handler function for use in tool registration.
        get_workflow_activities as get_workflow_activities_tool,
    )
  • Helper function to unwrap parameters from Pydantic model to dict, used in all workflow tools including get_workflow_activities.
    def _unwrap_params(params: Any, param_class: Type[T]) -> Dict[str, Any]:
        """
        Unwrap parameters if they're wrapped in a Pydantic model.
        This helps handle cases where the parameters are passed as a model instead of a dict.
        """
        if isinstance(params, dict):
            return params
        if isinstance(params, param_class):
            return params.dict(exclude_none=True)
        return params
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 a read operation ('Get'), implying it's likely non-destructive, but doesn't specify permissions required, rate limits, pagination, error handling, or what the return format includes (e.g., list of activities with details). This leaves significant gaps for a tool that fetches data.

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, efficient sentence with zero waste—it directly states the tool's purpose without unnecessary words. It's appropriately sized for a simple retrieval tool, though this conciseness comes at the cost of detail.

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 tool's complexity (retrieving workflow activities), lack of annotations, and no output schema, the description is incomplete. It doesn't explain what 'activities' are, how results are structured, or behavioral aspects like authentication needs. For a data-fetching tool with no structured support, more context is needed to guide the agent effectively.

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?

Schema description coverage is 100%, so the schema already documents both parameters (workflow_id and version) with descriptions. The description adds no additional meaning beyond implying 'activities' are retrieved, which is redundant with the tool's purpose. Baseline 3 is appropriate as the schema does the heavy lifting.

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

Purpose3/5

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

The description 'Get activities for a specific workflow' clearly states the action (get) and resource (activities for a workflow), but it's vague about what 'activities' entail (e.g., tasks, steps, logs) and doesn't distinguish it from sibling tools like 'get_workflow_details' or 'list_workflows', which might overlap in scope. It avoids tautology by not just restating the name, but lacks specificity.

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?

The description provides no guidance on when to use this tool versus alternatives. It doesn't mention prerequisites (e.g., needing a valid workflow ID), exclusions, or compare it to siblings like 'list_workflow_versions' or 'get_workflow_details', leaving the agent to infer usage from the name alone.

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/vparlapalli490/MCP'

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