Read and write PR comments with the GitLab and Bitbucket MCP servers
Part of the Software Factory series, a pattern by Greg Alton. Review is the second-to-last station on the line. Here the factory reads the published pull request (called a merge request on GitLab), posts a structured review, fixes findings one at a time, and leaves a written disposition, all through MCP.
- Time
- About 30 minutes
- Checked
If a button name on the screen does not match this guide, follow the action. These products rename buttons often. This is an advanced guide: it uses code, and each technical term is explained the first time it appears. Model names and prices change, so check the linked docs before you ship.
Steps
Connect GitLab
GitLab has a built-in MCP server at
/api/v4/mcpon your GitLab instance (for GitLab.com,https://gitlab.com/api/v4/mcp). It signs in with OAuth on first use. A header can limit which toolsets the agent sees:{ "mcpServers": { "gitlab": { "type": "http", "url": "https://gitlab.com/api/v4/mcp", "headers": { "X-Gitlab-Enabled-Mcp-Server-Toolsets": "core" } } } }Useful tools include
get_merge_request,get_merge_request_diffs,get_merge_request_notes,save_note, andsave_merge_request_review. Check GitLab's tools page for the current toolset names.Connect Bitbucket Cloud
Bitbucket Cloud tools come through the same Atlassian Rovo MCP server as Jira (
https://mcp.atlassian.com/v2/mcp). The workspace must be linked to an Atlassian organization, and at launch the Bitbucket tools required API-token authentication (scopesread:bitbucket:agent-interfaceandwrite:bitbucket:agent-interface) enabled by an org admin. Check Atlassian's docs for the current auth options. Tools include pull request get, diff, comments, and add comment.Deny merge tools everywhere
Both servers include a merge tool (
accept_merge_requeston GitLab,mergeBitbucketRepoPullRequeston Bitbucket). Block them in your MCP client's tool permissions so no agent can merge, whatever its prompt says. Give Git host tools only to the orchestrator (to open the PR after you approve) and the two review agents.Post one structured review
--- name: pr-code-reviewer description: Reads a published PR/MR diff and posts ONE structured review comment. Never edits code. model: opus --- 1. Resolve the PR/MR for the current branch. Read the complete diff and the tests that cover it. If you can't read it, stop. 2. Run the repo's checks and security scan. Never claim a pass you didn't run. 3. Post exactly one comment: ## Code Review (findings with file:line, severity, why) ## Security Review ### Verification (commands + results) Never modify files, commit, push, or merge.Fix one finding per cycle
--- name: pr-review-fixer description: Triages the latest review and prepares ONE tested fix, then waits for approval. model: opus --- 1. Read the live review comment. Sort every finding: Fix, Waive (with evidence), or Defer (with follow-up ticket). 2. Take the highest-severity Fix. If behavior changes, write a failing test first, then the minimal fix. Run tests. 3. STOP. Return "READY_FOR_APPROVAL: F1 — title", the diff summary, test results, and the proposed commit message. 4. Commit and push only after the developer approves this finding. 5. When no Fix items remain, post the Review Disposition Report.Post the Review Disposition Report
Every review round ends with a durable comment on the PR that accounts for every finding:
## Review response — Accept / Partial / Reject Follow-up to review comment <id>, verified on <branch> @ <sha>. ### Accept (fixed) | Finding | Action | | --- | --- | | Missing input validation | Fixed. Added check + test. Commit abc123. | ### Partial (scoped / deferred) | Finding | Response | | --- | --- | | _none_ | | ### Reject (incorrect or N/A) | Finding | Counter | | --- | --- | | _none_ | | ### Verification <exact commands and results>
Tips
Keep the review format identical on GitLab and Bitbucket. Only the tool calls differ.
If the MCP server is missing or unauthorized, the agent should stop and tell you, not fall back to tokens in shell commands.
Let the PR pipeline finish between fix cycles, then have the fixer re-read the live comments.
Common questions
Can I use GitHub instead?
Yes. GitHub has an official MCP server with similar PR tools. The review and disposition formats stay the same.
Why only one fix per cycle?
Small, separately approved commits are easy to review and easy to revert. Batching fixes hides mistakes.
Inline comments or one big comment?
The pattern uses one structured comment by default so it's easy to find and reference. Ask for inline comments when a finding is tied to a specific line.
More guides
AdvancedClaudeBuilding
Call the Claude API in Python and cut costs with prompt caching
Get an API key, make your first Claude Messages API call in Python, then add prompt caching so repeated long prompts cost less and run faster.
About 30 minutes using Claude Console, Claude API docs
AdvancedClaudeBuilding
Build your first MCP server in Python and use it in Claude Desktop
Write a small Model Context Protocol server with the official Python SDK, expose a tool, and connect it to Claude Desktop so Claude can call it.
About 35 minutes using MCP docs, Claude Desktop
AdvancedGrokBuilding
Build a simple RAG pipeline with the xAI Grok API
Answer questions from your own documents: split them into chunks, retrieve the best matches, and have Grok answer with citations via the xAI API.
About 40 minutes using xAI API docs, xAI Console
Occasional notes
Hear when a new guide is up
A short note when a guide is added. No account, and no emails until this form is connected to a real list.