Skip to content

feat: support ${input:...} variable resolution for self-defined MCP servers#344

Merged
danielmeppiel merged 4 commits intomicrosoft:mainfrom
sergio-sisternes-epam:feat/342-input-variable-resolution
Mar 17, 2026
Merged

feat: support ${input:...} variable resolution for self-defined MCP servers#344
danielmeppiel merged 4 commits intomicrosoft:mainfrom
sergio-sisternes-epam:feat/342-input-variable-resolution

Conversation

@sergio-sisternes-epam
Copy link
Collaborator

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

  • New feature

Testing

  • Tested locally
  • All existing tests pass (1922 passed)
  • Added tests for new functionality (11 new tests)

…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
@sergio-sisternes-epam sergio-sisternes-epam marked this pull request as ready for review March 17, 2026 11:05
Copilot AI review requested due to automatic review settings March 17, 2026 11:05
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 corresponding inputs definitions to mcp.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, ):
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch — the trailing comma/whitespace is a leftover from editing. Will clean it up in the next push when terminal is available.

Comment on lines +106 to +111
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 "
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed — added seen set to deduplicate by variable id within a single call. See commit f62b22d.

Comment on lines +333 to +335
_INPUT_VAR_RE = re.compile(r"\$\{input:([^}]+)\}")

def _extract_input_variables(self, mapping, server_name):
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +336 to +346
"""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.
"""
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call — documentation for this feature is tracked separately in #343 (which depends on #342). We'll address the docs update in a follow-up PR once this lands.

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.

[FEATURE] Support ${input:...} variable resolution for self-defined MCP server headers and env

3 participants