Skip to main content
Glama
pdogra1299
by pdogra1299

update_pull_request

Modify an existing pull request to update its title, description, destination branch, or reviewers while preserving approval status. Works with Bitbucket repositories for streamlined PR lifecycle management.

Instructions

Update an existing pull request. When updating without specifying reviewers, existing reviewers and their approval status will be preserved.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
descriptionNoNew description (optional)
destination_branchNoNew destination branch (optional)
pull_request_idYesPull request ID
repositoryYesRepository slug (e.g., "my-repo")
reviewersNoNew list of reviewer usernames/emails. If provided, replaces the reviewer list (preserving approval status for existing reviewers). If omitted, existing reviewers are preserved. (optional)
titleNoNew title (optional)
workspaceYesBitbucket workspace/project key (e.g., "PROJ")

Implementation Reference

  • Main handler function for update_pull_request tool. Validates input using isUpdatePullRequestArgs, constructs appropriate API request for Bitbucket Server or Cloud (preserving reviewer approvals on Server), performs PUT request to update PR, formats and returns the response.
    async handleUpdatePullRequest(args: any) {
      if (!isUpdatePullRequestArgs(args)) {
        throw new McpError(
          ErrorCode.InvalidParams,
          'Invalid arguments for update_pull_request'
        );
      }
    
      const { workspace, repository, pull_request_id, title, description, destination_branch, reviewers } = args;
    
      try {
        let apiPath: string;
        let requestBody: any = {};
    
        if (this.apiClient.getIsServer()) {
          // Bitbucket Server API
          apiPath = `/rest/api/1.0/projects/${workspace}/repos/${repository}/pull-requests/${pull_request_id}`;
          
          // First get the current PR to get version number and existing data
          const currentPr = await this.apiClient.makeRequest<any>('get', apiPath);
          
          requestBody.version = currentPr.version;
          if (title !== undefined) requestBody.title = title;
          if (description !== undefined) requestBody.description = description;
          if (destination_branch !== undefined) {
            requestBody.toRef = {
              id: `refs/heads/${destination_branch}`,
              repository: {
                slug: repository,
                project: {
                  key: workspace
                }
              }
            };
          }
          
          // Handle reviewers: preserve existing ones if not explicitly updating
          if (reviewers !== undefined) {
            // User wants to update reviewers
            // Create a map of existing reviewers for preservation of approval status
            const existingReviewersMap = new Map(
              currentPr.reviewers.map((r: any) => [r.user.name, r])
            );
            
            requestBody.reviewers = reviewers.map(username => {
              const existing = existingReviewersMap.get(username);
              if (existing) {
                // Preserve existing reviewer's full data including approval status
                return existing;
              } else {
                // Add new reviewer (without approval status)
                return { user: { name: username } };
              }
            });
          } else {
            // No reviewers provided - preserve existing reviewers with their full data
            requestBody.reviewers = currentPr.reviewers;
          }
        } else {
          // Bitbucket Cloud API
          apiPath = `/repositories/${workspace}/${repository}/pullrequests/${pull_request_id}`;
          
          if (title !== undefined) requestBody.title = title;
          if (description !== undefined) requestBody.description = description;
          if (destination_branch !== undefined) {
            requestBody.destination = {
              branch: {
                name: destination_branch
              }
            };
          }
          if (reviewers !== undefined) {
            requestBody.reviewers = reviewers.map(r => ({ username: r }));
          }
        }
    
        const pr = await this.apiClient.makeRequest<any>('put', apiPath, requestBody);
        
        const formattedResponse = this.apiClient.getIsServer() 
          ? formatServerResponse(pr as BitbucketServerPullRequest, undefined, this.baseUrl)
          : formatCloudResponse(pr as BitbucketCloudPullRequest);
    
        return {
          content: [
            {
              type: 'text',
              text: JSON.stringify({
                message: 'Pull request updated successfully',
                pull_request: formattedResponse
              }, null, 2),
            },
          ],
        };
      } catch (error) {
        return this.apiClient.handleApiError(error, `updating pull request ${pull_request_id} in ${workspace}/${repository}`);
      }
    }
  • MCP tool definition including name, description, and inputSchema JSON Schema for validating tool parameters.
    {
      name: 'update_pull_request',
      description: 'Update an existing pull request. When updating without specifying reviewers, existing reviewers and their approval status will be preserved.',
      inputSchema: {
        type: 'object',
        properties: {
          workspace: {
            type: 'string',
            description: 'Bitbucket workspace/project key (e.g., "PROJ")',
          },
          repository: {
            type: 'string',
            description: 'Repository slug (e.g., "my-repo")',
          },
          pull_request_id: {
            type: 'number',
            description: 'Pull request ID',
          },
          title: {
            type: 'string',
            description: 'New title (optional)',
          },
          description: {
            type: 'string',
            description: 'New description (optional)',
          },
          destination_branch: {
            type: 'string',
            description: 'New destination branch (optional)',
          },
          reviewers: {
            type: 'array',
            items: { type: 'string' },
            description: 'New list of reviewer usernames/emails. If provided, replaces the reviewer list (preserving approval status for existing reviewers). If omitted, existing reviewers are preserved. (optional)',
          },
        },
        required: ['workspace', 'repository', 'pull_request_id'],
      },
  • Type guard function for validating and typing update_pull_request arguments at runtime.
    export const isUpdatePullRequestArgs = (
      args: any
    ): args is {
      workspace: string;
      repository: string;
      pull_request_id: number;
      title?: string;
      description?: string;
      destination_branch?: string;
      reviewers?: string[];
    } =>
      typeof args === 'object' &&
      args !== null &&
      typeof args.workspace === 'string' &&
      typeof args.repository === 'string' &&
      typeof args.pull_request_id === 'number' &&
      (args.title === undefined || typeof args.title === 'string') &&
      (args.description === undefined || typeof args.description === 'string') &&
      (args.destination_branch === undefined || typeof args.destination_branch === 'string') &&
      (args.reviewers === undefined || Array.isArray(args.reviewers));
  • src/index.ts:102-103 (registration)
    Tool dispatch registration in main server switch statement, routing 'update_pull_request' calls to the PullRequestHandlers.handleUpdatePullRequest method.
    case 'update_pull_request':
      return this.pullRequestHandlers.handleUpdatePullRequest(request.params.arguments);
  • Tool registration in the exported toolDefinitions array used by listTools endpoint.
    {
      name: 'update_pull_request',
      description: 'Update an existing pull request. When updating without specifying reviewers, existing reviewers and their approval status will be preserved.',
      inputSchema: {
        type: 'object',
        properties: {
          workspace: {
            type: 'string',
            description: 'Bitbucket workspace/project key (e.g., "PROJ")',
          },
          repository: {
            type: 'string',
            description: 'Repository slug (e.g., "my-repo")',
          },
          pull_request_id: {
            type: 'number',
            description: 'Pull request ID',
          },
          title: {
            type: 'string',
            description: 'New title (optional)',
          },
          description: {
            type: 'string',
            description: 'New description (optional)',
          },
          destination_branch: {
            type: 'string',
            description: 'New destination branch (optional)',
          },
          reviewers: {
            type: 'array',
            items: { type: 'string' },
            description: 'New list of reviewer usernames/emails. If provided, replaces the reviewer list (preserving approval status for existing reviewers). If omitted, existing reviewers are preserved. (optional)',
          },
        },
        required: ['workspace', 'repository', 'pull_request_id'],
      },
    },
Behavior4/5

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

With no annotations provided, the description carries the full burden. It discloses a key behavioral trait: 'When updating without specifying reviewers, existing reviewers and their approval status will be preserved.' This clarifies a non-obvious side effect of the reviewers parameter, adding valuable context beyond the input schema.

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

Conciseness5/5

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

The description is appropriately sized with two sentences that are front-loaded and zero waste. The first sentence states the core purpose, and the second adds crucial behavioral context, with every sentence earning its place.

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

Completeness3/5

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

For a mutation tool with 7 parameters, no annotations, and no output schema, the description is adequate but has clear gaps. It explains the reviewers behavior well but doesn't cover other aspects like error conditions, permission requirements, or what the tool returns, leaving room for improvement.

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?

Schema description coverage is 100%, so the schema already documents all 7 parameters thoroughly. The description adds minimal parameter semantics beyond the schema, only reinforcing the reviewers behavior. Baseline 3 is appropriate since the schema does the heavy lifting.

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

Purpose5/5

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

The description clearly states the verb 'update' and resource 'existing pull request', making the purpose specific. It distinguishes from sibling tools like create_pull_request (creation) and merge_pull_request (merging), establishing its unique role in modifying existing PRs.

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

Usage Guidelines4/5

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

The description provides clear context for when to use it ('update an existing pull request'), but lacks explicit guidance on when not to use it or alternatives for specific scenarios. It doesn't mention prerequisites like authentication or compare it to tools like get_pull_request for viewing.

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

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/pdogra1299/bitbucket-mcp-server'

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