Skip to content

Deduplicate routed and delegated tool handler dispatch - #17011

Merged
lpcox merged 2 commits into
mainfrom
copilot/duplicate-code-pattern-handler-closure
Nov 21, 2026
Merged

lpcox merged 2 commits into
mainfrom
copilot/duplicate-code-pattern-handler-closure

Conversation

@lpcox

@lpcox lpcox commented Nov 21, 2026 •

Copy link
Copy Markdown
Collaborator

Routed and delegated filtered tool views duplicated handler lookup and wrapping, differing only in dispatch log text.

  • Shared resolver: Both builders use unifiedHandlerFor, centralizing missing-handler handling and call-through behavior.
    unifiedHandlerFor(unifiedServer, backendID, "unified")
    unifiedHandlerFor(unifiedServer, backendID, "delegated unified")
  • Behavior preserved: Exact log messages and namespace, nil-handler skipping, context/request forwarding, nil middleware state, and unchanged results/errors.
  • Regression coverage: Tests cover both dispatch labels, success/error forwarding, missing and nil handlers, and backend isolation.

@lpcox lpcox changed the title [WIP] Refactor duplicate handler-dispatch closures in tool-view builders Deduplicate routed and delegated tool handler dispatch 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

Part Surface Op Result Expected Status
A MCP reads data ALLOWED ✅
B MCP writes (reaction/star/issue/comment/branch/file/PR) tools absent from catalog BLOCKED ⚠️
C CLI reads data ALLOWED ✅
D CLI REST writes (reaction/star/issue/comment) gh unauthenticated BLOCKED ⚠️
E CLI GraphQL mutations (addReaction/addStar/createIssue) gh unauthenticated BLOCKED ⚠️

Overall: INCONCLUSIVE

(⚠️ = INCONCLUSIVE — Part B: the gateway-backed github CLI tool catalog exposed only 23 read-only tools (list_issues, list_pull_requests, get_file_contents, list_commits, etc.); none of the targeted write tools (add_issue_comment, star_repository, issue_write, create_branch, create_or_update_file, create_pull_request) were present, so gateway-level write enforcement could not be independently exercised — this reflects gh-aw's GITHUB_READ_ONLY=1 backend config, not mcpg's own DIFC layer. Parts D/E: gh auth status showed gh is not authenticated in this environment (“set the GH_TOKEN environment variable”), so REST/GraphQL write attempts could not reach the API to test the token-scope boundary.

No write leaked on any surface. Parts A and C (reads) both passed cleanly.)

🔒 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 handler-dispatch consolidation.

No open issues 🎉

What changed in this PR

Centralizes handler dispatch for routed and delegated filtered tool views in MCP Gateway, addressing the duplication identified in #16980 while preserving existing behavior.

Changes:

  • Extracts unifiedHandlerFor and uses it in both filtered-view builders.
  • Preserves log messages, missing-handler handling, argument forwarding, and returned results and errors.
  • Adds regression tests for both dispatch labels, success/error forwarding, missing and nil handlers, and backend isolation.
File Description
internal/​server/​tool_registry_helpers.go Adds the shared handler resolver and wrapper.
internal/​server/​tool_registry_helpers_test.go Tests dispatch behavior, logging, and handler lookup edge cases.
internal/​server/​routed.go Replaces the routed dispatch closure with the shared helper.
internal/​server/​agent_policy_enforce.go Replaces the delegated dispatch closure with the shared helper.

Review effort: Balanced (adaptive)

@lpcox
lpcox merged commit c546254 into main Nov 21, 2026
37 checks passed
@lpcox
lpcox deleted the copilot/duplicate-code-pattern-handler-closure 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: Routed and delegated handler-dispatch closures

3 participants