opencode icon indicating copy to clipboard operation
opencode copied to clipboard

feat(config): add support for loading MCP configuration from `mcp.json`

Open delafthi opened this issue 5 months ago • 0 comments

This PR adds support for loading MCP configuration from mcp.json files, enabling more flexible and backward-compatible configuration management.

Changes

  • Load MCP configuration from both global (~/.config/opencode/mcp.json) and local (.mcp.json) files.
  • Introduce a new McpConfig namespace dedicated to managing MCP server configurations.
  • Support typed and legacy MCP server formats, validated via Zod schemas to ensure correctness.
  • Implement variable and file expansion supporting {VAR} and {VAR:-default} syntax for enhanced configuration flexibility.
  • Merge global and local MCP configs into the main config state, converting legacy formats to the current structure for backward compatibility.
  • Note: The variable expansion logic currently exists in both mcp.ts and config.ts and could be refactored to reduce duplication.

Additional Notes

This PR was primarily generated by Claude Sonnet 4.

What do you guys think?

delafthi avatar Jul 20 '25 14:07 delafthi