Skip to content

Extract shared allowlist filtering for tools and prompts - #17012

Merged
lpcox merged 2 commits into
mainfrom
copilot/duplicate-code-allowlist-filter-log
Nov 21, 2026
Merged

lpcox merged 2 commits into
mainfrom
copilot/duplicate-code-allowlist-filter-log

Conversation

@lpcox

@lpcox lpcox commented Nov 21, 2026 •

Copy link
Copy Markdown
Collaborator

Tool and prompt registration duplicated the same in-place allowlist filter but handled empty sets differently.

  • Shared filter: Add generic util.FilterByAllowlist, preserving item order and backing-array reuse while returning the removal count.
  • Consistent semantics: Skip filtering for empty per-server sets in both paths, matching the configuration builder’s unrestricted-access contract.
  • Logging: Retain caller-specific tags and original kept/total counts.
  • Regression coverage: Cover empty sets, subsets, no matches, false entries, order, duplicates, and pointer preservation.
kept, removed := util.FilterByAllowlist(listResult.Tools, allowedSet,
	func(tool backendToolDefinition) string { return tool.Name })

@lpcox lpcox changed the title [WIP] Refactor duplicate allowlist filter and log patterns Extract shared allowlist filtering for tools and prompts Nov 21, 2026
@lpcox
lpcox marked this pull request as ready for review November 21, 2026 16:50
Copilot AI adaptive review requested due to automatic review settings November 21, 2026 16:50
@github-actions

Copy link
Copy Markdown
Contributor

🔒 mcpg Read-Only Stress — default

Surface coverage: MCP tool calls + proxied CLI (REST) + GraphQL mutations
Isolation runtime: default (standard AWF container isolation)

Part Surface Op Result Expected Status
A MCP reads (list_issues, list_pull_requests, get_file_contents, list_commits) data returned ALLOWED ✅
B MCP writes (add_issue_comment/star_repository/issue_write/create_branch/create_or_update_file/create_pull_request) all 6 absent from the 23-tool catalog BLOCKED ⚠️
C CLI reads (same 4 ops via proxied github CLI) data returned ALLOWED ✅
D CLI REST writes (reaction/star/issue/comment) not attempted — gh unauthenticated BLOCKED ⚠️
E CLI GraphQL mutations (addReaction/addStar/createIssue) not attempted — gh unauthenticated BLOCKED ⚠️

Overall: INCONCLUSIVE

No writes leaked through either surface. Part B is INCONCLUSIVE because the backend GitHub MCP server runs with GITHUB_READ_ONLY=1 (gh-aw framework default), so write tools never appear in the catalog — this proves backend config, not mcpg's own DIFC/guard enforcement layer (covered separately by internal/guard/internal/difc unit tests). Parts D/E are INCONCLUSIVE because gh auth status showed no authenticated host and GH_TOKEN was unset, so REST/GraphQL write attempts failed on auth before reaching GitHub's API — the token-scope boundary could not be independently exercised this run.

🔒 mcpg read-only stress (default AWF runtime) by Read-Only Stress: default runtime

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

No active review issues are reported for the shared allowlist-filtering change.

No open issues 🎉

What changed in this PR

This PR removes duplicated allowlist filtering from MCP Gateway’s tool and prompt registration, addressing #16981 and aligning empty-set behavior.

Changes:

  • Adds a generic in-place filter that preserves order, reuses the backing array, and returns the removal count.
  • Uses the shared helper for tools and prompts while retaining caller-specific logging and treating empty per-server sets as unrestricted.
  • Adds regression coverage for filtering semantics, ordering, duplicates, and pointer preservation.
File Description
internal/​util/​collections.go Adds the shared FilterByAllowlist helper.
internal/​util/​collections_test.go Tests filter edge cases and backing-array reuse.
internal/​server/​tool_registry.go Integrates the helper and aligns empty-set handling.
internal/​server/​register_tools_from_backend_test.go Adds tool-registration allowlist coverage.
internal/​server/​register_prompts_test.go Expands prompt-registration allowlist coverage.

Review effort: Balanced (adaptive)

@lpcox
lpcox merged commit 14f6b68 into main Nov 21, 2026
36 checks passed
@lpcox
lpcox deleted the copilot/duplicate-code-allowlist-filter-log branch November 21, 2026 16:58
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.

[duplicate-code] Duplicate Code Pattern: Allowlist filter-and-log in tool and prompt registration

3 participants