fix(claude-plugin): use plugin-scoped MCP tool prefix in UserPromptSubmit hint#642
Conversation
…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.
📝 WalkthroughWalkthroughClaude 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. ChangesClaude Code tool selection
Estimated code review effort: 1 (Trivial) | ~2 minutes Suggested labels: Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
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
📒 Files selected for processing (2)
plugin/claude-code/scripts/user-prompt-submit.ps1plugin/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." |
There was a problem hiding this comment.
🎯 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."}' |
There was a problem hiding this comment.
🎯 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__.
There was a problem hiding this comment.
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." |
|
Thanks for catching this @cristdar17. Flagging some overlap and a couple of workflow blockers before it can land. Substance: swapping Workflow (per CONTRIBUTING):
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. |
Problem
The UserPromptSubmit hook (
plugin/claude-code/scripts/user-prompt-submit.ps1/.sh) emits a first-turn hint telling the agent to run: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_*. Theselect:query matches nothing and the agent cannot load the memory tools from the hint.internal/setup/setup.goalready handles both prefixes for the permissions allowlist — only the plugin hook scripts were left on the old prefix.Fix
Replace
mcp__engram__withmcp__plugin_engram_engram__in both claude-code hook scripts (2 lines).Notes
plugin/codex/scripts/user-prompt-submit.shalso referencesmcp__engram__— left untouched since Codex tool naming may differ; happy to update it here too if the same prefix applies.select:list loads all 13 tools.Summary by CodeRabbit