memoryintelligence-mcp 0.2.11__tar.gz → 0.2.13__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of memoryintelligence-mcp might be problematic. Click here for more details.

Files changed (23) hide show
  1. {memoryintelligence_mcp-0.2.11 → memoryintelligence_mcp-0.2.13}/CHANGELOG.md +44 -0
  2. {memoryintelligence_mcp-0.2.11 → memoryintelligence_mcp-0.2.13}/PKG-INFO +1 -1
  3. {memoryintelligence_mcp-0.2.11 → memoryintelligence_mcp-0.2.13}/pyproject.toml +1 -1
  4. {memoryintelligence_mcp-0.2.11 → memoryintelligence_mcp-0.2.13}/src/mi_mcp/__init__.py +1 -1
  5. {memoryintelligence_mcp-0.2.11 → memoryintelligence_mcp-0.2.13}/src/mi_mcp/__main__.py +5 -3
  6. {memoryintelligence_mcp-0.2.11 → memoryintelligence_mcp-0.2.13}/src/mi_mcp/cli.py +72 -3
  7. {memoryintelligence_mcp-0.2.11 → memoryintelligence_mcp-0.2.13}/src/mi_mcp/local_index.py +37 -5
  8. {memoryintelligence_mcp-0.2.11 → memoryintelligence_mcp-0.2.13}/.gitignore +0 -0
  9. {memoryintelligence_mcp-0.2.11 → memoryintelligence_mcp-0.2.13}/CONTRIBUTING.md +0 -0
  10. {memoryintelligence_mcp-0.2.11 → memoryintelligence_mcp-0.2.13}/LICENSE +0 -0
  11. {memoryintelligence_mcp-0.2.11 → memoryintelligence_mcp-0.2.13}/README.md +0 -0
  12. {memoryintelligence_mcp-0.2.11 → memoryintelligence_mcp-0.2.13}/src/mi_mcp/client.py +0 -0
  13. {memoryintelligence_mcp-0.2.11 → memoryintelligence_mcp-0.2.13}/src/mi_mcp/config.py +0 -0
  14. {memoryintelligence_mcp-0.2.11 → memoryintelligence_mcp-0.2.13}/src/mi_mcp/embedder.py +0 -0
  15. {memoryintelligence_mcp-0.2.11 → memoryintelligence_mcp-0.2.13}/src/mi_mcp/indexer.py +0 -0
  16. {memoryintelligence_mcp-0.2.11 → memoryintelligence_mcp-0.2.13}/src/mi_mcp/keys.py +0 -0
  17. {memoryintelligence_mcp-0.2.11 → memoryintelligence_mcp-0.2.13}/src/mi_mcp/localreads.py +0 -0
  18. {memoryintelligence_mcp-0.2.11 → memoryintelligence_mcp-0.2.13}/src/mi_mcp/paths.py +0 -0
  19. {memoryintelligence_mcp-0.2.11 → memoryintelligence_mcp-0.2.13}/src/mi_mcp/recall_guard.py +0 -0
  20. {memoryintelligence_mcp-0.2.11 → memoryintelligence_mcp-0.2.13}/src/mi_mcp/scrub.py +0 -0
  21. {memoryintelligence_mcp-0.2.11 → memoryintelligence_mcp-0.2.13}/src/mi_mcp/server.py +0 -0
  22. {memoryintelligence_mcp-0.2.11 → memoryintelligence_mcp-0.2.13}/src/mi_mcp/umo_format.py +0 -0
  23. {memoryintelligence_mcp-0.2.11 → memoryintelligence_mcp-0.2.13}/src/mi_mcp/vault.py +0 -0
@@ -3,6 +3,50 @@
3
3
  All notable changes to `memoryintelligence-mcp` are documented here.
