create_work_item
Generate and manage work items in Azure DevOps by specifying project, type, title, description, and assignee to streamline task tracking and project management.
Instructions
Create a new work item
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| assignedTo | No | User to assign the work item to | |
| description | No | Description of the work item | |
| project | Yes | Name of the Azure DevOps project | |
| title | Yes | Title of the work item | |
| type | Yes | Type of work item (e.g., 'Task', 'Bug') |
Input Schema (JSON Schema)
{
"properties": {
"assignedTo": {
"description": "User to assign the work item to",
"type": "string"
},
"description": {
"description": "Description of the work item",
"type": "string"
},
"project": {
"description": "Name of the Azure DevOps project",
"type": "string"
},
"title": {
"description": "Title of the work item",
"type": "string"
},
"type": {
"description": "Type of work item (e.g., 'Task', 'Bug')",
"type": "string"
}
},
"required": [
"project",
"type",
"title"
],
"type": "object"
}
Implementation Reference
- src/tools/workItems.ts:119-213 (handler)The main handler function for the 'create_work_item' tool. Parses input using Zod schema, performs additional validation for 'Feature' type, constructs patch operations for required and optional fields, calls the Azure DevOps Work Item Tracking client to create the work item, and returns the created work item as JSON.export async function createWorkItem(rawParams: any) { // Parse arguments with defaults from environment variables const params = createWorkItemSchema.parse({ project: rawParams.project || DEFAULT_PROJECT, type: rawParams.type, title: rawParams.title, description: rawParams.description, assignedTo: rawParams.assignedTo, technologyInvestmentType: rawParams.technologyInvestmentType, securityVulnerability: rawParams.securityVulnerability, }); console.error("[API] Creating work item:", params); // Specific validation for 'Feature' type if (params.type === "Feature") { if (!params.technologyInvestmentType) { throw new Error( "Field 'technologyInvestmentType' is required for work item type 'Feature'." ); } if (!params.securityVulnerability) { throw new Error( "Field 'securityVulnerability' is required for work item type 'Feature'." ); } } try { // Get the Work Item Tracking API client const witClient = await getWorkItemClient(); // Create patch operations for the work item const patchOperations = [ // Removed explicit type annotation { op: "add", path: "/fields/System.Title", value: params.title, }, ]; // Conditionally add optional fields if (params.technologyInvestmentType) { patchOperations.push({ op: "add", path: "/fields/Technology Investment Type", // Assuming field name value: params.technologyInvestmentType, }); } if (params.securityVulnerability) { patchOperations.push({ op: "add", path: "/fields/Security Vulnerability", // Assuming field name value: params.securityVulnerability, }); } if (params.description) { patchOperations.push({ op: "add", path: "/fields/System.Description", value: params.description, }); } if (params.assignedTo) { patchOperations.push({ op: "add", path: "/fields/System.AssignedTo", value: params.assignedTo, }); } // Create the work item const workItem = await witClient.createWorkItem( undefined, patchOperations, params.project, params.type ); return { content: [ { type: "text", text: JSON.stringify(workItem, null, 2), }, ], }; } catch (error) { logError("Error creating work item", error); throw error; } }
- src/schemas/workItems.ts:28-38 (schema)Zod schema used for input validation in the createWorkItem handler, defining the expected parameters with types and optionality.export const createWorkItemSchema = z.object({ project: z.string(), type: z.string(), title: z.string(), description: z.string().optional(), assignedTo: z.string().optional(), technologyInvestmentType: z.string().optional(), // Made optional securityVulnerability: z.string().optional(), // Made optional }); export type CreateWorkItemParams = z.infer<typeof createWorkItemSchema>;
- src/tools/workItems.ts:265-304 (registration)Tool registration in the workItemTools array, defining the name, description, and inputSchema for 'create_work_item' which is later included in the MCP server's tool list.{ name: "create_work_item", description: "Create a new work item", inputSchema: { type: "object", properties: { project: { type: "string", description: "Name of the Azure DevOps project", }, type: { type: "string", description: "Type of work item (e.g., 'Task', 'Bug')", }, title: { type: "string", description: "Title of the work item", }, description: { type: "string", description: "Description of the work item", }, assignedTo: { type: "string", description: "User to assign the work item to", }, technologyInvestmentType: { type: "string", description: "The Technology Investment Type for the work item (Required for Features)", // Updated description }, securityVulnerability: { type: "string", description: "The Security Vulnerability status for the work item (Required for Features)", // Updated description }, }, required: ["project", "type", "title"], // Removed optional fields from required }, },
- src/index.ts:73-74 (registration)Dispatch handler in the MCP server's CallToolRequest handler that routes calls to 'create_work_item' to the createWorkItem function.case "create_work_item": return await createWorkItem(request.params.arguments || {});
- src/index.ts:52-61 (registration)MCP server ListToolsRequest handler that includes workItemTools (containing create_work_item) in the advertised tools list.tools: [ // Work Items ...workItemTools, // Pull Requests ...pullRequestTools, // Wiki ...wikiTools, // Projects ...projectTools, ],