update_pull_request
Modify an existing pull request's title and description in Bitbucket to reflect code review feedback or updated requirements.
Instructions
Update an existing pull request.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| repository_name | Yes | Name of the repository (repo slug) | |
| pull_request_id | Yes | The ID of the pull request. | |
| title | No | The new title of the pull request. | |
| description | No | The new description of the pull request. |
Implementation Reference
- The main handler function that executes the tool's core logic: validates input, performs a PUT request to the Bitbucket API to update the pull request's title and description, formats a success response with PR details, or returns an error message.export async function updatePullRequest( axiosInstance: AxiosInstance, config: Config, args: any ): Promise<{ content: Array<{ type: string; text: string }> }> { try { const { repository_name, pull_request_id, title, description } = args; if (!repository_name || !pull_request_id) { throw new Error('Repository name and pull request ID are required'); } console.error( `Updating pull request ${pull_request_id} in repository: ${repository_name}` ); const response = await axiosInstance.put<PullRequest>( `/repositories/${config.BITBUCKET_WORKSPACE}/${repository_name}/pullrequests/${pull_request_id}`, { title, description, } ); const pr = response.data; const prDetails = `**Successfully updated PR #${pr.id}: ${pr.title}** - State: ${pr.state} - Author: ${pr.author.display_name} - Source: ${pr.source.branch.name} - Destination: ${pr.destination.branch.name} - URL: ${pr.links.html.href}`; return { content: [ { type: 'text', text: prDetails, }, ], }; } catch (error) { console.error('Error updating pull request:', error); return { content: [ { type: 'text', text: `Error updating pull request: ${ error instanceof Error ? error.message : 'Unknown error' }`, }, ], }; } }
- The tool schema defining the name 'update_pull_request', description, and input schema with required fields repository_name and pull_request_id, optional title and description.export const updatePullRequestTool = { name: 'update_pull_request', description: 'Update an existing pull request.', inputSchema: { type: 'object', properties: { repository_name: { type: 'string', description: 'Name of the repository (repo slug)', }, pull_request_id: { type: 'string', description: 'The ID of the pull request.', }, title: { type: 'string', description: 'The new title of the pull request.', }, description: { type: 'string', description: 'The new description of the pull request.', }, }, required: ['repository_name', 'pull_request_id'], }, };
- src/index.ts:66-68 (registration)Import statement bringing in the handler function and tool schema from the implementation file.updatePullRequest, updatePullRequestTool, } from './tools/pull-requests/updatePullRequest.js';
- src/index.ts:111-135 (registration)Registration of the tool schema in the listTools request handler, adding updatePullRequestTool to the available tools list.this.server.setRequestHandler(ListToolsRequestSchema, async () => ({ tools: [ // Repositories listRepositoriesTool, getRepositoryDetailsTool, // Commits listCommitsTool, getCommitTool, // Branching Model updateRepositoryBranchingModelSettingsTool, updateProjectBranchingModelSettingsTool, listBranchRestrictionsTool, getBranchRestrictionTool, // Projects getProjectTool, listDefaultReviewersTool, // Pull Requests listPullRequestsTool, getPullRequestTool, createPullRequestTool, updatePullRequestTool, // Workspaces listWorkspacesTool, ], }));
- src/index.ts:169-173 (registration)Mapping of the tool name 'update_pull_request' to its handler function in the CallToolRequest handler's dispatch map.create_pull_request: createPullRequest, update_pull_request: updatePullRequest, // Workspaces list_workspaces: listWorkspaces, };