4
4
  The format follows [Keep a Changelog](https://keepachangelog.com/); this project uses [Semantic Versioning](https://semver.org/).
5
5
 
6
+ ## [0.2.13] — 2026-08-12
7
+
8
+ ### Fixed — `setup` could not be re-run without re-entering your API key (#1351)
9
+
10
+ `mi-mcp setup` is the most discoverable command for "my install is broken, fix it", but it
11
+ was written as the **first-run** path: it prompted for the API key unconditionally, so a
12
+ returning user got sent to the portal to dig out a credential they never needed to touch,
13
+ and a perfectly good stored key was overwritten.
14
+
15
+ `setup` now **keeps a key that is already in the Keychain or the keyfile**, printing only a
16
+ masked prefix. `--reset-key` replaces it deliberately. Resolution order, most explicit
17
+ first: `--api-key` → `MI_API_KEY` → already-stored → prompt.
18
+
19
+ It also names the command that user actually wanted. **`mi-mcp wire`** re-connects Claude
20
+ Desktop / Code / Cursor and never touches your key — `doctor` recommended it in five
21
+ places, but the failure is precisely for the user who does not run `doctor` first. The
22
+ `--help` epilog now says which of the two you need.
23
+
24
+ ## [0.2.12] — 2026-08-12
25
+
26
+ ### Fixed — local recency was corpus-relative, so importing one old memory reordered every result (#1253)
27
+
28
+ `LocalIndex.search` normalised recency against `max_age`, the age of the **oldest entry
29
+ currently in the index**. A document's score therefore depended on the whole corpus, not
30
+ on the query and the document: import one old memory and every existing result reorders,
31
+ with no change to the query and no change to the memories being ranked. Ranking stopped
32
+ being a function of `(query, document)`.
33
+
34
+ Recency is now an **absolute linear 30-day decay**, with semantics reused from the cloud
35
+ read path (`core/engines/rerank.py::recency_score`) rather than re-derived — floor to
36
+ whole days, decay over 30, floor at 0.0. One deliberate difference, stated rather than
37
+ silent: the result is also capped at **1.0**, so a future-dated entry from clock skew
38
+ cannot let recency out-rank every real signal.
39
+
40
+ `DEFAULT_WEIGHTS` carried the comment *"kept comparable to the cloud ranking."* The
41
+ numbers do match; the signals underneath do not all match. It now says so. Recency is
42
+ genuinely shared as of this release; keyword and entity remain locally derived.
43
+
44
+ ⚠️ **Ranking output changes for any vault whose oldest entry is not ~30 days old.** Under
45
+ the old formula the oldest entry always scored 0.0 recency and the newest always 1.0,
46
+ whatever the real span. Absolute decay means a vault where everything is a week old now
47
+ sees recency contribute ~equally across all entries — which is correct, and is the point.
48
+
49
+ ||||||| parent of 3fd5f209 (fix(mcp): setup keeps an already-stored key, and names `wire` as the repair command)
6
50
  ## [0.2.11] — 2026-08-11
7
51
 
8
52
  ### Fixed — `doctor` only ever asked PyPI, so a mirror install could not learn it was behind (#1347)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: memoryintelligence-mcp
3
- Version: 0.2.11
3
+ Version: 0.2.13
4
4
  Summary: MCP server for MemoryIntelligence — give Claude a memory you own, set up in one command
5
5
  Project-URL: Homepage, https://memoryintelligence.io
6
6
  Project-URL: Repository, https://github.com/somewhere11/memoryintelligence-mcp
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "memoryintelligence-mcp"
7
- version = "0.2.11"
7
+ version = "0.2.13"
8
8
  description = "MCP server for MemoryIntelligence — give Claude a memory you own, set up in one command"
9
9
  readme = "README.md"
10
10
  license = "Apache-2.0"
@@ -1,3 +1,3 @@
1
1
  """MI MCP Server — MemoryIntelligence tools for Claude."""
2
2
 
3
- __version__ = "0.2.11"
3
+ __version__ = "0.2.13"
@@ -43,9 +43,11 @@ def main():
43
43
  # user checking `--help` for `setup` shouldn't conclude the docs are stale.
44
44
  epilog=(
45
45
  "setup commands (run these first, not shown above):\n"
46
- " mi-mcp setup store your API key + wire + opt-in + verify (one command)\n"
47
- " mi-mcp wire wire into Claude Desktop / Code / Cursor\n"
48
- " mi-mcp doctor verify install, key resolution, and wiring\n"
46
+ " mi-mcp setup first run: store your API key + wire + opt-in + verify\n"
47
+ " mi-mcp wire ALREADY SET UP AND SOMETHING BROKE? start here —\n"
48
+ " re-connects Claude Desktop / Code / Cursor and\n"
49
+ " never touches your key\n"
50
+ " mi-mcp doctor tells you which of the two you need\n"
49
51
  " mi-mcp status show wired surfaces + opt-in allowlist\n"
50
52
  "\nGet a key at https://memoryintelligence.io/portal, then run `mi-mcp setup`."
51
53
  ),
@@ -1082,6 +1082,36 @@ def cmd_backfill(argv: list[str]) -> int:
1082
1082
  # setup — the one-command front door (store key → wire → opt-in → verify)
1083
1083
  # ---------------------------------------------------------------------------
1084
1084
 
1085
+ def _stored_api_key(home: Path) -> str | None:
1086
+ """Return (key, where) for a key already on disk/Keychain, else (None, "").
1087
+
1088
+ Deliberately does NOT consult ``MI_API_KEY`` from the environment, unlike
1089
+ ``config.resolve_api_key``. Setup uses this to answer "do you already have a
1090
+ key I would be about to overwrite?", and an env var is neither stored nor
1091
+ overwritten — reporting it as "already stored" would be a lie the user
1092
+ cannot act on.
1093
+ """
1094
+ account = os.environ.get("MI_KEYCHAIN_ACCOUNT") or os.environ.get("USER") or ""
1095
+ try:
1096
+ r = subprocess.run(
1097
+ ["security", "find-generic-password", "-a", account, "-s", "MI_API_KEY", "-w"],
1098
+ capture_output=True, text=True, timeout=5,
1099
+ )
1100
+ if r.returncode == 0 and r.stdout.strip():
1101
+ return r.stdout.strip()
1102
+ except (OSError, subprocess.SubprocessError):
1103
+ pass # non-macOS or `security` unavailable — fall through to the keyfile
1104
+ envf = paths.resolve_keyfile(home)
1105
+ if envf is not None:
1106
+ for line in envf.read_text().splitlines():
1107
+ line = line.strip()
1108
+ if line.startswith("MI_API_KEY="):
1109
+ val = line.split("=", 1)[1].strip().strip('"').strip("'")
1110
+ if val:
1111
+ return val
1112
+ return None
1113
+
1114
+
1085
1115
  def _store_key_keychain(key: str, account: str) -> None:
1086
1116
  """Store the key in the macOS Keychain under service ``MI_API_KEY``.
1087
1117
 
@@ -1145,6 +1175,8 @@ def cmd_setup(argv: list[str]) -> int:
1145
1175
  )
1146
1176
  ap.add_argument("--api-key", default=None,
1147
1177
  help="provide the key non-interactively (else you're prompted, hidden)")
1178
+ ap.add_argument("--reset-key", action="store_true",
1179
+ help="replace a key that is already stored (default: keep it)")
1148
1180
  ap.add_argument("--store", choices=["auto", "keychain", "file"], default="auto",
1149
1181
  help="where to keep the key (auto: Keychain on macOS, ~/.memoryintelligence/.env elsewhere)")
1150
1182
  ap.add_argument("--surfaces", default="desktop,code",
@@ -1174,6 +1206,46 @@ def cmd_setup(argv: list[str]) -> int:
1174
1206
  if key:
1175
1207
  print(" ⚠ --api-key is visible in the process list (ps); on shared machines\n"
1176
1208
  " prefer the interactive prompt or the MI_API_KEY env var.", file=sys.stderr)
1209
+
1210
+ # #1351 — `setup` is the most discoverable command for "my install is
1211
+ # broken, fix it", but it was written as the FIRST-RUN path and prompted
1212
+ # for the key unconditionally. A returning user got sent to the portal to
1213
+ # dig out a credential they never needed to touch, and a perfectly good
1214
+ # stored key was overwritten.
1215
+ #
1216
+ # `mi-mcp wire` is the correct command for that user — it re-connects the
1217
+ # hosts and never touches the key — and nothing told them so. `doctor`
1218
+ # recommends `wire` in five places, but the whole failure is for the user
1219
+ # who does NOT run doctor first and goes straight for the command whose
1220
+ # name sounds like what they want.
1221
+ #
1222
+ # Resolution order, most explicit first:
1223
+ # --api-key → MI_API_KEY env → ALREADY-STORED key → prompt
1224
+ #
1225
+ # An env var set for this invocation is a deliberate per-run override and
1226
+ # outranks what is on disk; a stored key outranks the prompt, which is the
1227
+ # fix. Ordering matters and is asserted in test_cli_setup.py.
1228
+ if not key and os.environ.get("MI_API_KEY"):
1229
+ key = os.environ["MI_API_KEY"].strip()
1230
+ print(" using MI_API_KEY from the environment")
1231
+
1232
+ if not key and not args.reset_key:
1233
+ existing = _stored_api_key(home)
1234
+ if existing:
1235
+ key = existing
1236
+ # Nothing derived from the key is printed — not a masked slice, not
1237
+ # a hash. CodeQL taints the key value, so ANY derived value reaching
1238
+ # stdout is a clear-text-logging flow, and it is right to: the useful
1239
+ # fact here is that a key was kept and WHERE it lives, which needs no
1240
+ # part of the secret. Two earlier attempts got this wrong — a
1241
+ # `key[:11]…key[-4:]` mask (1 alert), then a SHA-256 fingerprint,
1242
+ # which kept that alert AND added a weak-hash-on-sensitive-data one
1243
+ # (2 alerts). `mi-mcp doctor` is where key identity belongs.
1244
+ print(" keeping the key already stored on this machine")
1245
+ print(" re-run with --reset-key to replace it\n")
1246
+ print(" \u2139 if you only need to re-connect the hosts, `mi-mcp wire` is\n"
1247
+ " the narrower command — it never touches your key.\n")
1248
+
1177
1249
  if not key:
1178
1250
  if sys.stdin.isatty():
1179
1251
  print("Get a free key at https://memoryintelligence.io/portal")
@@ -1182,9 +1254,6 @@ def cmd_setup(argv: list[str]) -> int:
1182
1254
  except (EOFError, KeyboardInterrupt):
1183
1255
  print("\naborted — nothing stored.", file=sys.stderr)
1184
1256
  return 130
1185
- elif os.environ.get("MI_API_KEY"):
1186
- key = os.environ["MI_API_KEY"].strip()
1187
- print(" using MI_API_KEY from the environment")
1188
1257
  else:
1189
1258
  print("error: no API key. Run in a terminal to be prompted, set MI_API_KEY,\n"
1190
1259
  " or pass --api-key. Get a free key at https://memoryintelligence.io/portal",
@@ -37,9 +37,44 @@ from typing import Optional, Sequence
37
37
  # module — for its dataclasses or JSON persistence — never requires numpy. Only
38
38
  # ranking does. Keeps `pip install memoryintelligence-mcp` numpy-free.
39
39
 
40
- # Local ranking weights, kept comparable to the cloud ranking.
40
+ # Local ranking weights. The NUMBERS match the cloud's
41
+ # (`core/engines/rerank.py`); the SIGNALS underneath are not all identical, so
42
+ # read this as "same blend, not the same function" rather than as a parity
43
+ # guarantee. Recency is now genuinely shared (see below); keyword and entity
44
+ # are still locally derived.
41
45
  DEFAULT_WEIGHTS = {"semantic": 0.60, "keyword": 0.15, "entity": 0.15, "recency": 0.10}
42
46
 
47
+ #: Days over which recency decays to zero. Mirrors `rerank.recency_score`,
48
+ #: which the cloud/sidecar read path uses.
49
+ RECENCY_HALFLIFE_DAYS = 30.0
50
+ _SECONDS_PER_DAY = 86_400.0
51
+
52
+
53
+ def _recency_score(created_at: float, now: float) -> float:
54
+ """Absolute linear 30-day decay — NOT normalized against the corpus (#1253).
55
+
56
+ This was ``1.0 - ((now - created_at) / max_age)`` where ``max_age`` was the
57
+ age of the oldest entry in the index. A document's score therefore depended
58
+ on the whole corpus: **importing one old memory reordered every existing
59
+ result**, with no change to the query and no change to the memories being
60
+ ranked. Ranking stopped being a function of ``(query, document)``, which is
61
+ wrong under any architecture we might pick for the local runtime — which is
62
+ why it is fixed here rather than folded into the local/cloud convergence
63
+ question.
64
+
65
+ Semantics are reused from ``core/engines/rerank.py::recency_score`` rather
66
+ than re-derived: floor to whole days ago, linear decay over
67
+ ``RECENCY_HALFLIFE_DAYS``, floor at 0.0.
68
+
69
+ One deliberate difference from the cloud function, stated rather than
70
+ silent: the result is also capped at **1.0**. A future-dated entry (clock
71
+ skew, a bad import) yields a negative ``days_ago`` there and a score above
72
+ 1.0, which would let recency out-rank every real signal. Capping cannot
73
+ hide a real difference — nothing legitimately scores above 1.0.
74
+ """
75
+ days_ago = (now - created_at) // _SECONDS_PER_DAY
76
+ return max(0.0, min(1.0, 1.0 - (days_ago / RECENCY_HALFLIFE_DAYS)))
77
+
43
78
  _TOKEN_RE = re.compile(r"[a-z0-9]+")
44
79
 
45
80
 
@@ -124,9 +159,6 @@ class LocalIndex:
124
159
  q_tokens = _tokens(query_text)
125
160
  q_ents = {e.lower() for e in (query_entities or [])}
126
161
 
127
- ages = [now - e.created_at for e in self._entries.values()]
128
- max_age = max(ages) or 1.0 # normalize recency against the oldest entry
129
-
130
162
  w = self._weights
131
163
  hits = []
132
164
  for e in self._entries.values():
@@ -135,7 +167,7 @@ class LocalIndex:
135
167
  semantic = max(0.0, cos) # similarity, never negative
136
168
  keyword = _overlap(q_tokens, _tokens(e.summary))
137
169
  entity = _overlap(q_ents, {x.lower() for x in e.entities}) if q_ents else 0.0
138
- recency = 1.0 - ((now - e.created_at) / max_age)
170
+ recency = _recency_score(e.created_at, now)
139
171
  score = (
140
172
  w["semantic"] * semantic
141
173
  + w["keyword"] * keyword