Skip to content

Centralize tool-name prefix handling - #16949

Merged
lpcox merged 2 commits into
mainfrom
copilot/duplicate-code-fix-separator
Nov 20, 2026
Merged

lpcox merged 2 commits into
mainfrom
copilot/duplicate-code-fix-separator

Conversation

@lpcox

@lpcox lpcox commented Nov 20, 2026 •

Copy link
Copy Markdown
Collaborator

Server and middleware code duplicate the ___ separator for building, stripping, and recognizing prefixed names.

  • Shared helpers: Export util.ToolNameSeparator; add PrefixToolName and StripToolPrefix.
  • Callers: Use the helpers for tool/prompt registration, backend lookup, policy identity, system tools, and logging.
  • Semantics: Strip only one exact server prefix; preserve embedded separators and unmatched names. Retain middleware’s sys___ recognition.
util.PrefixToolName("github", "owner___search")             // "github___owner___search"
util.StripToolPrefix("github", "github___owner___search")  // "owner___search"

@lpcox lpcox changed the title [WIP] Fix hard-coded tool-name separator in server package Centralize tool-name prefix handling Nov 20, 2026
@lpcox
lpcox marked this pull request as ready for review November 20, 2026 20:42
Copilot AI adaptive review requested due to automatic review settings November 20, 2026 20:42
@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 AWF (normal container isolation)

Part Surface Op Result Expected Status
A MCP reads data ALLOWED ✅
B MCP writes (reaction/star/issue/comment/branch/file/PR) refused (unknown tool) BLOCKED ⚠️
C CLI reads data ALLOWED ✅
D CLI REST writes (reaction/star/issue/comment) not attempted BLOCKED ⚠️
E CLI GraphQL mutations (addReaction/addStar/createIssue) not attempted BLOCKED ⚠️

Overall: INCONCLUSIVE

⚠️ Part B: all 6 write tools (add_issue_comment, star_repository, issue_write, create_branch, create_or_update_file, create_pull_request) were absent from the exposed 23-tool catalog — refusal was -32602 unknown tool, which only proves backend config (gh-aw's GITHUB_READ_ONLY=1), not the gateway's own DIFC/guard blocking layer.

⚠️ Parts D/E: gh auth status showed not authenticated ("not logged into any GitHub hosts"), so REST/GraphQL writes could not be attempted — token-scope boundary unverified this run.

No writes leaked. No reaction/star/issue/comment/branch/file/PR was created.

🔒 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 remain for the refactor centralizing backend-prefixed name handling in shared helpers.

No open issues 🎉

What changed in this PR

Centralizes backend-prefixed name handling in shared utility helpers, addressing the duplication described in #16904 across server registration, lookup, policy checks, and middleware.

Changes:

  • Exports ToolNameSeparator and adds helpers to build names and strip one exact server prefix.
  • Replaces duplicated prefix handling while preserving embedded separators, unmatched names, and middleware’s sys___ recognition.
  • Adds regression coverage for prefix edge cases and handler lookup.
File Description
internal/​util/​format_tool.go Defines shared separator and prefix helpers.
internal/​util/​format_test.go Tests prefix construction, stripping, and edge cases.
internal/​server/​unified_test.go Tests embedded prefixes and unmatched names.
internal/​server/​unified_lifecycle.go Uses helpers for backend tool listing and handler lookup.
internal/​server/​tool_registry.go Uses helpers for tool, prompt, and system-tool registration.
internal/​server/​tool_name_test.go Extends name-preservation and handler tests.
internal/​server/​routed.go Uses the shared builder in missing-handler logs.
internal/​server/​agent_policy_enforce.go Uses helpers for policy identity and logging.
internal/​middleware/​jqschema.go Uses the shared builder to recognize system tools.
internal/​middleware/​jqschema_test.go Covers system-prefix recognition edge cases.

Review effort: Balanced (adaptive)

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: Hard-coded Tool-Name Separator Instead of Shared Helper

3 participants