Skip to content

fix(claude-plugin): use plugin-scoped MCP tool prefix in UserPromptSubmit hint#642

Open
cristdar17 wants to merge 1 commit into
Gentleman-Programming:mainfrom
cristdar17:fix/claude-plugin-tool-prefix
Open

fix(claude-plugin): use plugin-scoped MCP tool prefix in UserPromptSubmit hint#642
cristdar17 wants to merge 1 commit into
Gentleman-Programming:mainfrom
cristdar17:fix/claude-plugin-tool-prefix

Conversation

@cristdar17

@cristdar17 cristdar17 commented Jul 20, 2026

Copy link
Copy Markdown

Problem

The UserPromptSubmit hook (plugin/claude-code/scripts/user-prompt-submit.ps1 / .sh) emits a first-turn hint telling the agent to run:

ToolSearch select:mcp__engram__mem_save,mcp__engram__mem_search,...

But when engram is installed as a Claude Code plugin (via the marketplace), the MCP server is registered with the plugin-scoped prefix, so the actual tool names are mcp__plugin_engram_engram__mem_*. The select: query matches nothing and the agent cannot load the memory tools from the hint.

internal/setup/setup.go already handles both prefixes for the permissions allowlist — only the plugin hook scripts were left on the old prefix.

Fix

Replace mcp__engram__ with mcp__plugin_engram_engram__ in both claude-code hook scripts (2 lines).

Notes

  • plugin/codex/scripts/user-prompt-submit.sh also references mcp__engram__ — left untouched since Codex tool naming may differ; happy to update it here too if the same prefix applies.
  • Verified locally on Windows 11 + Claude Code with the plugin installed from the marketplace: the corrected select: list loads all 13 tools.

Summary by CodeRabbit

  • Bug Fixes
    • Updated tool-loading guidance so memory tools can be discovered and invoked correctly.
    • Applied the fix consistently across supported command-line environments.

…bmit hint

The hook's ToolSearch hint listed tools as mcp__engram__mem_*, but when
engram is installed as a Claude Code plugin the MCP server is registered
with the plugin-scoped prefix mcp__plugin_engram_engram__mem_*. The
select: query therefore matched nothing and agents could not load the
memory tools from the hint.
Copilot AI review requested due to automatic review settings July 20, 2026 16:05
@coderabbitai

coderabbitai Bot commented Jul 20, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

Claude Code prompt hook scripts now direct ToolSearch to use the plugin-qualified Engram MCP tool identifiers instead of the previous namespace. Other prompt handling and script behavior remain unchanged.

Changes

Claude Code tool selection

Layer / File(s) Summary
Update ToolSearch identifiers
plugin/claude-code/scripts/user-prompt-submit.ps1, plugin/claude-code/scripts/user-prompt-submit.sh
ToolSearch guidance now references mcp__plugin_engram_engram__mem_* identifiers in both script variants.

Estimated code review effort: 1 (Trivial) | ~2 minutes

Suggested labels: type:bug

Suggested reviewers: copilot, gentleman-programming, alan-thegentleman

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: switching UserPromptSubmit to the plugin-scoped MCP tool prefix.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@plugin/claude-code/scripts/user-prompt-submit.ps1`:
- Line 22: Preserve UTF-8 encoding for the non-ASCII message assigned to
$message in the user-prompt submission script by saving the file with a UTF-8
BOM. Do not alter the system message text or require a PowerShell 7+ runtime.

In `@plugin/claude-code/scripts/user-prompt-submit.sh`:
- Line 59: The ToolSearch payload in the prompt submission script hardcodes the
plugin MCP namespace, violating the existing contract. Update the command to
derive each tool identifier from the script’s current MCP server ID, preserving
the listed tool names and mem_context follow-up behavior without embedding
mcp__plugin_engram_engram__.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: bc03bb92-0f7f-4733-8183-f0cbfeb96795

📥 Commits

Reviewing files that changed from the base of the PR and between 763a6ba and 4188520.

📒 Files selected for processing (2)
  • plugin/claude-code/scripts/user-prompt-submit.ps1
  • plugin/claude-code/scripts/user-prompt-submit.sh


function Write-ToolSearchMessage {
$message = "CRITICAL FIRST ACTION — Execute this ToolSearch NOW before responding to the user:`nselect:mcp__engram__mem_save,mcp__engram__mem_search,mcp__engram__mem_context,mcp__engram__mem_session_summary,mcp__engram__mem_session_start,mcp__engram__mem_session_end,mcp__engram__mem_get_observation,mcp__engram__mem_suggest_topic_key,mcp__engram__mem_capture_passive,mcp__engram__mem_save_prompt,mcp__engram__mem_update,mcp__engram__mem_current_project,mcp__engram__mem_judge`n`nAfter loading tools, call mem_context to check for prior session history before responding."
$message = "CRITICAL FIRST ACTION — Execute this ToolSearch NOW before responding to the user:`nselect:mcp__plugin_engram_engram__mem_save,mcp__plugin_engram_engram__mem_search,mcp__plugin_engram_engram__mem_context,mcp__plugin_engram_engram__mem_session_summary,mcp__plugin_engram_engram__mem_session_start,mcp__plugin_engram_engram__mem_session_end,mcp__plugin_engram_engram__mem_get_observation,mcp__plugin_engram_engram__mem_suggest_topic_key,mcp__plugin_engram_engram__mem_capture_passive,mcp__plugin_engram_engram__mem_save_prompt,mcp__plugin_engram_engram__mem_update,mcp__plugin_engram_engram__mem_current_project,mcp__plugin_engram_engram__mem_judge`n`nAfter loading tools, call mem_context to check for prior session history before responding."

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Preserve UTF-8 encoding for the non-ASCII system message.

