Skip to main content
Glama

protect_branch

Destructive

Set branch protection rules to control who can push, merge, or unprotect a GitLab branch or wildcard pattern.

Instructions

Protect a repository branch (set push/merge/unprotect access levels). Use this to create or update protection rules for a branch or wildcard; use get_protected_branch to inspect existing rules first. The operation changes who may push, merge, or unprotect, may enable force-push or code-owner settings, requires maintainer-level permission, and returns the protection rule or a validation/permission error.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
nameNoDeprecated alias for branch_name; prefer branch_name for consistency
jmespathNoOptional JMESPath expression filtering the JSON result before return.
project_idYesProject ID or complete URL-encoded path to project
branch_nameYesBranch name or wildcard pattern to protect
allow_force_pushNoAllow force push to the protected branch. Default: false
push_access_levelNoAccess level for pushing (0=No access, 30=Developer, 40=Maintainer, 60=Admin). GitLab default applies when omitted.
merge_access_levelNoAccess level for merging (0=No access, 30=Developer, 40=Maintainer, 60=Admin). GitLab default applies when omitted.
unprotect_access_levelNoAccess level for unprotecting (0=No access, 30=Developer, 40=Maintainer, 60=Admin). GitLab default applies when omitted.
code_owner_approval_requiredNoRequire code owner approval before merging (PREMIUM). Default: false

Schema Changelog

Changes observed during successful MCP inspections.

  1. Changed1 schema field changedv2.1.66
    • addedInput schema / properties / jmespath
      Added value: +{
      +  "description": "Optional JMESPath expression filtering the JSON result before return.",
      +  "type": "string"
      +}
  2. Changed7 schema fields changedv2.1.62
    • addedInput schema / properties / merge_access_level / maximum
      Added value: +9007199254740991
    • addedInput schema / properties / merge_access_level / minimum
      Added value: +-9007199254740991
    • addedInput schema / properties / push_access_level / maximum
      Added value: +9007199254740991
    • addedInput schema / properties / push_access_level / minimum
      Added value: +-9007199254740991
    • addedInput schema / properties / unprotect_access_level / maximum
      Added value: +9007199254740991
    • addedInput schema / properties / unprotect_access_level / minimum
      Added value: +-9007199254740991
    • changedInput schema / required
      Previous value: -[
      -  "branch_name"
      -]New value: +[
      +  "project_id",
      +  "branch_name"
      +]
  3. Addedv2.1.21

TDQS

A4.7/5.0
Behavior5/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

The description goes beyond the destructiveHint and openWorldHint annotations by disclosing the permission requirement ('requires maintainer-level permission'), the possible side effects ('may enable force-push or code-owner settings'), and the return format ('returns the protection rule or a validation/permission error'). This adds significant behavioral context that annotations do not convey, and it does not contradict them.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, tightly written paragraph of three sentences. The main purpose is front-loaded, followed by usage guidance and behavioral details. Every sentence adds necessary information with no fluff or repetition.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness5/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's 9 parameters (the schema fully documents them), no output schema, and annotations that already signal destructiveness and open world, the description covers all critical operational aspects: purpose, usage, permission, side effects, and return behavior. An agent has enough information to correctly invoke this tool and interpret the result.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, with each parameter (including access level meanings) already described in the schema. The tool description does not add any parameter-specific semantics beyond what the schema provides, so the baseline of 3 is appropriate. It does not clarify interactions between parameters (e.g., the effect of setting push_access_level to 0), but that is not required given full schema coverage.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool's purpose: 'Protect a repository branch' and specifies the actions (set push/merge/unprotect access levels). It distinguishes from siblings like get_protected_branch by explicitly naming it as the inspection tool, and the name contrasts with unprotect_branch. The scope (branch or wildcard) is also made explicit.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines5/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

It provides explicit when-to-use guidance: 'Use this to create or update protection rules for a branch or wildcard; use get_protected_branch to inspect existing rules first.' This directly routes the agent to the correct sibling and implies this tool is for modification, not inspection. No exclusions are missing.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Deploy Server

Other Tools