Skip to main content
Glama
JLKmach

ServiceNow MCP Server

by JLKmach

create_story_dependency

Establish relationships between ServiceNow stories by defining dependencies, ensuring proper workflow sequencing in agile project management.

Instructions

Create a dependency between two stories in ServiceNow

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
dependent_storyYesSys_id of the dependent story is required
prerequisite_storyYesSys_id that this story depends on is required

Implementation Reference

  • The main handler function implementing the logic for the 'create_story_dependency' tool. It validates input parameters using CreateStoryDependencyParams, constructs a POST request to the ServiceNow 'm2m_story_dependencies' table API, and returns the created dependency or error.
    def create_story_dependency(
        auth_manager: AuthManager,
        server_config: ServerConfig,
        params: Dict[str, Any],
    ) -> Dict[str, Any]:
        """
        Create a dependency between two stories in ServiceNow.
    
        Args:
            auth_manager: The authentication manager.
            server_config: The server configuration.
            params: The parameters for creating a story dependency.
    
        Returns:
            The created story dependency.
        """
        # Unwrap and validate parameters    
        result = _unwrap_and_validate_params(
            params, 
            CreateStoryDependencyParams,
            required_fields=["dependent_story", "prerequisite_story"]
        )
        
        if not result["success"]:
            return result
        
        validated_params = result["params"]
        
        # Prepare the request data
        data = {
            "dependent_story": validated_params.dependent_story,
            "prerequisite_story": validated_params.prerequisite_story,
        }
        
        # 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/m2m_story_dependencies"
        
        try:
            response = requests.post(url, json=data, headers=headers)
            response.raise_for_status()
            
            result = response.json()    
            return {
                "success": True,
                "message": "Story dependency created successfully",
                "story_dependency": result["result"],
            }
        except requests.exceptions.RequestException as e:
            logger.error(f"Error creating story dependency: {e}")
            return {
                "success": False,
                "message": f"Error creating story dependency: {str(e)}",
            }
  • Pydantic BaseModel defining the input schema for the create_story_dependency tool, requiring 'dependent_story' and 'prerequisite_story' sys_ids.
    class CreateStoryDependencyParams(BaseModel):
        """Parameters for creating a story dependency."""
    
        dependent_story: str = Field(..., description="Sys_id of the dependent story is required")
        prerequisite_story: str = Field(..., description="Sys_id that this story depends on is required")
  • Tool registration in the get_tool_definitions() dictionary, associating the tool name 'create_story_dependency' with its aliased handler function, input schema (CreateStoryDependencyParams), return type, description, and serialization method.
    "create_story_dependency": (
        create_story_dependency_tool,
        CreateStoryDependencyParams,
        str,
        "Create a dependency between two stories in ServiceNow",
        "str",
    ),
  • Exposes the create_story_dependency function in the tools package __all__ list for easy import.
    "create_story_dependency",
  • Import alias for the handler function used in tool registration.
    create_story_dependency as create_story_dependency_tool,

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