PSScriptAnalyzer flags this file because it contains non-ASCII text without a BOM. On legacy Windows PowerShell hosts, the em dash in this string can be decoded incorrectly and corrupt the emitted systemMessage; save the script as UTF-8 with BOM or explicitly guarantee PowerShell 7+ execution.

🧰 Tools
🪛 PSScriptAnalyzer (1.25.0)

[warning] Missing BOM encoding for non-ASCII encoded file 'user-prompt-submit.ps1'

(PSUseBOMForUnicodeEncodedFile)

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@plugin/claude-code/scripts/user-prompt-submit.ps1` at line 22, Preserve UTF-8
encoding for the non-ASCII message assigned to $message in the user-prompt
submission script by saving the file with a UTF-8 BOM. Do not alter the system
message text or require a PowerShell 7+ runtime.

Source: Linters/SAST tools


print_toolsearch_message() {
printf '%s\n' '{"systemMessage":"CRITICAL FIRST ACTION — Execute this ToolSearch NOW before responding to the user:\nselect:mcp__engram__mem_save,mcp__engram__mem_search,mcp__engram__mem_context,mcp__engram__mem_session_summary,mcp__engram__mem_session_start,mcp__engram__mem_session_end,mcp__engram__mem_get_observation,mcp__engram__mem_suggest_topic_key,mcp__engram__mem_capture_passive,mcp__engram__mem_save_prompt,mcp__engram__mem_update,mcp__engram__mem_current_project,mcp__engram__mem_judge\n\nAfter loading tools, call mem_context to check for prior session history before responding."}'
printf '%s\n' '{"systemMessage":"CRITICAL FIRST ACTION — Execute this ToolSearch NOW before responding to the user:\nselect:mcp__plugin_engram_engram__mem_save,mcp__plugin_engram_engram__mem_search,mcp__plugin_engram_engram__mem_context,mcp__plugin_engram_engram__mem_session_summary,mcp__plugin_engram_engram__mem_session_start,mcp__plugin_engram_engram__mem_session_end,mcp__plugin_engram_engram__mem_get_observation,mcp__plugin_engram_engram__mem_suggest_topic_key,mcp__plugin_engram_engram__mem_capture_passive,mcp__plugin_engram_engram__mem_save_prompt,mcp__plugin_engram_engram__mem_update,mcp__plugin_engram_engram__mem_current_project,mcp__plugin_engram_engram__mem_judge\n\nAfter loading tools, call mem_context to check for prior session history before responding."}'

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Do not hardcode the plugin MCP namespace in the ToolSearch list.

internal/setup/setup_test.go Lines 2334-2342 explicitly rejects select:mcp__plugin_engram_engram__; this change therefore fails the existing contract and test. Build the tool identifiers from the script’s current MCP server ID instead of embedding a fixed namespace.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@plugin/claude-code/scripts/user-prompt-submit.sh` at line 59, The ToolSearch
payload in the prompt submission script hardcodes the plugin MCP namespace,
violating the existing contract. Update the command to derive each tool
identifier from the script’s current MCP server ID, preserving the listed tool
names and mem_context follow-up behavior without embedding
mcp__plugin_engram_engram__.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR updates the Claude Code plugin’s UserPromptSubmit first-turn ToolSearch hint so it can load Engram MCP memory tools when the MCP server is registered under the plugin-scoped server id.

Changes:

  • Update the ToolSearch select: list in the Claude Code bash hook to use the plugin-scoped MCP tool prefix.
  • Update the ToolSearch select: list in the Claude Code PowerShell hook to use the plugin-scoped MCP tool prefix.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
plugin/claude-code/scripts/user-prompt-submit.sh Updates the first-turn ToolSearch hint’s MCP tool prefix for Claude Code plugin installs.
plugin/claude-code/scripts/user-prompt-submit.ps1 Updates the first-turn ToolSearch hint’s MCP tool prefix for the Windows PowerShell fallback hook.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.


