feat: support ${input:...} variable resolution for self-defined MCP servers#344
Conversation
…ervers (microsoft#342) Scan headers and env values in self-defined MCP server configs for ${input:<id>} patterns and auto-generate matching input variable definitions in .vscode/mcp.json. For adapters that don't support input prompts (Copilot CLI, Codex CLI, Cursor, OpenCode), emit a warning when ${input:...} references are detected. Changes: - vscode.py: add _extract_input_variables() helper, call from _format_server_config() for _raw_stdio env and remote headers - base.py: add _warn_input_variables() static method - copilot.py: call _warn_input_variables() for _raw_stdio env and remote headers (inherited by Cursor and OpenCode) - codex.py: call _warn_input_variables() for _raw_stdio env - tests: 11 new tests covering extraction, dedup, end-to-end, and warning paths
There was a problem hiding this comment.
Pull request overview
Adds support for VS Code-style ${input:...} placeholders in MCP server configs by extracting them from self-defined server env/headers and generating inputs entries for .vscode/mcp.json, while warning users when configuring MCP servers for runtimes that can’t resolve these prompts (Copilot/Codex).
Changes:
- VS Code adapter: extract
${input:...}references from env/headers and add correspondinginputsdefinitions tomcp.json. - Base adapter: introduce
_warn_input_variables()helper; Copilot/Codex adapters call it for env/headers where applicable. - Unit tests: cover extraction, config update behavior, and warning emission.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/unit/test_vscode_adapter.py | Adds unit tests for input-variable extraction, VS Code inputs generation, and base warning behavior. |
| src/apm_cli/adapters/client/vscode.py | Implements ${input:...} scanning and includes extracted variables in VS Code mcp.json inputs. |
| src/apm_cli/adapters/client/base.py | Adds shared warning helper for runtimes that don’t support VS Code input prompts. |
| src/apm_cli/adapters/client/copilot.py | Emits warnings when ${input:...} placeholders appear in env/headers (unsupported by runtime). |
| src/apm_cli/adapters/client/codex.py | Emits warnings when ${input:...} placeholders appear in env (unsupported by runtime). |
You can also share your feedback on Copilot code review. Take the survey.
| class TestWarnInputVariables(unittest.TestCase): | ||
| """Tests for _warn_input_variables on adapters that don't support input prompts.""" | ||
|
|
||
| def test_warning_emitted_for_input_reference(self, ): |
There was a problem hiding this comment.
Good catch — the trailing comma/whitespace is a leftover from editing. Will clean it up in the next push when terminal is available.
src/apm_cli/adapters/client/base.py
Outdated
| for value in mapping.values(): | ||
| if not isinstance(value, str): | ||
| continue | ||
| for match in _INPUT_VAR_RE.finditer(value): | ||
| print( | ||
| f"[!] Warning: ${{input:{match.group(1)}}} in server " |
There was a problem hiding this comment.
Fixed — added seen set to deduplicate by variable id within a single call. See commit f62b22d.
| _INPUT_VAR_RE = re.compile(r"\$\{input:([^}]+)\}") | ||
|
|
||
| def _extract_input_variables(self, mapping, server_name): |
There was a problem hiding this comment.
Fixed — removed the duplicate class-level _INPUT_VAR_RE and now import the shared _INPUT_VAR_RE from base.py. Also removed the unused import re from vscode.py. See commit f62b22d.
| """Scan dict values for ${input:...} references and return input variable definitions. | ||
|
|
||
| Args: | ||
| mapping (dict): Header or env dict whose values may contain | ||
| ``${input:<id>}`` placeholders. | ||
| server_name (str): Server name used in the description field. | ||
|
|
||
| Returns: | ||
| list[dict]: Input variable definitions (``promptString``, ``password: true``). | ||
| Duplicates within *mapping* are already deduplicated. | ||
| """ |
Description
Support
${input:...}variable resolution for self-defined MCP server headers and env values. When users write${input:my-token}in headers or env of a self-defined server, APM now auto-generates matching input variable definitions in.vscode/mcp.json.For runtimes that don't support input prompts (Copilot CLI, Codex CLI, Cursor, OpenCode), a warning is emitted so users know their placeholders won't be resolved.
Fixes #342
Type of change
Testing