Skip to content

Gerrit API JSON response not parsing correctly due to magic prefix #3

@iceleaf916

Description

@iceleaf916

Problem

When calling Gerrit REST API endpoints, the server returns a JSON response prefixed with the security string )]}:

)]}'
{
  "id": "...",
  ...
}

This is a Gerrit security feature to prevent JSON hijacking attacks (Gerrit REST API Documentation). However, the gerrit-mcp-server does not strip this prefix before parsing the JSON, causing JSON parse errors.

Error Message

Error executing tool get_change_details: Expecting value: line 1 column 1 (char 0)

Steps to Reproduce

  1. Configure gerrit-mcp-server with valid Gerrit credentials
  2. Call any REST API endpoint, e.g.:
    mcporter call 'Gerrit.get_change_details(change_id:"324339")'
    
  3. Observe JSON parsing error

Expected Behavior

The MCP server should strip the )]} prefix from Gerrit API responses before parsing the JSON.

Actual Behavior

The MCP server fails to parse the JSON response because of the )]} prefix.

Environment

  • gerrit-mcp-server: used via uvx gerrit-mcp-server
  • Gerrit instance: UnionTech Gerrit (gerrit.uniontech.com)
  • Authentication: HTTP Basic Auth

Possible Fix

Strip the )]} prefix from the response body before JSON parsing, or use the Gerrit CLI/Go library which handles this automatically.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions