Skip to content

Feature Request: Support comments in JSON configuration files (JSONC) #124

@GoCoder7

Description

@GoCoder7

Describe the Feature

Currently, pi-mcp-adapter throws a SyntaxError when reading configuration files such as mcp.json or .mcp.json if they contain:

  • line comments (//)
  • block comments (/* ... */)
  • trailing commas after the last item in an object or array

Many developers use JSONC-style config files to document environment variables, explain CLI arguments, or temporarily disable servers. In the VS Code and Claude Desktop ecosystem, this is a common and expected format.

It would be very helpful if pi-mcp-adapter could accept JSON files with comments and trailing commas.

Current Behavior

The adapter reads configuration files in config.ts and parses them directly with JSON.parse():

JSON.parse(readFileSync(configPath, "utf-8"))

Because of this, files with comments or trailing commas fail with errors like:

  • SyntaxError: Unexpected token / in JSON at position ...
  • SyntaxError: Unexpected token } in JSON at position ...

Proposed Solution

Strip comments and trailing commas from the raw file string before parsing it.

A lightweight and proven option is strip-json-comments, using its trailingCommas: true option.

Example:

import stripJsonComments from "strip-json-comments";

const rawConfig = readFileSync(configPath, "utf-8");
const config = JSON.parse(stripJsonComments(rawConfig, { trailingCommas: true }));

Additional Context

  • This would improve the experience for users migrating from other MCP hosts like Cursor or VS Code, where commented config files are common.
  • It would prevent unnecessary crashes when teams share .mcp.json files in repositories.
  • Supporting both comments and trailing commas makes the config format much more practical for hand-edited files.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions