UNPKG

@tiberriver256/mcp-server-azure-devops

Version:

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

99 lines 3.36 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.createWorkItem = createWorkItem; const errors_1 = require("../../../shared/errors"); /** * Create a work item * * @param connection The Azure DevOps WebApi connection * @param projectId The ID or name of the project * @param workItemType The type of work item to create (e.g., "Task", "Bug", "User Story") * @param options Options for creating the work item * @returns The created work item */ async function createWorkItem(connection, projectId, workItemType, options) { try { if (!options.title) { throw new Error('Title is required'); } const witApi = await connection.getWorkItemTrackingApi(); // Create the JSON patch document const document = []; // Add required fields document.push({ op: 'add', path: '/fields/System.Title', value: options.title, }); // Add optional fields if provided if (options.description) { document.push({ op: 'add', path: '/fields/System.Description', value: options.description, }); } if (options.assignedTo) { document.push({ op: 'add', path: '/fields/System.AssignedTo', value: options.assignedTo, }); } if (options.areaPath) { document.push({ op: 'add', path: '/fields/System.AreaPath', value: options.areaPath, }); } if (options.iterationPath) { document.push({ op: 'add', path: '/fields/System.IterationPath', value: options.iterationPath, }); } if (options.priority !== undefined) { document.push({ op: 'add', path: '/fields/Microsoft.VSTS.Common.Priority', value: options.priority, }); } // Add parent relationship if parentId is provided if (options.parentId) { document.push({ op: 'add', path: '/relations/-', value: { rel: 'System.LinkTypes.Hierarchy-Reverse', url: `${connection.serverUrl}/_apis/wit/workItems/${options.parentId}`, }, }); } // Add any additional fields if (options.additionalFields) { for (const [key, value] of Object.entries(options.additionalFields)) { document.push({ op: 'add', path: `/fields/${key}`, value: value, }); } } // Create the work item const workItem = await witApi.createWorkItem(null, document, projectId, workItemType); if (!workItem) { throw new Error('Failed to create work item'); } return workItem; } catch (error) { if (error instanceof errors_1.AzureDevOpsError) { throw error; } throw new Error(`Failed to create work item: ${error instanceof Error ? error.message : String(error)}`); } } //# sourceMappingURL=feature.js.map