UNPKG

@mcp-apps/azure-devops-mcp-server

Version:

A Model Context Protocol (MCP) server for Azure DevOps integration

62 lines (60 loc) 3.23 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.listWorkItemsTool = void 0; const zod_1 = require("zod"); const azure_devops_client_1 = require("../utils/azure-devops-client"); // Tool to list work items exports.listWorkItemsTool = { name: "list-work-items", description: ` List work items in Azure DevOps. This tool accepts a WIQL query to filter work items. WIQL (Work Item Query Language) is similar to SQL and allows querying work items based on their fields. If you have a work item URL like 'https://dev.azure.com/{organization}/{project}/_workitems/edit/{id}', you can extract the work item ID from the URL and use it in a query like: 'SELECT [System.Id] FROM workitems WHERE [System.Id] = {id}' `, 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"), query: zod_1.z.string().describe("Work item query (e.g., SELECT [System.Id] FROM workitems WHERE [System.WorkItemType] = 'Bug')"), }, handler: async ({ organizationUrl, project, query }) => { try { const witApi = await (0, azure_devops_client_1.getWorkItemTrackingApi)(organizationUrl); // Execute the query const queryResult = await witApi.queryByWiql({ query }, { project }, false, 10); if (!queryResult || !queryResult.workItems || queryResult.workItems.length === 0) { return { content: [{ type: "text", text: "No work items found matching the query." }], }; } const workItemIds = queryResult.workItems.map((wi) => wi.id).filter((id) => id !== undefined); const workItems = await witApi.getWorkItems(workItemIds); const formattedItems = workItems.map((item) => { const fields = item.fields || {}; return { id: item.id, type: fields["System.WorkItemType"] || "Unknown", title: fields["System.Title"] || "No Title", state: fields["System.State"] || "Unknown", description: fields["System.Description"] || "No Description", createdBy: fields["System.CreatedBy"]?.displayName || "Unknown", assignedTo: fields["System.AssignedTo"]?.displayName || "Unassigned", url: item._links?.html?.href || `https://dev.azure.com/${organizationUrl.split("/")[3]}/${project}/_workitems/edit/${item.id}`, }; }); return { content: [{ type: "text", text: JSON.stringify(formattedItems, null, 2) }], }; } catch (error) { console.error("Error listing work items:", error); const errorMessage = error instanceof Error ? error.message : String(error); return { content: [{ type: "text", text: `Error listing work items: ${errorMessage}` }], }; } } }; //# sourceMappingURL=list-work-items.js.map