approve_pull_request
Automate approval of Bitbucket pull requests by specifying workspace, repository, and pull request ID for streamlined code review and PR lifecycle management.
Instructions
Approve a pull request
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| pull_request_id | Yes | Pull request ID | |
| repository | Yes | Repository slug (e.g., "my-repo") | |
| workspace | Yes | Bitbucket workspace/project key (e.g., "PROJ") |
Implementation Reference
- src/handlers/review-handlers.ts:129-169 (handler)The main handler function that validates arguments using isApprovePullRequestArgs, constructs the appropriate Bitbucket API endpoint for Cloud or Server, sends the approval request, and returns a success message or handles errors.async handleApprovePullRequest(args: any) { if (!isApprovePullRequestArgs(args)) { throw new McpError( ErrorCode.InvalidParams, 'Invalid arguments for approve_pull_request' ); } const { workspace, repository, pull_request_id } = args; try { let apiPath: string; if (this.apiClient.getIsServer()) { // Bitbucket Server API - use participants endpoint // Convert email format: @ to _ for the API const username = this.username.replace('@', '_'); apiPath = `/rest/api/latest/projects/${workspace}/repos/${repository}/pull-requests/${pull_request_id}/participants/${username}`; await this.apiClient.makeRequest<any>('put', apiPath, { status: 'APPROVED' }); } else { // Bitbucket Cloud API apiPath = `/repositories/${workspace}/${repository}/pullrequests/${pull_request_id}/approve`; await this.apiClient.makeRequest<any>('post', apiPath); } return { content: [ { type: 'text', text: JSON.stringify({ message: 'Pull request approved successfully', pull_request_id, approved_by: this.username }, null, 2), }, ], }; } catch (error) { return this.apiClient.handleApiError(error, `approving pull request ${pull_request_id} in ${workspace}/${repository}`); } }
- src/tools/definitions.ts:349-369 (schema)JSON Schema definition for the approve_pull_request tool, specifying input parameters: workspace, repository, pull_request_id.name: 'approve_pull_request', description: 'Approve a pull request', 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', }, }, required: ['workspace', 'repository', 'pull_request_id'], }, },
- src/index.ts:124-125 (registration)Registration of the approve_pull_request tool in the main server request handler switch statement, delegating to ReviewHandlers.handleApprovePullRequest.case 'approve_pull_request': return this.reviewHandlers.handleApprovePullRequest(request.params.arguments);
- src/types/guards.ts:186-198 (schema)Type guard function for validating approve_pull_request arguments at runtime, used in the handler.export const isApprovePullRequestArgs = ( args: any ): args is { workspace: string; repository: string; pull_request_id: number; } => typeof args === 'object' && args !== null && typeof args.workspace === 'string' && typeof args.repository === 'string' && typeof args.pull_request_id === 'number';