fix(mem0-plugin): use env var in .mcp.json, fix onboarding MCP check

- .mcp.json: use ${MEM0_API_KEY} instead of ${user_config.MEM0_API_KEY}
  so MCP connects for --plugin-dir users with the key in their shell
- mem0-onboard: check MCP tools availability first, stop early with
  clear instructions if MCP server not connected
This commit is contained in:
kartik-mem0
2026-05-21 21:29:19 +05:30
parent d5b15cebb7
commit 141782a230
2 changed files with 11 additions and 22 deletions
+1 -1
View File
@@ -4,7 +4,7 @@
"type": "http", "type": "http",
"url": "https://mcp.mem0.ai/mcp/", "url": "https://mcp.mem0.ai/mcp/",
"headers": { "headers": {
"Authorization": "Token ${user_config.MEM0_API_KEY}" "Authorization": "Token ${MEM0_API_KEY}"
} }
} }
} }
+10 -21
View File
@@ -11,22 +11,16 @@ description: >
Run this wizard to set up the mem0 plugin for the current project. Complete in ~30 seconds. Run this wizard to set up the mem0 plugin for the current project. Complete in ~30 seconds.
## Step 1: Verify API key ## Step 1: Verify API key and MCP connection
Check if the API key is available. Claude Code may provide it via `userConfig` (stored in system keychain, exposed as `CLAUDE_PLUGIN_OPTION_MEM0_API_KEY`) or via shell environment (`MEM0_API_KEY`): Check that the mem0 MCP tools are available by looking for `mcp__mem0__search_memories` in the deferred tools list (use ToolSearch if needed).
```bash - If **MCP tools found**: Proceed to Step 2. The API key is working.
echo "${MEM0_API_KEY:-${CLAUDE_PLUGIN_OPTION_MEM0_API_KEY:-NOT_SET}}" - If **MCP tools NOT found**: The MCP server failed to connect. Tell the user:
``` 1. "MCP server not connected. Make sure `MEM0_API_KEY` is exported in your shell."
2. Show: `export MEM0_API_KEY="m0-your-key-here"` then restart Claude Code.
- If **NOT_SET** (neither variable is set): 3. If they need a key: https://app.mem0.ai/dashboard/api-keys or `mem0 init --agent --json`
1. Ask the user: "No API key found. Do you have one, or need to create one?" 4. **STOP here.** Do not proceed — all other steps need MCP tools.
2. If they need one, provide two options:
- **Browser**: Go to https://app.mem0.ai/dashboard/api-keys and copy the key
- **CLI**: Run `pip install mem0-cli && mem0 init --agent --json` to mint a key without email
3. Once they have the key, tell them to run: `export MEM0_API_KEY="m0-..."` in their terminal, then restart this Claude Code session.
4. **STOP here.** Do not proceed until the key is confirmed set.
- If **SET** (either variable has a value): Proceed to Step 2.
## Step 2: Show identity ## Step 2: Show identity
@@ -59,15 +53,10 @@ If user says yes (or default):
Ask: "Install coding categories optimized for development workflows? [Y/n]" Ask: "Install coding categories optimized for development workflows? [Y/n]"
If yes, run the script directly (no external dependencies required — uses stdlib only). If yes, run the setup script (uses stdlib only, no SDK required):
The script lives at `scripts/setup_coding_categories.py` relative to the plugin root. Use the appropriate plugin root variable for the current platform:
- Claude Code: `${CLAUDE_PLUGIN_ROOT}`
- Codex: `${CODEX_PLUGIN_ROOT}`
- Cursor: `${CURSOR_PLUGIN_ROOT}`
```bash ```bash
python3 "<PLUGIN_ROOT>/scripts/setup_coding_categories.py" --apply python3 "${CLAUDE_PLUGIN_ROOT:-${CURSOR_PLUGIN_ROOT:-${CODEX_PLUGIN_ROOT}}}/scripts/setup_coding_categories.py" --apply
``` ```
If the script reports an error, show the error message and suggest checking the API key. If the script reports an error, show the error message and suggest checking the API key.