Skip to content

feat(config): support repeated --mcp-config flags#29

Draft
ghul0 wants to merge 2 commits intonicobailon:mainfrom
ghul0:feat/repeated-mcp-config-flags
Draft

feat(config): support repeated --mcp-config flags#29
ghul0 wants to merge 2 commits intonicobailon:mainfrom
ghul0:feat/repeated-mcp-config-flags

Conversation

@ghul0
Copy link
Copy Markdown

@ghul0 ghul0 commented Mar 30, 2026

Problem

The adapter only preserved a single --mcp-config value end-to-end even though layered MCP configuration is useful for combining shared and project-specific definitions.

Root Cause

The config loading path still treated --mcp-config as a single string in key wiring points:

  • argv parsing only exposed one path
  • config loading and provenance tracking expected one override path
  • /mcp panel wiring still relied on the stale single-path flow

Fix

  • parse repeated --mcp-config flags from argv in order
  • let loadMcpConfig() merge multiple config files in order before project-local overrides
  • let getServerProvenance() track multiple user config sources
  • update initialization and /mcp panel wiring to use getConfigPathsFromArgv() directly so repeated flags survive end-to-end
  • keep the existing single-path behavior intact when only one config path is provided

Summary

  • add getConfigPathsFromArgv() in utils.ts
  • extend config.ts to accept multiple override paths for config loading and provenance
  • update index.ts, init.ts, and commands.ts to use the repeated-flag path flow
  • add tests for config merging, provenance, argv parsing, and call-site wiring

Testing

Targeted tests for this change

npx vitest run __tests__/config.test.ts __tests__/config-provenance.test.ts __tests__/utils.test.ts __tests__/wiring.test.ts
 RUN  v3.2.4 /tmp/pi-mcp-adapter-pr1

 ✓ __tests__/wiring.test.ts (5 tests) 2ms
 ✓ __tests__/utils.test.ts (10 tests) 3ms
 ✓ __tests__/config-provenance.test.ts (2 tests) 3ms
 ✓ __tests__/config.test.ts (10 tests) 5ms

 Test Files  4 passed (4)
      Tests  27 passed (27)
   Duration  217ms

Maintainer note

upstream/main currently does not track examples/interactive-visualizer/dist/app.html or dist/server.js, so the unrelated __tests__/interactive-visualizer-server.test.ts fails on a full-suite run before this PR's changes are involved.

Tomasz Młynek added 2 commits March 30, 2026 12:22
Allow passing multiple MCP config files in a single invocation:

  pi -e ./index.ts --mcp-config a.json b.json
  pi -e ./index.ts --mcp-config a.json --mcp-config b.json

Changes:
- utils.ts: add getConfigPathsFromArgv() and parseConfigFlag() for
  multi-path argv parsing with tilde expansion
- config.ts: loadMcpConfig() and getServerProvenance() accept
  string | string[] with ordered shallow merge (later file wins)
- index.ts, init.ts, commands.ts: wire all call sites to use
  getConfigPathsFromArgv() for consistent repeated-flag support

Merge strategy:
- mcpServers: shallow merge by key, later file wins
- settings: shallow merge, later wins
- imports: union with dedup
- project config (.pi/mcp.json) overrides all

Missing/invalid files are skipped with a warning.
…Path param

- index.ts: fix runtime error 'earlyConfigPath is not defined' in /mcp command
- commands.ts: remove configOverridePath parameter from openMcpPanel() since
  it now reads argv internally via getConfigPathsFromArgv()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant