Skip to content

fix: parse approve/unapprove response with correct schema#368

Open
millerchou wants to merge 1 commit intozereight:mainfrom
millerchou:fix/approve-response-parsing
Open

fix: parse approve/unapprove response with correct schema#368
millerchou wants to merge 1 commit intozereight:mainfrom
millerchou:fix/approve-response-parsing

Conversation

@millerchou
Copy link

Problem

approve_merge_request and unapprove_merge_request fail with:

MCP error -32603: Invalid arguments: approved_by.0.username: Required,
approved_by.0.name: Required, approved_by.0.state: Required,
approved_by.0.web_url: Required

Root Cause

The GitLab POST /approve and POST /unapprove endpoints return the approvals format where approved_by contains nested objects:

{ "approved_by": [{ "user": { "username": "X", "name": "Y", ... } }] }

But approveMergeRequest() and unapproveMergeRequest() parse the response with GitLabMergeRequestApprovalStateSchema, which expects flat user objects:

{ "approved_by": [{ "username": "X", "name": "Y", ... }] }

This worked before because the schema didn't include approved_by. After bfc49de added approved_by to the schema, Zod validation fails on the nested structure.

Fix

Extract a shared parseApprovalsResponse() helper that:

  1. Parses with GitLabMergeRequestApprovalsResponseSchema (correct nested format)
  2. Flattens { user: {...} } to {...}
  3. Returns the unified GitLabMergeRequestApprovalState format

This is the same conversion that getMergeRequestApprovalsFallback() already does correctly — the fix reuses it for approveMergeRequest(), unapproveMergeRequest(), and the fallback itself.

Changes

  • index.ts: 3 call sites updated, 1 new helper function, net +13/-5 lines

The POST /approve and POST /unapprove endpoints return the approvals
format where approved_by contains nested { user: {...} } objects.
However, approveMergeRequest() and unapproveMergeRequest() were
parsing the response directly with GitLabMergeRequestApprovalStateSchema,
which expects flat user objects in approved_by.

This worked before v2.0.32 because the schema didn't include
approved_by field. After bfc49de added approved_by to the schema,
Zod validation fails because it finds { user: { username, ... } }
instead of { username, ... } at the array item level.

Fix by extracting a shared parseApprovalsResponse() that correctly
parses the nested format and converts to the flat format, consistent
with getMergeRequestApprovalsFallback().
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant