merge_pull_request
Merge approved pull requests into target branches using specified strategies like merge-commit, squash, or fast-forward to integrate reviewed code changes.
Instructions
Merge an approved pull request into the target branch. Use this when a PR has been reviewed, approved, and is ready to be integrated. Choose the appropriate merge strategy based on your team's workflow and repository history preferences.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| project | No | Bitbucket project key. If omitted, uses BITBUCKET_DEFAULT_PROJECT environment variable. | |
| repository | Yes | Repository slug containing the pull request. | |
| prId | Yes | Pull request ID to merge. | |
| message | No | Custom merge commit message. If not provided, uses default merge message format. | |
| strategy | No | Merge strategy: "merge-commit" creates a merge commit preserving branch history, "squash" combines all commits into one, "fast-forward" moves the branch pointer without creating a merge commit. |
Implementation Reference
- src/index.ts:722-746 (handler)The primary handler function that executes the merge_pull_request tool logic by making a POST request to Bitbucket's merge endpoint with optional message and strategy.private async mergePullRequest(params: PullRequestParams, options: MergeOptions = {}) { const { project, repository, prId } = params; if (!project || !repository || !prId) { throw new McpError( ErrorCode.InvalidParams, 'Project, repository, and prId are required' ); } const { message, strategy = 'merge-commit' } = options; const response = await this.api.post( `/projects/${project}/repos/${repository}/pull-requests/${prId}/merge`, { version: -1, message, strategy } ); return { content: [{ type: 'text', text: JSON.stringify(response.data, null, 2) }] }; }
- src/index.ts:223-241 (registration)Tool registration in the MCP server's tool list, defining the name, description, and input schema for merge_pull_request.{ name: 'merge_pull_request', description: 'Merge an approved pull request into the target branch. Use this when a PR has been reviewed, approved, and is ready to be integrated. Choose the appropriate merge strategy based on your team\'s workflow and repository history preferences.', inputSchema: { type: 'object', properties: { project: { type: 'string', description: 'Bitbucket project key. If omitted, uses BITBUCKET_DEFAULT_PROJECT environment variable.' }, repository: { type: 'string', description: 'Repository slug containing the pull request.' }, prId: { type: 'number', description: 'Pull request ID to merge.' }, message: { type: 'string', description: 'Custom merge commit message. If not provided, uses default merge message format.' }, strategy: { type: 'string', enum: ['merge-commit', 'squash', 'fast-forward'], description: 'Merge strategy: "merge-commit" creates a merge commit preserving branch history, "squash" combines all commits into one, "fast-forward" moves the branch pointer without creating a merge commit.' } }, required: ['repository', 'prId'] } },
- src/index.ts:226-240 (schema)Input schema definition for the merge_pull_request tool, specifying parameters like project, repository, prId, message, and strategy.inputSchema: { type: 'object', properties: { project: { type: 'string', description: 'Bitbucket project key. If omitted, uses BITBUCKET_DEFAULT_PROJECT environment variable.' }, repository: { type: 'string', description: 'Repository slug containing the pull request.' }, prId: { type: 'number', description: 'Pull request ID to merge.' }, message: { type: 'string', description: 'Custom merge commit message. If not provided, uses default merge message format.' }, strategy: { type: 'string', enum: ['merge-commit', 'squash', 'fast-forward'], description: 'Merge strategy: "merge-commit" creates a merge commit preserving branch history, "squash" combines all commits into one, "fast-forward" moves the branch pointer without creating a merge commit.' } }, required: ['repository', 'prId'] }
- src/index.ts:459-469 (handler)Dispatch handler in the main CallToolRequestSchema switch statement that prepares parameters and calls the mergePullRequest method.case 'merge_pull_request': { const mergePrParams: PullRequestParams = { project: getProject(args.project as string), repository: args.repository as string, prId: args.prId as number }; return await this.mergePullRequest(mergePrParams, { message: args.message as string, strategy: args.strategy as 'merge-commit' | 'squash' | 'fast-forward' }); }