Skip to main content
Glama
Tiberriver256

Azure DevOps MCP Server

update_pull_request

Modify Azure DevOps pull requests by updating properties, managing reviewers, linking work items, and adding or removing tags to maintain accurate project tracking.

Instructions

Update an existing pull request with new properties, manage reviewers and work items, and add or remove tags

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
projectIdNoThe ID or name of the project (Default: MyProject)
organizationIdNoThe ID or name of the organization (Default: mycompany)
repositoryIdYesThe ID or name of the repository
pullRequestIdYesThe ID of the pull request to update
titleNoThe updated title of the pull request
descriptionNoThe updated description of the pull request
statusNoThe updated status of the pull request
isDraftNoWhether the pull request should be marked as a draft (true) or unmarked (false)
addWorkItemIdsNoList of work item IDs to link to the pull request
removeWorkItemIdsNoList of work item IDs to unlink from the pull request
addReviewersNoList of reviewer email addresses or IDs to add
removeReviewersNoList of reviewer email addresses or IDs to remove
addTagsNoList of tags to add to the pull request
removeTagsNoList of tags to remove from the pull request
additionalPropertiesNoAdditional properties to update on the pull request

Implementation Reference

  • The core handler function that executes the update_pull_request tool logic. It uses Azure DevOps Git API to update PR properties, links/unlinks work items, adds/removes reviewers, and manages tags.
    export const updatePullRequest = async (
      options: UpdatePullRequestOptions,
    ): Promise<GitPullRequest> => {
      const {
        projectId,
        repositoryId,
        pullRequestId,
        title,
        description,
        status,
        isDraft,
        addWorkItemIds,
        removeWorkItemIds,
        addReviewers,
        removeReviewers,
        addTags,
        removeTags,
        additionalProperties,
      } = options;
    
      try {
        // Get connection to Azure DevOps
        const client = new AzureDevOpsClient({
          method:
            (process.env.AZURE_DEVOPS_AUTH_METHOD as AuthenticationMethod) ?? 'pat',
          organizationUrl: process.env.AZURE_DEVOPS_ORG_URL ?? '',
          personalAccessToken: process.env.AZURE_DEVOPS_PAT,
        });
        const connection = await client.getWebApiClient();
    
        // Get the Git API client
        const gitApi = await connection.getGitApi();
    
        // First, get the current pull request
        const pullRequest = await gitApi.getPullRequestById(
          pullRequestId,
          projectId,
        );
    
        if (!pullRequest) {
          throw new AzureDevOpsError(
            `Pull request ${pullRequestId} not found in repository ${repositoryId}`,
          );
        }
    
        // Store the artifactId for work item linking
        const artifactId = pullRequest.artifactId;
        const effectivePullRequestId = pullRequest.pullRequestId ?? pullRequestId;
    
        // Create an object with the properties to update
        const updateObject: Partial<GitPullRequest> = {};
    
        if (title !== undefined) {
          updateObject.title = title;
        }
    
        if (description !== undefined) {
          updateObject.description = description;
        }
    
        if (isDraft !== undefined) {
          updateObject.isDraft = isDraft;
        }
    
        if (status) {
          const enumStatus = pullRequestStatusMapper.toEnum(status);
          if (enumStatus !== undefined) {
            updateObject.status = enumStatus;
          } else {
            throw new AzureDevOpsError(
              `Invalid status: ${status}. Valid values are: active, abandoned, completed`,
            );
          }
        }
    
        // Add any additional properties that were specified
        if (additionalProperties) {
          Object.assign(updateObject, additionalProperties);
        }
    
        // Update the pull request
        const updatedPullRequest = await gitApi.updatePullRequest(
          updateObject,
          repositoryId,
          pullRequestId,
          projectId,
        );
    
        // Handle work items separately if needed
        const addIds = addWorkItemIds ?? [];
        const removeIds = removeWorkItemIds ?? [];
        if (addIds.length > 0 || removeIds.length > 0) {
          await handleWorkItems({
            connection,
            pullRequestId,
            repositoryId,
            projectId,
            workItemIdsToAdd: addIds,
            workItemIdsToRemove: removeIds,
            artifactId,
          });
        }
    
        // Handle reviewers separately if needed
        const addReviewerIds = addReviewers ?? [];
        const removeReviewerIds = removeReviewers ?? [];
        if (addReviewerIds.length > 0 || removeReviewerIds.length > 0) {
          await handleReviewers({
            connection,
            pullRequestId,
            repositoryId,
            projectId,
            reviewersToAdd: addReviewerIds,
            reviewersToRemove: removeReviewerIds,
          });
        }
    
        const normalizedTagsToAdd = normalizeTags(addTags);
        const normalizedTagsToRemove = normalizeTags(removeTags);
    
        if (
          effectivePullRequestId &&
          (normalizedTagsToAdd.length > 0 || normalizedTagsToRemove.length > 0)
        ) {
          let labels =
            (await gitApi.getPullRequestLabels(
              repositoryId,
              effectivePullRequestId,
              projectId,
            )) ?? [];
    
          const existingNames = new Set(
            labels
              .map((label) => label.name?.toLowerCase())
              .filter((name): name is string => Boolean(name)),
          );
    
          const tagsToCreate = normalizedTagsToAdd.filter(
            (tag) => !existingNames.has(tag.toLowerCase()),
          );
    
          for (const tag of tagsToCreate) {
            try {
              const createdLabel = await gitApi.createPullRequestLabel(
                { name: tag },
                repositoryId,
                effectivePullRequestId,
                projectId,
              );
              labels.push(createdLabel);
              existingNames.add(tag.toLowerCase());
            } catch (error) {
              throw new Error(
                `Failed to add tag '${tag}': ${
                  error instanceof Error ? error.message : String(error)
                }`,
              );
            }
          }
    
          for (const tag of normalizedTagsToRemove) {
            try {
              await gitApi.deletePullRequestLabels(
                repositoryId,
                effectivePullRequestId,
                tag,
                projectId,
              );
              labels = labels.filter((label) => {
                const name = label.name?.toLowerCase();
                return name ? name !== tag.toLowerCase() : true;
              });
              existingNames.delete(tag.toLowerCase());
            } catch (error) {
              if (
                error &&
                typeof error === 'object' &&
                'statusCode' in error &&
                (error as { statusCode?: number }).statusCode === 404
              ) {
                continue;
              }
    
              throw new Error(
                `Failed to remove tag '${tag}': ${
                  error instanceof Error ? error.message : String(error)
                }`,
              );
            }
          }
    
          updatedPullRequest.labels = labels;
        }
    
        return updatedPullRequest;
      } catch (error) {
        throw new AzureDevOpsError(
          `Failed to update pull request ${pullRequestId} in repository ${repositoryId}: ${error instanceof Error ? error.message : String(error)}`,
        );
      }
    };
  • Zod schema for validating input arguments to the update_pull_request tool.
    export const UpdatePullRequestSchema = z.object({
      projectId: z
        .string()
        .optional()
        .describe(`The ID or name of the project (Default: ${defaultProject})`),
      organizationId: z
        .string()
        .optional()
        .describe(`The ID or name of the organization (Default: ${defaultOrg})`),
      repositoryId: z.string().describe('The ID or name of the repository'),
      pullRequestId: z.number().describe('The ID of the pull request to update'),
      title: z
        .string()
        .optional()
        .describe('The updated title of the pull request'),
      description: z
        .string()
        .optional()
        .describe('The updated description of the pull request'),
      status: z
        .enum(['active', 'abandoned', 'completed'])
        .optional()
        .describe('The updated status of the pull request'),
      isDraft: z
        .boolean()
        .optional()
        .describe(
          'Whether the pull request should be marked as a draft (true) or unmarked (false)',
        ),
      addWorkItemIds: z
        .array(z.number())
        .optional()
        .describe('List of work item IDs to link to the pull request'),
      removeWorkItemIds: z
        .array(z.number())
        .optional()
        .describe('List of work item IDs to unlink from the pull request'),
      addReviewers: z
        .array(z.string())
        .optional()
        .describe('List of reviewer email addresses or IDs to add'),
      removeReviewers: z
        .array(z.string())
        .optional()
        .describe('List of reviewer email addresses or IDs to remove'),
      addTags: z
        .array(z.string().trim().min(1))
        .optional()
        .describe('List of tags to add to the pull request'),
      removeTags: z
        .array(z.string().trim().min(1))
        .optional()
        .describe('List of tags to remove from the pull request'),
      additionalProperties: z
        .record(z.string(), z.any())
        .optional()
        .describe('Additional properties to update on the pull request'),
    });
  • Tool definition registration for the update_pull_request MCP tool, including name, description, and JSON schema.
    {
      name: 'update_pull_request',
      description:
        'Update an existing pull request with new properties, manage reviewers and work items, and add or remove tags',
      inputSchema: zodToJsonSchema(UpdatePullRequestSchema),
    },
  • MCP request handler dispatcher switch case that parses tool arguments and invokes the updatePullRequest handler.
    case 'update_pull_request': {
      const params = UpdatePullRequestSchema.parse(request.params.arguments);
      const fixedParams = {
        ...params,
        projectId: params.projectId ?? defaultProject,
      };
      const result = await updatePullRequest(fixedParams);
      return {
        content: [{ type: 'text', text: JSON.stringify(result, null, 2) }],
      };
    }
  • TypeScript interface defining options for the updatePullRequest handler.
    export interface UpdatePullRequestOptions {
      projectId: string;
      repositoryId: string;
      pullRequestId: number;
      title?: string;
      description?: string;
      status?: 'active' | 'abandoned' | 'completed';
      isDraft?: boolean;
      addWorkItemIds?: number[];
      removeWorkItemIds?: number[];
      addReviewers?: string[]; // Array of reviewer identifiers (email or ID)
      removeReviewers?: string[]; // Array of reviewer identifiers (email or ID)
      addTags?: string[];
      removeTags?: string[];
      additionalProperties?: Record<string, string | number | boolean>;
    }
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the full burden of behavioral disclosure. It mentions updating properties and managing elements but fails to detail critical aspects like required permissions, whether changes are reversible, potential side effects, or response format. For a mutation tool with 15 parameters, this is a significant gap in transparency.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence that front-loads the core action and lists key capabilities without unnecessary words. It could be slightly improved by structuring it into bullet points for clarity, but it remains appropriately concise for the tool's complexity.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's complexity (15 parameters, mutation operation, no annotations, and no output schema), the description is insufficient. It lacks details on behavioral traits, error handling, return values, and usage context, making it incomplete for effective agent invocation despite the comprehensive schema.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The schema description coverage is 100%, meaning all parameters are documented in the schema itself. The description adds minimal value by listing general categories ('new properties, manage reviewers and work items, and add or remove tags') but does not provide additional syntax, constraints, or examples beyond what the schema offers, aligning with the baseline score.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the action ('Update an existing pull request') and specifies what can be updated ('new properties, manage reviewers and work items, and add or remove tags'), making the purpose evident. However, it does not explicitly differentiate this tool from sibling tools like 'update_work_item' or 'create_pull_request', which would be needed for a score of 5.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives, such as 'create_pull_request' for new pull requests or 'update_work_item' for related updates. It lacks context on prerequisites, exclusions, or typical scenarios, leaving usage unclear.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other 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/Tiberriver256/mcp-server-azure-devops'

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