UNPKG

@tiberriver256/mcp-server-azure-devops

Version:

Azure DevOps reference server for the Model Context Protocol (MCP)

60 lines 2.95 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getWorkItem = getWorkItem; const WorkItemTrackingInterfaces_1 = require("azure-devops-node-api/interfaces/WorkItemTrackingInterfaces"); const errors_1 = require("../../../shared/errors"); const workItemTypeFieldsCache = {}; /** * Get a work item by ID * * @param connection The Azure DevOps WebApi connection * @param workItemId The ID of the work item * @param expand Optional expansion options (defaults to WorkItemExpand.All) * @returns The work item details with all fields (null for empty fields) * @throws {AzureDevOpsResourceNotFoundError} If the work item is not found */ async function getWorkItem(connection, workItemId, expand = WorkItemTrackingInterfaces_1.WorkItemExpand.All) { try { const witApi = await connection.getWorkItemTrackingApi(); // Always use expand parameter for consistent behavior const workItem = await witApi.getWorkItem(workItemId, undefined, undefined, expand); if (!workItem) { throw new errors_1.AzureDevOpsResourceNotFoundError(`Work item '${workItemId}' not found`); } // Extract project and work item type to get all possible fields const projectName = workItem.fields?.['System.TeamProject']; const workItemType = workItem.fields?.['System.WorkItemType']; if (!projectName || !workItemType) { // If we can't determine the project or type, return the original work item return workItem; } // Get all possible fields for this work item type const allFields = workItemTypeFieldsCache[projectName.toString()]?.[workItemType.toString()] ?? (await witApi.getWorkItemTypeFieldsWithReferences(projectName.toString(), workItemType.toString(), WorkItemTrackingInterfaces_1.WorkItemTypeFieldsExpandLevel.All)); workItemTypeFieldsCache[projectName.toString()] = { ...workItemTypeFieldsCache[projectName.toString()], [workItemType.toString()]: allFields, }; // Create a new work item object with all fields const enhancedWorkItem = { ...workItem }; // Initialize fields object if it doesn't exist if (!enhancedWorkItem.fields) { enhancedWorkItem.fields = {}; } // Set null for all potential fields that don't have values for (const field of allFields) { if (field.referenceName && !(field.referenceName in enhancedWorkItem.fields)) { enhancedWorkItem.fields[field.referenceName] = field.defaultValue; } } return enhancedWorkItem; } catch (error) { if (error instanceof errors_1.AzureDevOpsError) { throw error; } throw new Error(`Failed to get work item: ${error instanceof Error ? error.message : String(error)}`); } } //# sourceMappingURL=feature.js.map