print_toolsearch_message() {
printf '%s\n' '{"systemMessage":"CRITICAL FIRST ACTION — Execute this ToolSearch NOW before responding to the user:\nselect:mcp__engram__mem_save,mcp__engram__mem_search,mcp__engram__mem_context,mcp__engram__mem_session_summary,mcp__engram__mem_session_start,mcp__engram__mem_session_end,mcp__engram__mem_get_observation,mcp__engram__mem_suggest_topic_key,mcp__engram__mem_capture_passive,mcp__engram__mem_save_prompt,mcp__engram__mem_update,mcp__engram__mem_current_project,mcp__engram__mem_judge\n\nAfter loading tools, call mem_context to check for prior session history before responding."}'
printf '%s\n' '{"systemMessage":"CRITICAL FIRST ACTION — Execute this ToolSearch NOW before responding to the user:\nselect:mcp__plugin_engram_engram__mem_save,mcp__plugin_engram_engram__mem_search,mcp__plugin_engram_engram__mem_context,mcp__plugin_engram_engram__mem_session_summary,mcp__plugin_engram_engram__mem_session_start,mcp__plugin_engram_engram__mem_session_end,mcp__plugin_engram_engram__mem_get_observation,mcp__plugin_engram_engram__mem_suggest_topic_key,mcp__plugin_engram_engram__mem_capture_passive,mcp__plugin_engram_engram__mem_save_prompt,mcp__plugin_engram_engram__mem_update,mcp__plugin_engram_engram__mem_current_project,mcp__plugin_engram_engram__mem_judge\n\nAfter loading tools, call mem_context to check for prior session history before responding."}'

function Write-ToolSearchMessage {
$message = "CRITICAL FIRST ACTION — Execute this ToolSearch NOW before responding to the user:`nselect:mcp__engram__mem_save,mcp__engram__mem_search,mcp__engram__mem_context,mcp__engram__mem_session_summary,mcp__engram__mem_session_start,mcp__engram__mem_session_end,mcp__engram__mem_get_observation,mcp__engram__mem_suggest_topic_key,mcp__engram__mem_capture_passive,mcp__engram__mem_save_prompt,mcp__engram__mem_update,mcp__engram__mem_current_project,mcp__engram__mem_judge`n`nAfter loading tools, call mem_context to check for prior session history before responding."
$message = "CRITICAL FIRST ACTION — Execute this ToolSearch NOW before responding to the user:`nselect:mcp__plugin_engram_engram__mem_save,mcp__plugin_engram_engram__mem_search,mcp__plugin_engram_engram__mem_context,mcp__plugin_engram_engram__mem_session_summary,mcp__plugin_engram_engram__mem_session_start,mcp__plugin_engram_engram__mem_session_end,mcp__plugin_engram_engram__mem_get_observation,mcp__plugin_engram_engram__mem_suggest_topic_key,mcp__plugin_engram_engram__mem_capture_passive,mcp__plugin_engram_engram__mem_save_prompt,mcp__plugin_engram_engram__mem_update,mcp__plugin_engram_engram__mem_current_project,mcp__plugin_engram_engram__mem_judge`n`nAfter loading tools, call mem_context to check for prior session history before responding."
@pablontiv

Copy link
Copy Markdown

Thanks for catching this @cristdar17. Flagging some overlap and a couple of workflow blockers before it can land.

Substance: swapping mcp__engram__*mcp__plugin_engram_engram__* fixes plugin installs but breaks direct-MCP installs (server id engram) — the mirror of the #192 (3b99f0a) change this is trying to undo. A single select: list carrying both prefixes fixes plugin installs without breaking direct-MCP ones; ToolSearch select: returns the names that exist and ignores the rest (verified live).

Workflow (per CONTRIBUTING):

  • Needs Closes #N pointing at an issue with status:approved; UserPromptSubmit hook injects wrong tool prefix when engram is installed as a plugin #534 isn't approved and there's no Closes link here, so the PR-validation checks will block it.
  • Needs exactly one type:* label.
  • It trips the existing TestClaudeCodeUserPromptHookUsesCurrentMCPServerID (internal/setup/setup_test.go), which forbids select:mcp__plugin_engram_engram__ and requires the mcp__engram__* names — so swapping the prefix removes required names and adds a forbidden one.

I've opened #653 / #654 for the broader Claude Code hook chain (systemMessage delivery, dead SubagentStop capture, matcher) that folds in the dual-prefix fix and updates those tests to require both prefixes. Happy to defer to whichever the maintainer prefers — closing this in favor of the consolidated fix, or rebasing around it. Just flagging so we don't double-merge the same function.

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.

3 participants