Skip to main content
Glama
ennuiii

Azure DevOps MCP Server with PAT Authentication

by ennuiii

wit_link_work_item_to_pull_request

Link a specific work item to an existing pull request in Azure DevOps using project, repository, and work item IDs for streamlined tracking and collaboration.

Instructions

Link a single work item to an existing pull request.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
projectIdYesThe project ID of the Azure DevOps project (note: project name is not valid).
pullRequestIdYesThe ID of the pull request to link to.
pullRequestProjectIdNoThe project ID containing the pull request. If not provided, defaults to the work item's project ID (for same-project linking).
repositoryIdYesThe ID of the repository containing the pull request. Do not use the repository name here, use the ID instead.
workItemIdYesThe ID of the work item to link to the pull request.

Implementation Reference

  • Maps the friendly name 'link_work_item_to_pull_request' to the MCP tool name 'wit_link_work_item_to_pull_request' in the WORKITEM_TOOLS constant used for registration.
    link_work_item_to_pull_request: "wit_link_work_item_to_pull_request",
  • Zod schema defining the input parameters for the tool.
    { projectId: z.string().describe("The project ID of the Azure DevOps project (note: project name is not valid)."), repositoryId: z.string().describe("The ID of the repository containing the pull request. Do not use the repository name here, use the ID instead."), pullRequestId: z.number().describe("The ID of the pull request to link to."), workItemId: z.number().describe("The ID of the work item to link to the pull request."), pullRequestProjectId: z.string().optional().describe("The project ID containing the pull request. If not provided, defaults to the work item's project ID (for same-project linking)."), },
  • The handler function that executes the tool: constructs a VSTFS URI for the pull request (vstfs:///Git/PullRequestId/...), creates a PATCH document to add an 'ArtifactLink' relation to the work item, and updates the work item via the Azure DevOps WorkItemTrackingApi.
    async ({ projectId, repositoryId, pullRequestId, workItemId, pullRequestProjectId }) => { try { const connection = await connectionProvider(); const workItemTrackingApi = await connection.getWorkItemTrackingApi(); // Create artifact link relation using vstfs format // Format: vstfs:///Git/PullRequestId/{project}/{repositoryId}/{pullRequestId} const artifactProjectId = pullRequestProjectId && pullRequestProjectId.trim() !== "" ? pullRequestProjectId : projectId; const artifactPathValue = `${artifactProjectId}/${repositoryId}/${pullRequestId}`; const vstfsUrl = `vstfs:///Git/PullRequestId/${encodeURIComponent(artifactPathValue)}`; // Use the PATCH document format for adding a relation const patchDocument = [ { op: "add", path: "/relations/-", value: { rel: "ArtifactLink", url: vstfsUrl, attributes: { name: "Pull Request", }, }, }, ]; // Use the WorkItem API to update the work item with the new relation const workItem = await workItemTrackingApi.updateWorkItem({}, patchDocument, workItemId, projectId); if (!workItem) { return { content: [{ type: "text", text: "Work item update failed" }], isError: true }; } return { content: [ { type: "text", text: JSON.stringify( { workItemId, pullRequestId, success: true, }, null, 2 ), }, ], }; } catch (error) { const errorMessage = error instanceof Error ? error.message : "Unknown error occurred"; return { content: [{ type: "text", text: `Error linking work item to pull request: ${errorMessage}` }], isError: true, }; } } );

Other Tools

Related Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/ennuiii/DevOpsMcpPAT'

If you have feedback or need assistance with the MCP directory API, please join our Discord server