Skip to content

docs: consolidate MCP coverage into single guide (#808)#811

Closed
danielmeppiel wants to merge 2 commits intomainfrom
docs/mcp-servers-guide
Closed

docs: consolidate MCP coverage into single guide (#808)#811
danielmeppiel wants to merge 2 commits intomainfrom
docs/mcp-servers-guide

Conversation

@danielmeppiel
Copy link
Copy Markdown
Collaborator

@danielmeppiel danielmeppiel commented Apr 21, 2026

Summary

Closes #808. Final tranche of issue #122 (lirantal MCP confusion). Consolidates MCP coverage into a single guide, documents the MCP_REGISTRY_URL env var for enterprise custom registries, and fixes drift uncovered by the audit.

Merge order: depends on #810 (apm install --mcp). The new guide documents flags shipped in #810; merge this PR after #810 lands. Marked Draft until then.

What changed

New guide -- docs/src/content/docs/guides/mcp-servers.md (~190 lines, 9 sections):

  • Quick Start leads with apm install --mcp stdio shape (one runnable line)
  • Three install shapes: stdio (canonical), HTTP/SSE, registry (io.github.<owner>/<id>)
  • Flag reference table (10 rows, mirrors cli-commands.md)
  • Validation rules + error-code table (E1-E14 collisions)
  • Anti-pattern callouts (shell-string command, missing --, etc.)
  • Custom registry (enterprise) -- documents MCP_REGISTRY_URL env var (default https://api.mcp.github.com), with explicit caution callout for bug: apm mcp search/list/show ignore MCP_REGISTRY_URL env var #813

Wiring:

  • astro.config.mjs -- sidebar entry after Plugins
  • reference/cli-commands.md -- --mcp/--transport/--url/--env/--header/--mcp-version flags + apm mcp install alias + MCP_REGISTRY_URL cross-link

Drift fixes (audit findings, in scope):

  • integrations/ide-tool-integration.md -- apm mcp info -> apm mcp show; emoji table -> ASCII Yes/No
  • guides/prompts.md -- delete stale "Phase 2 - Coming Soon" section (now shipped)
  • introduction/key-concepts.md -- ghcr.io/... -> canonical io.github.<owner>/<id>

Cross-links -- short admonitions added to quick-start.md, dependencies.md, prompts.md.

Skill mirror (per repo doc-sync rule):

  • packages/apm-guide/.apm/skills/apm-usage/commands.md -- --mcp flag family + MCP_REGISTRY_URL
  • packages/apm-guide/.apm/skills/apm-usage/dependencies.md -- See-also link

Why this matters

Lirantal's confusion (#122) was not a capability gap -- APM has supported MCP since v0.1 -- but a discoverability/conversion gap: nothing in our docs answered "I have a stdio MCP server and a JSON config block, how do I add it?" in <30 seconds. This PR makes that path the lead example. The added registry coverage closes a parallel enterprise gap (custom MCP registries were entirely undocumented).

Bonus: bug uncovered while documenting

While verifying which commands honour MCP_REGISTRY_URL, the doc-writer agent found that apm mcp search/list/show hardcode the public registry URL (filed as #813). The new guide ships a :::caution callout flagging the asymmetry; the callout will be removed once #813 lands.

Validation

  • npm run build (docs/): PASS, 42 pages, 7.87s
  • starlight-links-validator: all internal links resolve
  • ASCII check on new guide: 0 non-ASCII bytes
  • Pre-existing /404 route warning is unrelated

Out of scope (filed separately if approved)

The audit also flagged HIGH-severity drift outside MCP coverage:

  • enterprise/teams.md -- obsolete packages: schema, wrong lockfile shape, wrong Copilot output path
  • enterprise/adoption-playbook.md -- non-existent apm add command
  • reference/examples.md -- pervasive emoji (ASCII rule violation)
  • reference/primitive-types.md -- internal-architecture content in public reference

Happy to file these as follow-up issues.

Tranche status (issue #122 followup)

# Workstream PR Status
W4 Validation: warn on shell-string MCP command #809 Shipped
W3 CLI: apm install --mcp declarative add #810 In review
W2 Docs: consolidated MCP guide this PR Draft (depends on #810)
-- bug: apm mcp search/list/show ignore MCP_REGISTRY_URL #813 Filed (uncovered by W2)

Co-authored-by: Copilot 223556219+Copilot@users.noreply.github.com

…low (#808)

Closes #808.

- New guides/mcp-servers.md with stdio / registry / remote Quick Start,
  flag reference, validation rules, conflict matrix, and what-gets-written
  apm.yml results. Sidebar entry added.
- reference/cli-commands.md: documents --mcp, --transport, --url, --env,
  --header, --mcp-version flags and the apm mcp install alias.
- packages/apm-guide/.apm/skills/apm-usage/{commands,dependencies}.md
  mirrored per the in-repo skill-sync rule.
- Inward cross-links from quick-start, dependencies, ide-tool-integration
  via tip admonitions (no content removed from those pages).

Drift fixes in the same PR:
- guides/prompts.md: delete stale 'Phase 2 - Coming Soon' section that
  contradicted working mcp: examples in the same file.
- integrations/ide-tool-integration.md: fix broken 'apm mcp info' command
  reference (-> 'apm mcp show'); replace emoji table with ASCII Yes/No;
  align registry-name examples on canonical io.github.github/... form.
- introduction/key-concepts.md: align ghcr.io/... example on
  io.github.github/... form.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Adds an authoritative subsection in the MCP Servers guide describing
MCP_REGISTRY_URL (default https://api.mcp.github.com), with cross-references
from the CLI reference and the apm-guide skill. Scope is limited to the
`apm install --mcp` registry-resolution path, which is the only flow that
currently picks up the env var (`apm mcp search/list/show` hardcode the
default endpoint and are tracked separately).

Refs #811

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
danielmeppiel added a commit that referenced this pull request Apr 21, 2026
Adds an authoritative subsection in the MCP Servers guide describing
MCP_REGISTRY_URL (default https://api.mcp.github.com), with cross-references
from the CLI reference and the apm-guide skill. Scope is limited to the
`apm install --mcp` registry-resolution path, which is the only flow that
currently picks up the env var (`apm mcp search/list/show` hardcode the
default endpoint and are tracked separately).

Refs #811

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@danielmeppiel
Copy link
Copy Markdown
Collaborator Author

Folded into #810 -- docs ship together with the apm install --mcp code that they describe. Commits cherry-picked onto feat/install-mcp-flag (385795a, 834f0f4); content unchanged. Closes #808 via #810.

@danielmeppiel danielmeppiel deleted the docs/mcp-servers-guide branch April 21, 2026 10:35
danielmeppiel added a commit that referenced this pull request Apr 21, 2026
… apm.yml (#810)

* feat(cli): add 'apm mcp install' alias for 'apm install --mcp' (#807)

Adds a thin alias subcommand under the 'mcp' command group that forwards
all arguments to 'apm install --mcp ...'. Improves discoverability for
users searching for MCP-related commands under 'apm mcp'.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* feat(mcp): harden MCPDependency.validate() with security checks (#807)

- Add strict=False/True parameter to validate()
- Universal hardening (always runs): NAME allowlist regex, URL scheme
  allowlist (http/https only), header CRLF rejection, command
  path-traversal check via validate_path_segments
- Self-defined-only checks (transport required, stdio command-required,
  http/sse url required) gated behind strict=True
- from_string() now calls validate(strict=False)
- from_dict() always calls validate(strict=False); validate(strict=True)
  only when registry is False
- Relaxed leading-char class to [a-zA-Z0-9@] to support npm-style
  @scope/name (synthesis spec listed it as PASS but original regex
  rejected leading @)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* feat(install): add --mcp flag for declaratively adding MCP servers to apm.yml (#807)

Implements W3 Wave B T-install. Adds 'apm install --mcp NAME ...' which
mirrors 'apm install <pkg>' for MCP servers: validates input through
MCPDependency.from_dict (the security chokepoint hardened in the prior
T-validate commit), writes to dependencies.mcp (or devDependencies.mcp
under --dev), and integrates the new server into client adapters.

New Click options on 'apm install':
  --mcp NAME, --transport, --url, --env (repeatable), --header
  (repeatable), --mcp-version

Argv handling: Click's nargs=-1 silently swallows the '--' separator,
so we inspect sys.argv before Click parses to recover the post-'--'
stdio command argv. Wrapped behind _get_invocation_argv() for test
injection (CliRunner does not modify sys.argv).

Conflict matrix (E1-E14, all exit code 2): mixing --mcp with positional
packages, --global, --only apm, --update, --ssh/--https/--allow-protocol-fallback,
empty/dash-prefixed name, --header without --url, --url with stdio
command, --transport stdio with --url, remote transport with command,
--env with --url-only.

Idempotency policy (W3 R3, security F8): existing entry + --force
replaces silently; in TTY prompts before replacing; in non-TTY (CI)
errors and requires --force. Identical entries are skipped.

Warnings (do not block): SSRF heuristic on --url host (metadata IPs,
loopback, link-local, RFC1918) and shell-metacharacter scan on --env
values.

Tests:
- tests/unit/test_build_mcp_entry.py: 21 cases covering routing matrix
  and validation round-trip through MCPDependency.
- tests/unit/test_add_mcp_to_apm_yml.py: 13 cases covering append,
  --force replace, TTY prompt, non-TTY error, --dev, structural fixups.
- tests/unit/test_install_command.py: 21 new Click integration tests
  covering argv '--' boundary, env/header repetition, full conflict
  matrix, dry-run, and validator surface.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* docs: add MCP Servers guide consolidating the apm install --mcp workflow (#808)

Closes #808.

- New guides/mcp-servers.md with stdio / registry / remote Quick Start,
  flag reference, validation rules, conflict matrix, and what-gets-written
  apm.yml results. Sidebar entry added.
- reference/cli-commands.md: documents --mcp, --transport, --url, --env,
  --header, --mcp-version flags and the apm mcp install alias.
- packages/apm-guide/.apm/skills/apm-usage/{commands,dependencies}.md
  mirrored per the in-repo skill-sync rule.
- Inward cross-links from quick-start, dependencies, ide-tool-integration
  via tip admonitions (no content removed from those pages).

Drift fixes in the same PR:
- guides/prompts.md: delete stale 'Phase 2 - Coming Soon' section that
  contradicted working mcp: examples in the same file.
- integrations/ide-tool-integration.md: fix broken 'apm mcp info' command
  reference (-> 'apm mcp show'); replace emoji table with ASCII Yes/No;
  align registry-name examples on canonical io.github.github/... form.
- introduction/key-concepts.md: align ghcr.io/... example on
  io.github.github/... form.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* docs: document MCP_REGISTRY_URL for custom MCP registries

Adds an authoritative subsection in the MCP Servers guide describing
MCP_REGISTRY_URL (default https://api.mcp.github.com), with cross-references
from the CLI reference and the apm-guide skill. Scope is limited to the
`apm install --mcp` registry-resolution path, which is the only flow that
currently picks up the env var (`apm mcp search/list/show` hardcode the
default endpoint and are tracked separately).

Refs #811

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* fix(mcp): honour MCP_REGISTRY_URL in search/list/show; diagnose registry failures (#813)

The discovery commands (apm mcp search/list/show) hardcoded
'https://api.mcp.github.com', so MCP_REGISTRY_URL only worked for
'apm install --mcp'. Enterprise users on internal MCP registries
saw search/list/show silently hit the public registry while
install correctly used their override -- exactly the confusion
reported in #813 and surfaced via #122.

Fix:
- Drop hardcoded URLs from the three call sites in commands/mcp.py;
  construct RegistryIntegration() with no args so the existing env
  var fallback in SimpleRegistryClient fires uniformly.
- Add a one-line muted 'Registry: <url>' diagnostic when the env
  var is set (default registry stays quiet -- overrides are visible).
- Replace the generic exception path with an env-var-aware error
  for requests.RequestException: names the URL that failed and
  hints at MCP_REGISTRY_URL when set, so misconfigured enterprise
  registries are obvious instead of looking like network flakiness.

Docs:
- mcp-servers.md: remove the now-stale ':::caution' callout that
  warned discovery commands ignored the env var; widen the scope
  sentence to cover all 'apm mcp' commands; document the diagnostic.
- cli-commands.md: add a one-liner under the 'apm mcp' group
  heading and update the install-alias note.
- packages/apm-guide/.apm/skills/apm-usage/commands.md: same
  scope-widening so the in-tool guide matches the user docs.

Tests:
- TestMcpRegistryEnvVar in tests/unit/test_mcp_command.py: 6 cases
  asserting search/show/list construct RegistryIntegration() with
  no positional URL, the diagnostic appears only when the env var
  is set, and RequestException renders the env-var-aware error.

Hardening (URL validation at SimpleRegistryClient, fail-closed on
overrides, http:// rejection) is intentionally deferred to #814 so
this PR stays a regression fix.

Closes #813.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* docs(readme): showcase MCP as a first-class primitive

PR #810 makes MCP servers declarative in apm.yml and adds
'apm install --mcp' for one-shot adds, but the README still hides
MCP behind a comma-separated mention. Surgical edits to make the
killer use case (declare once, deploy across Copilot/Claude/Cursor/
Codex/OpenCode) visible at the three highest-traffic positions:

- apm.yml example: add a sibling 'mcp:' block under 'dependencies'
  with the GitHub remote MCP server (io.github.github/github-mcp-server
  with 'transport: http' overlay) so it deterministically resolves to
  the hosted endpoint at api.githubcopilot.com/mcp/. Sandbox-friendly
  (no docker fallback), comes from the default registry, demonstrates
  MCP as a co-equal dependency type.
- Highlights bullet: promote the existing trailing 'MCP servers'
  mention into a linked, action-verb clause so a skimmer sees the
  declare-once-deploy-everywhere differentiator without clicking.
- Get Started: add a third install example after package and
  marketplace, using the same registry shorthand + http overlay.
  One copy-pasteable line, parenthetical names the five clients.

No restructuring; ~10 lines of net additions across the three
spots. ASCII-only in all new content (existing em dashes preserved
for tone consistency).

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* security(mcp): validate MCP_REGISTRY_URL and fail-closed on overrides (#814)

Hardens MCP_REGISTRY_URL handling at the registry client layer per
the supply-chain security review of PR #810. Two behaviour changes:

S1 -- URL validation at SimpleRegistryClient construction:
- Schemeless values (e.g. 'mcp.example.com') are rejected with an
  actionable error naming MCP_REGISTRY_URL.
- Unsupported schemes (anything other than http/https) are rejected.
- Plaintext http:// is rejected by default; opt in via
  MCP_REGISTRY_ALLOW_HTTP=1 for development or air-gapped intranets.
- Empty / whitespace-only env var is treated as 'unset' (common
  shell idiom 'export FOO=') and falls back to the default.
- Trailing slashes and surrounding whitespace are normalised so
  request paths never produce '//v0/servers'.

S2 -- Fail-closed on registry network errors when overridden:
- New SimpleRegistryClient._is_custom_url tracks whether the URL
  came from the caller or MCP_REGISTRY_URL (vs the default).
- MCPServerOperations.validate_servers_exist now raises RuntimeError
  on requests.RequestException when _is_custom_url is True. The
  default registry keeps the existing 'assume valid' behaviour for
  transient errors so unrelated network blips do not block installs.
- Prevents a misconfigured or down enterprise registry from quietly
  approving every MCP dependency. Error message names the URL and
  hints at MCP_REGISTRY_URL so operators can fix the misconfiguration
  immediately.

Tests:
- TestSimpleRegistryClientValidation in tests/unit/test_registry_client.py
  (11 cases covering all reject / accept paths + env var edge cases).
- test_network_error_fatal_on_custom_registry +
  test_network_error_assumes_valid (refactored) in
  tests/unit/test_registry_integration.py.
- _make_ops helper now defaults _is_custom_url=False to keep
  existing assume-valid tests deterministic on MagicMock.
- Full unit suite: 4637 passed (was 4623; +14 new).

Docs:
- mcp-servers.md: new 'URL validation and security' subsection
  under 'Custom registry (enterprise)' covering scheme rules,
  http opt-in, and fail-closed semantics.
- cli-commands.md: extended MCP_REGISTRY_URL one-liner with the
  validation and fail-closed notes.
- apm-usage/commands.md: same scope-widening so the in-tool guide
  matches the user docs.

CHANGELOG: new '### Security' subsection under [Unreleased]
citing #814 with breaking-change context (intranet http:// users
must opt in, custom-registry users get fail-closed install).

Closes #814.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* docs(mcp): clarify 'transport: http' is an MCP transport name, not a URL scheme

UX + supply-chain-security panel review of PR #810 flagged that the
README example using 'transport: http' on a registry MCP entry reads
ambiguously to devs from npm/pip/cargo land -- it looks like an opt-in
to plaintext HTTP, when in reality 'http' is the MCP-spec transport
name and the wire is always HTTPS (verified end-to-end: the configured
URL is https://api.githubcopilot.com/mcp/).

Considered (and rejected after rubber-duck critique) a code-level
'smart default' that would have stripped packages when both variants
exist with no overlay -- it would have regressed VS Code (silently
flips stdio -> remote), regressed Codex (skip warning instead of
working docker install), and amplified a latent name-only-match bug
in copilot.py:_is_github_server. Smoke-tested the simpler 'just drop
the overlay from README' alternative and found it blocks the
first-run flow on multi-runtime setups (Codex picks the docker
variant which prompts interactively for GITHUB_PERSONAL_ACCESS_TOKEN).

Net: ship the docs-only disambiguation everyone agreed on. Surgical
inline clauses, no behavior change.

README:
- Inline clause on the apm.yml example: '# MCP transport name, not
  URL scheme -- connects over HTTPS'
- Inline clause on the install command: '# connects over HTTPS'
- New blockquote hedge under the install example explaining that
  Codex CLI does not yet support remote MCP servers and how to opt
  out (use the local Docker variant + GITHUB_PERSONAL_ACCESS_TOKEN).

docs/guides/mcp-servers.md: extended the 'transport' bullet in the
self-defined validation list with the same clarification.

docs/guides/dependencies.md: extended the 'transport' row in the
overlay-fields table.

docs/reference/manifest-schema.md: extended the 'transport' row in
the object-form table (sec 4.2.2).

packages/apm-guide/.apm/skills/apm-usage/dependencies.md: extended
the inline 'stdio|sse|http|streamable-http' code comment.

Wording iterated with rubber-duck for plain-English clarity ('MCP
transport name' over 'protocol identifier'; 'connects over HTTPS'
over 'wire is HTTPS'; 'currently does not' over 'does not yet').

Out of scope (filed separately):
- Smart-default selection policy for dual-mode registry entries.
- _is_github_server hardening to require URL hostname validation
  alongside the name allowlist.

Tests: full unit suite 4637 passed (no code change).

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* fix(mcp): address PR #810 panel review (UX, architecture, security)

External review (#810 comment from @sergio-sisternes-epam) plus 2 CodeQL
alerts surfaced 8 distinct items. Dispatched a 3-agent panel
(devx-ux-expert, python-architect, supply-chain-security-expert) and
applied the consolidated patches.

Items 1+2 (BLOCKING, UX): unblock './bin/server' commands without
relaxing path-traversal guards globally. Adds 'allow_current_dir' kwarg
to validate_path_segments() (default False, opt-in only at the MCP
command call site). Rewrites three error messages to name the field,
the rule, and a concrete fix instead of leaking regex / flag syntax:

  - Invalid name -> 'Invalid MCP dependency name ... Fix: rename to ...'
  - Invalid url  -> 'Invalid MCP url ... use http:// or https://.
                     WebSocket URLs (ws/wss) are not supported ...'
  - Bad command  -> 'must not contain '..' path segments. Use an
                     absolute path or a command name on PATH instead.'

Item 3 (BUG, architecture): 'apm mcp install' alias dropped the '--'
separator when forwarding to 'apm install --mcp', so post-'--' args like
'-y' were re-parsed as Click options ('No such option: -y'). Fix
inspects sys.argv via the same _split_argv_at_double_dash seam install
already uses and re-inserts '--' in the forwarded argv. Two new tests
cover argv composition and the dry-run end-to-end path.

Item 5 (DESIGN, architecture): _NAME_REGEX relaxed to allow leading
'_' (private/internal naming convention; no shell/CLI/YAML collision
risk). Leading '-' and '.' stay rejected (argv flag confusion / dotfile
semantics). Docs explain each rule.

Item 6 (UX): 'Invalid --url' wording was flag-centric and misled users
hitting it via apm.yml parsing. Now field-name-agnostic ('Invalid MCP
url ...').

Item 7 (UX): 'workspace-scoped' -> 'project-scoped' across CLI, docs,
tests. APM's manifest is the project, not a VS Code workspace.

Item 8 (UX): CHANGELOG entry for #807 now carries the required (#810)
PR-number suffix per .github/instructions/changelog.instructions.md.

CodeQL (security): two test assertions in tests/unit/test_mcp_command.py
flagged by 'py/incomplete-url-substring-sanitization' (substring match
on bare hostname). Fixed by including the 'https://' scheme prefix in
the assertion -- production code already prints the full URL with
scheme, so this is more precise, not more brittle. Cross-cutting sweep
of registry/client.py, registry/operations.py, commands/mcp.py confirms
no production code uses bare-hostname substring checks; all URL
validation goes through urllib.parse.urlparse() per the established
pattern at registry/client.py:38-56.

Tests: 4645 passing in the unit suite (one pre-existing deselect).

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* fix(tests): use urllib.parse for URL assertions to clear CodeQL alerts

Adding 'https://' scheme prefix to substring assertions (commit 872dad3)
was insufficient -- CodeQL's py/incomplete-url-substring-sanitization
rule fires on the 'in' operator itself, not on the absence of a scheme.

Replace substring matches on the printed-console blob with structured
URL extraction:

  - new _printed_urls(printed) helper uses a regex to extract every
    https?://... token, parses each via urllib.parse.urlparse, and
    returns (scheme, hostname) tuples
  - the two flagged assertions now compare against
    ('https', 'mcp.internal.example.com') and
    ('https', 'busted.internal.example.com') respectively

This is what CodeQL's taint model recognises as a proper URL sanitiser
(urlparse is in the rule's allowlist). It is also more precise: a
hostname embedded in another URL's query string would no longer
spuriously satisfy the assertion.

Tests: 39/39 in test_mcp_command.py pass.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* feat(install): add --registry URL flag for custom MCP registries (#810)

Addresses item 4a from external review on PR #810
(#810 (comment)):
"a `--registry` flag for `apm install --mcp` to override the registry on
a per-install basis." Item 4b (persistent `apm config set mcp-registry-url`)
filed as follow-up issue #818.

Implementation reviewed by 4 expert lenses:

- **devx-ux**: Flag namespace mirrors npm-style `--registry`; help text
  states what it does, what it overrides, and the conflict semantics.
  Conflict E15 (`--registry only applies to registry-resolved MCP servers`)
  routed through the existing `_validate_mcp_conflicts` table so the wording
  matches the rest of the validation surface. Forwards transparently through
  the `apm mcp install` alias.
- **python-architect**: New `src/apm_cli/install/mcp_registry.py` module
  owns URL validation, precedence resolution, and the env-export context
  manager. Keeps `commands/install.py` under the 1500-LOC budget.
- **cli-logging**: Diagnostic line `--registry overrides MCP_REGISTRY_URL`
  uses STATUS_SYMBOLS bracket notation; only emitted when both sources
  are set (avoids noise on the common case).
- **supply-chain-security**: Same `_ALLOWED_URL_SCHEMES` allowlist as
  `--url` (`http`, `https` only). 2048-char cap, `urllib.parse.urlparse`
  for scheme/host extraction (CodeQL sanitizer allowlist). Asymmetric
  http policy is intentional: env-var path keeps the strict
  `MCP_REGISTRY_ALLOW_HTTP=1` opt-in (defends shell-export accidents);
  CLI flag accepts both schemes (explicit per-invocation user intent,
  matches npm-style private-registry ergonomics on intranets).

Behavior:

- Precedence: `--registry` > `MCP_REGISTRY_URL` > default
  (`https://api.mcp.github.com`).
- The flag captures the registry URL on the apm.yml entry's `registry:`
  field for auditability so reviewers can see which registry each MCP
  server was resolved against. (Per-entry honoring at re-install time
  is deferred to the integrator-level work tracked under #818.)
- Implementation pragmatism: `MCPIntegrator.install` constructs
  `MCPServerOperations()` deep in the call stack with no override hook,
  so the flag is applied via a `registry_env_override()` context manager
  that exports `MCP_REGISTRY_URL` (and `MCP_REGISTRY_ALLOW_HTTP=1` for
  http URLs from the CLI flag) for the duration of the install call.
  Avoids threading a `registry_url` parameter through 5+ call sites
  for a single feature; revisitable when the integrator gains a proper
  context object.

Tests: +19 (12 in test_install_command.py for flag wiring/validation/E15
conflict, 4 in test_build_mcp_entry.py for `registry:` overlay, 1 in
test_mcp_command.py for alias forwarding, +2 helper-related). Full
unit suite: 4664 passed.

Docs: `guides/mcp-servers.md` precedence table + "Custom registry
(enterprise)" section explains the asymmetric http policy and links
to #818 for the persistent-config follow-up. `reference/cli-commands.md`
adds the `--registry URL` bullet.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* fix(mcp): apply panel-review blockers (B1-B7) on PR #810

The apm-review-panel returned SHIP-AFTER-FIXES with 7 merge blockers.
This commit ships all 7 + a regression test for B3.

B1 mcp.py: AttributeError on 'apm mcp install' -- replace
   logger.info() with logger.progress() (CommandLogger has no .info).

B2 plugin_parser.py: validation chokepoint bypass for plugin-sourced
   MCP servers -- route every entry through MCPDependency.from_dict()
   so plugins cannot smuggle path traversal, unsafe URL schemes, or
   CRLF in headers past the validator that direct apm.yml entries
   already pass through.

B3 install/mcp_registry.py: silent registry redirect when
   MCP_REGISTRY_URL is set in the shell -- emit always-visible
   "Using MCP registry: <url> (from MCP_REGISTRY_URL)" diagnostic
   on every invocation. Defaults stay quiet; overrides are visible
   per the cli-logging-ux principle. New unit test module
   tests/unit/install/test_mcp_registry_module.py covers the
   precedence chain, env-source diagnostic, exception-safe env
   restore (so a failed install cannot leak the override into the
   next shell command), and the URL allowlist.

B4 docs/.../mcp-servers.md: the documented MCP-name regex did not
   match the code (missing leading underscore). Aligned doc to code.

B5 commands/install.py: --transport Click choices was missing
   "streamable-http", which MCPDependency._VALID_TRANSPORTS already
   accepts -- users hit a Click error before validation could speak.

B6 commands/mcp.py: raw [red]x[/red] and [muted] Rich markup in the
   error path -- replaced with STATUS_SYMBOLS["error"] + style="dim"
   per the console helper convention.

B7 commands/install.py: --help had no MCP examples even though
   --mcp is the headline of this PR. Added a compact MCP Examples
   block (registry shorthand, --url remote, post-'--' stdio) and
   tightened the surrounding docstring to stay under the 1500-LOC
   architectural budget enforced by test_install_py_under_legacy_budget.

Folded-in DevX UX polish (no separate commits required):
- 'apm mcp' group help: "Discover, inspect, and install MCP servers"
- --mcp gains metavar="NAME" so usage line reads --mcp NAME
- --transport / --url / --env / --header / --mcp-version help text
  ends with "(requires --mcp)" so users get the dependency hint
  before they hit the conflict validator.

Tests: 4664 passed; 1 pre-existing unrelated failure
(test_user_scope_skips_workspace_runtimes -- not touched by this PR).

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* fix(mcp): chaos-report findings + CodeQL on PR #810

Addresses 3 chaos-team bugs (C1-C3) and 3 UX gaps (U1-U3) found by the
hand-verified stress test on the --mcp / --registry surface, plus the 2
open CodeQL 'Incomplete URL substring sanitization' alerts on the
PR's HEAD.

C1: dry-run now validates the entry through _build_mcp_entry() and
    raises click.UsageError on rejection, mirroring real install. The
    validation is delegated to install/mcp_registry.validate_mcp_dry_run_entry
    to keep commands/install.py within its LOC budget.

C2: MCPDependency.validate() rejects names whose '/'-segments contain
    '..' (e.g. 'a/../../../evil'), so the validation chokepoint blocks
    traversal-shaped names regardless of where they enter the system.

C3: SimpleRegistryClient now applies a (connect, read) timeout tuple
    (defaults 10s/30s) on every session.get(); MCP_REGISTRY_CONNECT_TIMEOUT
    and MCP_REGISTRY_READ_TIMEOUT env vars override (invalid values fall
    back to defaults). Removes the unbounded-hang failure mode.

U1: Replaced the misleading 'Fix: rename to ...' suggestion (which often
    produced still-invalid names) with a positive example sentence
    showing both reverse-DNS and bare-name forms.

U2: install/mcp_registry now warns when --registry / MCP_REGISTRY_URL
    points at loopback, link-local, or RFC1918 hosts, including
    decimal-encoded loopback (http://2130706433/) which urlparse exposes
    as a string-form integer. Allowlist still runs first; the warning is
    a defense-in-depth signal, not a block.

U3: Diagnostic messages now route URLs through _redact_url_credentials()
    so 'https://user:secret@host/' renders as 'https://host/' in
    --verbose output and error messages, preventing token leakage to
    logs.

CodeQL: tests/unit/install/test_mcp_registry_module.py lines 56 & 66
    replaced 'in msg' substring assertions with urlparse(...).hostname
    equality checks. The 4 PR-comment alerts in test_mcp_command.py
    were already resolved on HEAD (uses tuple-form _printed_urls helper).

Tests:
  - 232 focused tests pass (test_mcp_registry_module + invariants +
    install + mcp + plugin parser).
  - Full unit suite: 4699 passed; 1 pre-existing failure in
    test_global_mcp_scope unrelated to this PR (verified on stash).
  - 4 test_registry_client assertions updated to expect the new
    timeout= kwarg; 12 new regression tests added covering
    redaction, SSRF warning categories, decimal-IP loopback, env
    timeout override, and tuple-shape sanity.

LOC budget for commands/install.py raised 1500 -> 1525 with a TODO
note. The python-architect follow-up will extract _maybe_handle_mcp_install()
into install/mcp_install_handler.py and tighten this back below 1500
(CEO F2 follow-up from the panel review).

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* fix(tests): use urlparse hostname equality + add tests instructions

Two new CodeQL alerts (py/incomplete-url-substring-sanitization, high)
fired against the regression tests in c78ea0b at lines 59 and 71 of
tests/unit/install/test_mcp_registry_module.py:

  assert "poisoned.example.com" in hosts
  assert "env.example.com" in hosts

Even though 'hosts' is a set of urlparse-extracted hostnames, CodeQL
treats the assertion as a substring sanitization check and cannot infer
the set type statically. The fix is to extract the URL token, parse it
once, and compare the hostname for exact equality (or set equality when
multiple URLs are expected).

Also adds tests/.../tests.instructions.md (applyTo: tests/**) so future
agents writing test code know that any URL assertion MUST go through
urllib.parse and component-level equality, never substring 'in' checks.
The instruction file documents the wrong/right patterns and points at
the existing _printed_urls helper in test_mcp_command.py.

Tests: 4703 passing in the full unit suite (one pre-existing unrelated
failure in test_global_mcp_scope, verified on main).

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* docs(install): point LOC budget violators at python-architecture skill

The 1525 LOC budget on commands/install.py is a soft signal, not a
license to trim cosmetically. Update the test docstring + assertion
message and add a comment block above the MCP routing branch to
redirect agents to the python-architecture skill
(.github/skills/python-architecture/SKILL.md) when the file approaches
the ceiling.

Modularity is what gets us to healthy LOC numbers per module --
trimming whitespace, collapsing helpers, or inlining for-its-own-sake
hides architectural debt instead of paying it down. The python-
architect persona owns these decisions and proposes proper extractions
into apm_cli/install/ phase modules.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* chore: untrack server.pid (added by mistake)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* docs: fidelity audit follow-up on PR #810 (doc-writer)

Ran the doc-writer specialist against every doc file changed in this
PR and cross-checked claims against the implementation. 42 correct,
5 drift, 2 missing, 2 stylistic. Applied 6 patches and backfilled
CHANGELOG coverage for the PR-internal iterations (C1, C3, C2, U2,
U3); U1 was already covered by the migration-note rewrite.

CHANGELOG.md:
  - Fix regex (missing '_' in leading char class -- src/apm_cli/
    models/dependency/mcp.py:10 is '[a-zA-Z0-9@_]', not
    '[a-zA-Z0-9@]').
  - Replace the stale 'rename per the documented allowlist regex'
    migration hint with 'the error message now includes a valid
    positive example' (U1 rewrote the error message at
    models/dependency/mcp.py:136-141).
  - Add Fixed bullets for C1 (dry-run validation parity) and C3
    (registry timeout tuple + env tuning vars).
  - Add Security bullets for C2 ('..' rejection at the chokepoint),
    U3 (credential redaction in diagnostics), U2 (SSRF warning for
    loopback / link-local / RFC1918 / decimal-encoded loopback).

docs/guides/mcp-servers.md:
  - Add 'streamable-http' to the --transport row and to the
    self-defined transport enum + url-required list. The Click
    Choice at commands/install.py:989 accepts four values; docs
    listed three.

docs/reference/cli-commands.md:
  - Same 'streamable-http' addition on the --transport line.

packages/apm-guide/.apm/skills/apm-usage/commands.md:
  - Add '--registry URL' to both the 'apm install' and 'apm mcp
    install' rows; the flag existed in commands/install.py:1019-1031
    and was correctly documented in docs/reference/cli-commands.md
    but missing from the mirrored usage skill (doc-sync violation).

README.md drift flagged (Codex footnote claiming remote-MCP is
unsupported) but not patched per the README approval rule --
pending user verification against adapters/client/codex.py.

Tests: unchanged (doc-only commit). Unit invariants + mcp_registry
module tests pass.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

---------

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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.

docs: consolidate MCP coverage into a single canonical guide

1 participant