Skip to content

Ading local MCP for OpenCode produces wrong config file #768

@mastermakrela

Description

@mastermakrela

Currently, adding the MCP for opencode using:

❯ sv add mcp

┌ Welcome to the Svelte CLI! (v0.9.11)
│
◇ Which client would you like to use?
│ opencode
│
◇ What setup do you want to use?
│ Local
│
◆ Successfully set up add-ons
│
◇ Which package manager do you want to install dependencies with?
│ bun
│
◆ Successfully installed dependencies
│
◇ Successfully formatted modified files
│
└ You're all set!

creates the following configuration:

{
	"$schema": "https://opencode.ai/config.json",
	"mcp": {
		"svelte": {
			"type": "local",
			"command": "npx",
			"args": ["-y", "@sveltejs/mcp"]
		}
	}
}

which leads to the following error:

❯ opencode
Error: Config file at /path/to/project/opencode.json is invalid
↳ Invalid input: expected array, received string mcp.svelte.command
↳ Unrecognized key: "args" mcp.svelte

If we open https://opencode.ai/config.json, we can see that the schema defines the following structure for a local MCP configuration:

"mcp": {
  "description": "MCP (Model Context Protocol) server configurations",
  "type": "object",
  "propertyNames": {
    "type": "string"
  },
  "additionalProperties": {
    "anyOf": [
      {
        "ref": "McpLocalConfig",
        "type": "object",
        "properties": {
          "type": {
            "description": "Type of MCP server connection",
            "type": "string",
            "const": "local"
          },
          "command": {
            "description": "Command and arguments to run the MCP server",
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "environment": {
            "description": "Environment variables to set when running the MCP server",
            "type": "object",
            "propertyNames": {
              "type": "string"
            },
            "additionalProperties": {
              "type": "string"
            }
          },
          "enabled": {
            "description": "Enable or disable the MCP server on startup",
            "type": "boolean"
          },
          "timeout": {
            "description": "Timeout in ms for fetching tools from the MCP server. Defaults to 5000 (5 seconds) if not specified.",
            "type": "integer",
            "exclusiveMinimum": 0,
            "maximum": 9007199254740991
          }
        },
        "required": ["type", "command"],
        "additionalProperties": false
      },
      ...
    ]
  }
}

According to the schema, the correct local configuration should be:

{
	"$schema": "https://opencode.ai/config.json",
	"mcp": {
		"svelte": {
			"type": "local",
			"command": ["npx", "-y", "@sveltejs/mcp"]
		}
	}
}

Steps to Reproduce

  1. Create a new Svelte project:
    sv create
  2. Add the MCP integration:
    sv add mcp
  3. Run opencode.
  4. Observe the error mentioned above.

Expected Behavior

A valid configuration matching the schema should be generated automatically, for example:

"command": ["npx", "-y", "@sveltejs/mcp"]

Actual Behavior

An invalid configuration is generated, causing an error due to command being a string and the presence of an unrecognized args key.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingpkg:addsv add

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions