feat: switch engines mid-session via MCP tools and /use-memory skill#62
feat: switch engines mid-session via MCP tools and /use-memory skill#62gonzaloserrano wants to merge 1 commit intomainfrom
Conversation
|
|
The Claude Code plugin couldn't switch Memory Engines mid-session. The MCP server bound at startup to whichever engine owned --api-key, so touching a different engine meant quitting Claude Code, running `me engine use <slug>`, and reopening. Blocks anyone who wants to dip into a team engine briefly without losing their personal default. Four new MCP tools and a /use-memory skill move engine selection from launch-time to runtime. me_engine_list enumerates engines via the session token (works in FRESH state). me_session_get_engine reads the current binding without exposing the API key. me_session_use_engine binds for the rest of the session, with an optional probe and a client cache so re-binds are free. me_session_provision_engine mints a key via accounts.engine.setupAccess, persists it under engines.<slug>.api_key, and binds; idempotent when the key already exists. --api-key is now optional. When present, its slug seeds the session as already bound, so the existing plugin's .mcp.json keeps working unchanged. Without it the server starts FRESH and the agent must call me_session_use_engine before any me_memory_* succeeds. Provisioning persists keys via a new addEngineApiKey helper that does not mutate active_engine. The existing storeApiKey does, because CLI callers expect it to. Two helpers keep session-scoped binding from leaking into whatever the next CLI process treats as default; running `me memory get foo` outside Claude Code after a provision call still hits the original active engine. The skill ships from packages/claude-plugin/skills/use-memory/, not td-aiguide. It's generic to all Memory Engine users, and bundling it next to the MCP tools means one install gets both halves. Plugin version 0.1.0 -> 0.2.0; "skills": "./skills/" added to plugin.json. Resolver and credentials persistence have unit tests (packages/cli/mcp/engine-resolve.test.ts, additions in packages/cli/credentials.test.ts). End-to-end MCP behavior validated by manual smoke test against the live server; no harness for spawning the stdio server in a test exists yet.
465945f to
66efe02
Compare
|
Gonzalo, I fully appreciate the motivation for this change. We need an ergonomic way to support multi-engine setups. There are a few issues here:
We're actively working on designs to make the agent plugins work and enable this sort of team-based activity. I think we should close this PR and pick the problem back up under that design. Would you be willing to provide feedback on these plans? I have a vision doc — would you read it and push back? |
|
Hey sorry about the noise. I did not want to open a PR but my AI companion did. I was just vibe-experimenting with the APIs and the whole problem without giving it mutch thought. Sorry about that again!
I will take a look for sure! I'm not sure if I will be able to push back though ;-) |
The Claude Code plugin couldn't switch Memory Engines mid-session. The MCP server bound at startup to whichever engine owned
--api-key, so touching a different engine meant quitting Claude Code, runningme engine use <slug>, and reopening. Blocks anyone who wants to dip into a team engine briefly without losing their personal default.Four new MCP tools and a
/use-memoryskill move engine selection from launch-time to runtime.me_engine_listenumerates engines via the session token (works in FRESH state).me_session_get_enginereads the current binding without exposing the API key.me_session_use_enginebinds for the rest of the session, with an optional probe and a client cache so re-binds are free.me_session_provision_enginemints a key viaaccounts.engine.setupAccess, persists it underengines.<slug>.api_key, and binds; idempotent when the key already exists.--api-keyis now optional. When present, its slug seeds the session as already bound, so the existing plugin's.mcp.jsonkeeps working unchanged. Without it the server starts FRESH and the agent must callme_session_use_enginebefore anyme_memory_*succeeds.Provisioning persists keys via a new
addEngineApiKeyhelper that does not mutateactive_engine. The existingstoreApiKeydoes, because CLI callers expect it to. Two helpers keep session-scoped binding from leaking into whatever the next CLI process treats as default; runningme memory get foooutside Claude Code after a provision call still hits the original active engine.The skill ships from
packages/claude-plugin/skills/use-memory/, nottd-aiguide. It's generic to all Memory Engine users, and bundling it next to the MCP tools means one install gets both halves. Plugin version 0.1.0 → 0.2.0;"skills": "./skills/"added to plugin.json.Manual smoke test against the live server (FRESH bootstrap, single-engine account):
me_session_get_enginereturns slug-only binding from bootstrap;me_engine_listreturns the full org/engine tree;me_session_provision_engine defaultis idempotent (provisioned: falseon retry); a bogus slug yields a resolver error pointing atme_engine_list;me_session_use_engine defaultreuses the cached client (validated: false) and backfills full metadata.Auto-capture hooks (UserPromptSubmit/Stop) are unchanged. They still read
CLAUDE_PLUGIN_OPTION_API_KEYfrom plugin userConfig, so in-sessionme_session_use_enginedoes not redirect them. Agent-driven writes follow the in-session bind; hook-driven captures follow scope-resolved userConfig. Multi-engine capture across sessions still requires the existing user/project scope split.Resolver and credentials persistence have unit tests (
packages/cli/mcp/engine-resolve.test.ts, additions inpackages/cli/credentials.test.ts). End-to-end MCP behavior validated by the smoke test above; no harness for spawning the stdio server in a test exists yet.