@mcp-apps/azure-devops-mcp-server
Version:
A Model Context Protocol (MCP) server for Azure DevOps integration
99 lines (97 loc) • 4.45 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.createWorkItemTool = void 0;
const zod_1 = require("zod");
const azure_devops_client_1 = require("../utils/azure-devops-client");
// Tool to create a work item
exports.createWorkItemTool = {
name: "create-work-item",
description: `
Creates a new work item in an Azure DevOps project. If the fields are required, they must be provided.
Confirm with the user if any of the required fields are missing.
Parameters:
- organizationUrl [Required]: Azure DevOps URL (https://dev.azure.com/{organization})
- project [Required]: Project name (case-sensitive)
- areaPath: [Required] Area path (e.g., TeamProject\\Area) - case-sensitive
- iterationPath: [Required] Iteration path (e.g., TeamProject\\Iteration) - case-sensitive
- workItemType [Required]: Type of work item (Bug, Task, User Story, etc.) - case-sensitive
- title [Required]: Title of the work item
- description [Optional]: Detailed description (supports HTML)
- assignedTo [Optional]: User email or display name
Make sure to provide link to the user in appropriate format.
`,
parameters: {
organizationUrl: zod_1.z.string().describe("Azure DevOps organization URL (e.g., https://dev.azure.com/organization)"),
project: zod_1.z.string().describe("Project name"),
areaPath: zod_1.z.string().describe("Area path (e.g., TeamProject\\Area)"),
iterationPath: zod_1.z.string().describe("Iteration path (e.g., TeamProject\\Iteration)"),
workItemType: zod_1.z.string().describe("Work item type (e.g., Bug, Task, User Story)"),
title: zod_1.z.string().describe("Work item title"),
description: zod_1.z.string().optional().describe("Work item description"),
assignedTo: zod_1.z.string().optional().describe("User to assign the work item to"),
},
handler: async ({ organizationUrl, project, areaPath, iterationPath, workItemType, title, description, assignedTo }) => {
try {
const witApi = await (0, azure_devops_client_1.getWorkItemTrackingApi)(organizationUrl);
const patchDocument = [
{
op: "add",
path: "/fields/System.Title",
value: title,
},
];
if (description) {
patchDocument.push({
op: "add",
path: "/fields/System.Description",
value: description,
});
}
if (assignedTo) {
patchDocument.push({
op: "add",
path: "/fields/System.AssignedTo",
value: assignedTo,
});
}
if (areaPath) {
patchDocument.push({
op: "add",
path: "/fields/System.AreaPath",
value: areaPath,
});
}
if (iterationPath) {
patchDocument.push({
op: "add",
path: "/fields/System.IterationPath",
value: iterationPath,
});
}
patchDocument.push({
op: "add",
path: "/fields/System.Tags",
value: "Created by AI",
});
// Create the work item
const createdWorkItem = await witApi.createWorkItem(null, patchDocument, project, workItemType);
const fields = createdWorkItem.fields || {};
return {
content: [
{
type: "text",
text: `Work item created successfully:\nID: ${createdWorkItem.id}\nTitle: ${fields["System.Title"] || workItemType}\nType: ${workItemType}\nURL: ${createdWorkItem._links?.html?.href || ""}`,
},
],
};
}
catch (error) {
console.error("Error creating work item:", error);
const errorMessage = error instanceof Error ? error.message : String(error);
return {
content: [{ type: "text", text: `Error creating work item: ${errorMessage}` }],
};
}
}
};
//# sourceMappingURL=create-work-item.js.map