Stu Mason
Stu Mason

Activity

Issue Opened

Issue #163 opened: JSON.parse error when /api/v1/version returns plain text (Coolify 4.0.0-beta.474)

Description

The MCP server fails with the following error when attempting to fetch the Coolify version or perform other operations: SyntaxError: Unexpected non-whitespace character after JSON at position 4 (line 1 column 5)

This occurs because some versions of Coolify (specifically 4.0.0-beta.474) return the version number as a raw string (e.g., 4.0.0-beta.474) from the /api/v1/version endpoint, while the CoolifyClient.request method attempts to JSON.parse the response text unconditionally if it is not empty.

Steps to Reproduce

  1. Connect to a Coolify instance (v4.0.0-beta.474).
  2. Run any tool that initializes the client (e.g., get_infrastructure_overview).
  3. Observe the parsing error.

Proposed Fix

Modify src/lib/coolify-client.ts to check the Content-Type header before parsing.

      const text = await response.text();
      const contentType = response.headers.get('Content-Type');
      let data: any = {};

      if (text) {
        if (contentType?.includes('application/json')) {
          try {
            data = JSON.parse(text);
          } catch (e) {
            data = text;
          }
        } else {
          data = text;
        }
      }

I have verified this fix locally, and it resolves the issue.