get_work_item_template
Retrieve detailed information about Azure DevOps work item templates to view default field values and understand what content is pre-populated.
Instructions
Gets detailed information about a specific work item template.
Use this tool when you need to:
- View default field values in a template
- Understand what a template pre-populates in a work item
- Get complete details about a template
Args:
team_context: Dictionary containing team information with keys:
project: Project name (Optional if project_id is provided)
project_id: Project ID (Optional if project is provided)
team: Team name (Optional if team_id is provided)
team_id: Team ID (Optional if team is provided)
template_id: The ID of the template
Returns:
Detailed information about the template including default field
values
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| team_context | Yes | ||
| template_id | Yes |
Implementation Reference
- The main handler function for the 'get_work_item_template' MCP tool. It is decorated with @mcp.tool() for automatic registration and implements the tool logic by calling the internal _get_work_item_template_impl helper.def get_work_item_template(team_context: dict, template_id: str) -> str: """ Gets detailed information about a specific work item template. Use this tool when you need to: - View default field values in a template - Understand what a template pre-populates in a work item - Get complete details about a template Args: team_context: Dictionary containing team information with keys: project: Project name (Optional if project_id is provided) project_id: Project ID (Optional if project is provided) team: Team name (Optional if team_id is provided) team_id: Team ID (Optional if team is provided) template_id: The ID of the template Returns: Detailed information about the template including default field values """ try: wit_client = get_work_item_client() return _get_work_item_template_impl( team_context, template_id, wit_client) except AzureDevOpsClientError as e: return f"Error: {str(e)}"
- Core implementation logic that retrieves the work item template using the Azure DevOps client, handles errors, and formats the output using _format_work_item_template.def _get_work_item_template_impl(team_context: dict, template_id: str, wit_client: WorkItemTrackingClient) -> str: """Implementation of work item template detail retrieval.""" try: team_ctx = _create_team_context(team_context) template = wit_client.get_template(team_ctx, template_id) if not template: return f"Template with ID '{template_id}' not found." return _format_work_item_template(template) except Exception as e: return f"Error retrieving template '{template_id}': {str(e)}"
- Aggregates and registers all work items tools by calling templates.register_tools(mcp), which in turn defines and registers the get_work_item_template tool.def register_tools(mcp) -> None: """ Register all work item tools with the MCP server. Args: mcp: The FastMCP server instance """ query.register_tools(mcp) read.register_tools(mcp) comments.register_tools(mcp) create.register_tools(mcp) types.register_tools(mcp) templates.register_tools(mcp) process.register_tools(mcp)
- Helper function to format the retrieved template data into a readable markdown structure including name, attributes, and default field values.def _format_work_item_template(template): """Format work item template data for display.""" result = [f"# Template: {template.name}"] for attr in ["description", "work_item_type_name", "id"]: value = getattr(template, attr, None) if value: result.append(f"{attr.replace('_', ' ').capitalize()}: {value}") fields = getattr(template, "fields", None) if fields: result.append("\n## Default Field Values") for field, value in fields.items(): result.append(f"- {field}: {value}") return "\n".join(result)
- Helper utility to convert the input team_context dictionary into the Azure DevOps TeamContext object required by the API.def _create_team_context(team_context_dict): """Create a TeamContext object from a dictionary.""" from azure.devops.v7_1.work_item_tracking.models import TeamContext return TeamContext( project=team_context_dict.get('project'), project_id=team_context_dict.get('project_id'), team=team_context_dict.get('team'), team_id=team_context_dict.get('team_id') )