create_pull_request
Create pull requests to propose code changes, request reviews, and merge feature branches in Bitbucket Server repositories. Submit code for review, assign reviewers, and manage branch merges.
Instructions
Create a new pull request to propose code changes, request reviews, or merge feature branches. Use this when you want to submit code for review, merge a feature branch, or contribute changes to a repository. Automatically sets up branch references and can assign reviewers.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| project | No | Bitbucket project key. If omitted, uses BITBUCKET_DEFAULT_PROJECT environment variable. Use list_projects to discover available projects. | |
| repository | Yes | Repository slug where the pull request will be created. Use list_repositories to find available repositories. | |
| title | Yes | Clear, descriptive title for the pull request that summarizes the changes. | |
| description | No | Detailed description of changes, context, and any relevant information for reviewers. Supports Markdown formatting. | |
| sourceBranch | Yes | Source branch name containing the changes to be merged (e.g., "feature/new-login", "bugfix/security-patch"). | |
| targetBranch | Yes | Target branch where changes will be merged (e.g., "main", "develop", "release/v1.2"). | |
| reviewers | No | Array of Bitbucket usernames to assign as reviewers for this pull request. |
Implementation Reference
- src/index.ts:674-701 (handler)The core handler function that executes the create_pull_request tool by making a POST request to the Bitbucket API to create a new pull request with the specified title, description, branches, and reviewers.private async createPullRequest(input: PullRequestInput) { const response = await this.api.post( `/projects/${input.project}/repos/${input.repository}/pull-requests`, { title: input.title, description: input.description, fromRef: { id: `refs/heads/${input.sourceBranch}`, repository: { slug: input.repository, project: { key: input.project } } }, toRef: { id: `refs/heads/${input.targetBranch}`, repository: { slug: input.repository, project: { key: input.project } } }, reviewers: input.reviewers?.map(username => ({ user: { name: username } })) } ); return { content: [{ type: 'text', text: JSON.stringify(response.data, null, 2) }] }; }
- src/index.ts:190-209 (registration)Tool registration in the MCP server, including name, description, and detailed input schema for validation.name: 'create_pull_request', description: 'Create a new pull request to propose code changes, request reviews, or merge feature branches. Use this when you want to submit code for review, merge a feature branch, or contribute changes to a repository. Automatically sets up branch references and can assign reviewers.', inputSchema: { type: 'object', properties: { project: { type: 'string', description: 'Bitbucket project key. If omitted, uses BITBUCKET_DEFAULT_PROJECT environment variable. Use list_projects to discover available projects.' }, repository: { type: 'string', description: 'Repository slug where the pull request will be created. Use list_repositories to find available repositories.' }, title: { type: 'string', description: 'Clear, descriptive title for the pull request that summarizes the changes.' }, description: { type: 'string', description: 'Detailed description of changes, context, and any relevant information for reviewers. Supports Markdown formatting.' }, sourceBranch: { type: 'string', description: 'Source branch name containing the changes to be merged (e.g., "feature/new-login", "bugfix/security-patch").' }, targetBranch: { type: 'string', description: 'Target branch where changes will be merged (e.g., "main", "develop", "release/v1.2").' }, reviewers: { type: 'array', items: { type: 'string' }, description: 'Array of Bitbucket usernames to assign as reviewers for this pull request.' } }, required: ['repository', 'title', 'sourceBranch', 'targetBranch'] } },
- src/index.ts:62-68 (schema)TypeScript interface defining the input structure for the createPullRequest handler, used for type checking.interface PullRequestInput extends RepositoryParams { title: string; description: string; sourceBranch: string; targetBranch: string; reviewers?: string[]; }
- src/index.ts:438-448 (handler)Dispatcher case in the main tool handler that validates input and delegates to the createPullRequest method.case 'create_pull_request': { if (!this.isPullRequestInput(args)) { throw new McpError( ErrorCode.InvalidParams, 'Invalid pull request input parameters' ); } // Ensure project is set const createArgs = { ...args, project: getProject(args.project) }; return await this.createPullRequest(createArgs); }
- src/index.ts:148-159 (helper)Runtime type guard helper function to validate arguments before calling createPullRequest.private isPullRequestInput(args: unknown): args is PullRequestInput { const input = args as Partial<PullRequestInput>; return typeof args === 'object' && args !== null && typeof input.project === 'string' && typeof input.repository === 'string' && typeof input.title === 'string' && typeof input.sourceBranch === 'string' && typeof input.targetBranch === 'string' && (input.description === undefined || typeof input.description === 'string') && (input.reviewers === undefined || Array.isArray(input.reviewers)); }