forever-brain-mcp 0.1.1__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.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 NextArk
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,166 @@
1
+ Metadata-Version: 2.5
2
+ Name: forever-brain-mcp
3
+ Version: 0.1.1
4
+ Summary: Local-first, encrypted, source-attributed, bi-temporal memory MCP server for Hermes, Claude, Cursor, Codex, and Antigravity.
5
+ Project-URL: Homepage, https://github.com/NextArkDAO/forever-brain-mcp
6
+ Project-URL: Repository, https://github.com/NextArkDAO/forever-brain-mcp
7
+ Project-URL: Issues, https://github.com/NextArkDAO/forever-brain-mcp/issues
8
+ Project-URL: Releases, https://github.com/NextArkDAO/forever-brain-mcp/releases
9
+ Author: NextArk
10
+ License-Expression: MIT
11
+ License-File: LICENSE
12
+ Keywords: ai-agents,fastmcp,forever-brain,hermes,mcp,memory
13
+ Classifier: Development Status :: 4 - Beta
14
+ Classifier: Intended Audience :: Developers
15
+ Classifier: Operating System :: MacOS :: MacOS X
16
+ Classifier: Operating System :: POSIX :: Linux
17
+ Classifier: Programming Language :: Python :: 3
18
+ Classifier: Programming Language :: Python :: 3.11
19
+ Classifier: Programming Language :: Python :: 3.12
20
+ Classifier: Programming Language :: Python :: 3.13
21
+ Classifier: Programming Language :: Python :: 3.14
22
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
23
+ Classifier: Topic :: Security :: Cryptography
24
+ Requires-Python: >=3.11
25
+ Requires-Dist: cryptography>=42.0.0
26
+ Requires-Dist: fastmcp>=2.0.0
27
+ Provides-Extra: dev
28
+ Requires-Dist: build>=1.2.0; extra == 'dev'
29
+ Requires-Dist: pytest>=8.0.0; extra == 'dev'
30
+ Requires-Dist: twine>=5.0.0; extra == 'dev'
31
+ Description-Content-Type: text/markdown
32
+
33
+ # Forever Brain MCP
34
+
35
+ **Local-first, encrypted, source-attributed, bi-temporal memory for AI agents.**
36
+
37
+ Built with FastMCP for POSIX hosts. Verified host: Hermes Agent 0.23.3 on macOS. Other stdio clients below are example configurations.
38
+
39
+ ---
40
+
41
+ ## Why Forever Brain (Instead of Markdown Files or Vector RAG)?
42
+
43
+ | Capability | Plain Markdown | Typical Vector RAG | Forever Brain MCP |
44
+ |---|---|---|---|
45
+ | **Encrypted at rest locally** | No | Cloud-hosted / plaintext | **AES-256-GCM (`0600` local vault)** |
46
+ | **Corrections without stale ghosts** | Manual edits | Returns old & new together | **Non-destructive `brain_correct` supersession** |
47
+ | **Bi-temporal truth** (*when true* vs. *when learned*) | No | Rarely | Stores both timestamps. `as_of` filters by recording time. |
48
+ | **Source attribution & trust tiers** | Informal | Usually lost | **Required `source` + `trust` (`user`/`agent`/`external`)** |
49
+ | **Full revision lineage** | Git only | No | **`brain_trace(record_id)` chain** |
50
+ | **Bounded startup budget** | Manual | Top-K noise | **`brain_startup(limit)` priority-ranked** |
51
+
52
+ ---
53
+
54
+ ## 60-Second Quickstart
55
+
56
+ ### 1. Install
57
+
58
+ In a Python 3.11+ virtual environment on a POSIX host, run:
59
+
60
+ ```bash
61
+ git clone https://github.com/NextArkDAO/forever-brain-mcp.git
62
+ cd forever-brain-mcp
63
+ pip install -e .
64
+ ```
65
+
66
+ To run the test suite from the repository root:
67
+
68
+ ```bash
69
+ pip install -e '.[dev]'
70
+ python -m pytest -q
71
+ ```
72
+
73
+ #### Try point-in-time recall
74
+
75
+ This example calls the MCP tools in a temporary vault. It uses the first write’s returned `recorded_at` as the historical cutoff.
76
+
77
+ ```bash
78
+ FOREVER_BRAIN_DIR="$(mktemp -d)" python - <<'PYTHON'
79
+ import asyncio
80
+ from fastmcp import Client
81
+ from forever_brain_mcp.server import mcp
82
+
83
+ async def demo():
84
+ async with Client(mcp) as client:
85
+ saved = await client.call_tool("brain_remember", {
86
+ "record_id": "demo.room.v1", "topic": "demo.room",
87
+ "text": "Meet in Room A.", "source": "fictional invitation",
88
+ })
89
+ cutoff = saved.data["record"]["recorded_at"]
90
+ await asyncio.sleep(1.1) # The vault records timestamps to the second.
91
+ await client.call_tool("brain_correct", {
92
+ "old_record_id": "demo.room.v1", "new_record_id": "demo.room.v2",
93
+ "text": "Meet in Room B.", "source": "fictional update",
94
+ })
95
+ for label, filters in [("As of first write", {"as_of": cutoff}), ("Now", {})]:
96
+ result = await client.call_tool("brain_recall", {"query": "room", **filters})
97
+ print(label, result.data["records"][0]["text"], sep=": ")
98
+
99
+ asyncio.run(demo())
100
+ PYTHON
101
+ ```
102
+
103
+ Expected output:
104
+
105
+ ```text
106
+ As of first write: Meet in Room A.
107
+ Now: Meet in Room B.
108
+ ```
109
+
110
+ ### 2. Wire into Hermes Agent (`~/.hermes/config.yaml`)
111
+ ```yaml
112
+ mcp_servers:
113
+ forever-brain:
114
+ command: forever-brain-mcp
115
+ env:
116
+ FOREVER_BRAIN_DIR: ~/.forever-brain/vault
117
+ ```
118
+ Restart Hermes, and your agent immediately gets `brain_startup`, `brain_remember`, `brain_correct`, `brain_recall`, `brain_trace`, and `brain_health`.
119
+
120
+ ### 3. Or Install into Claude Code / Claude Desktop / Cursor
121
+ ```bash
122
+ fastmcp install claude-code src/forever_brain_mcp/server.py:mcp
123
+ fastmcp install claude-desktop src/forever_brain_mcp/server.py:mcp
124
+ fastmcp install cursor src/forever_brain_mcp/server.py:mcp -e .
125
+ ```
126
+
127
+ ### 4. Local Validation (Hermes FastMCP Quality Bar)
128
+ ```bash
129
+ fastmcp inspect src/forever_brain_mcp/server.py:mcp
130
+ fastmcp list src/forever_brain_mcp/server.py --json
131
+ fastmcp call src/forever_brain_mcp/server.py brain_health --json
132
+ ```
133
+
134
+ ---
135
+
136
+ ## Tools, Resources & Prompts
137
+
138
+ | Surface | Name | Purpose |
139
+ |---|---|---|
140
+ | Tool | `brain_startup(limit=12)` | Bounded session-start context (identity, principles, decisions, preferences, focus). |
141
+ | Tool | `brain_remember(...)` | Save an encrypted, source-attributed, bi-temporal record (idempotent on `record_id`). |
142
+ | Tool | `brain_correct(...)` | Non-destructively supersede an outdated record while preserving full history. |
143
+ | Tool | `brain_recall(...)` | Search active truth by default; optional `include_history=True` or point-in-time `as_of`. |
144
+ | Tool | `brain_trace(record_id)` | Trace full revision chain from original record to current truth. |
145
+ | Tool | `brain_health()` | Verify encryption, capacity pressure, record counts, and vault SHA-256. |
146
+ | Resource | `brain://status` | Read-only vault health summary. |
147
+ | Resource | `brain://recent` | 10 most recent active records. |
148
+ | Prompt | `session_handoff` | Reusable end-of-session memory hygiene template. |
149
+
150
+ ---
151
+
152
+ ## Environment Variables
153
+
154
+ | Variable | Default | Description |
155
+ |---|---|---|
156
+ | `FOREVER_BRAIN_DIR` | `~/.forever-brain/vault` | Private (`0700`) directory holding `vault.enc.json` and lockfile. |
157
+ | `FOREVER_BRAIN_KEY_FILE` | `<FOREVER_BRAIN_DIR>/vault.key` | Base64 encoding of 32 random bytes in an owner-private file. The default key is generated for a new vault. Provision any external key in advance. |
158
+ | `FOREVER_BRAIN_PASSPHRASE` | *(unset)* | Optional passphrase (PBKDF2-HMAC-SHA256, 200k iterations) instead of a keyfile. |
159
+
160
+ ## Recovery and local access
161
+
162
+ For keyfile mode, back up the ciphertext and its original key. Anyone holding both can decrypt the vault. For passphrase mode, retain the ciphertext, original vault.salt and the passphrase. Restore into a dedicated directory owned by the current user (0700), with owner-private files (0600). Back up a consistent snapshot while the server is stopped.
163
+
164
+ The supported transport is stdio for a trusted local client on POSIX. Every connected client can read and change the entire selected vault. Use a separate vault per trust boundary. Source and trust labels are supplied by the client. Corrections inherit the old trust label unless explicitly set. Keep untrusted inputs attributed as such. A third-party HTTP wrapper is outside the supported configuration.
165
+
166
+ A correction records its effective date in event_at. The as_of query shows the history the vault knew by the specified recorded time. A future effective date does not defer a saved correction. Set explicit event_at when effective time matters.
@@ -0,0 +1,134 @@
1
+ # Forever Brain MCP
2
+
3
+ **Local-first, encrypted, source-attributed, bi-temporal memory for AI agents.**
4
+
5
+ Built with FastMCP for POSIX hosts. Verified host: Hermes Agent 0.23.3 on macOS. Other stdio clients below are example configurations.
6
+
7
+ ---
8
+
9
+ ## Why Forever Brain (Instead of Markdown Files or Vector RAG)?
10
+
11
+ | Capability | Plain Markdown | Typical Vector RAG | Forever Brain MCP |
12
+ |---|---|---|---|
13
+ | **Encrypted at rest locally** | No | Cloud-hosted / plaintext | **AES-256-GCM (`0600` local vault)** |
14
+ | **Corrections without stale ghosts** | Manual edits | Returns old & new together | **Non-destructive `brain_correct` supersession** |
15
+ | **Bi-temporal truth** (*when true* vs. *when learned*) | No | Rarely | Stores both timestamps. `as_of` filters by recording time. |
16
+ | **Source attribution & trust tiers** | Informal | Usually lost | **Required `source` + `trust` (`user`/`agent`/`external`)** |
17
+ | **Full revision lineage** | Git only | No | **`brain_trace(record_id)` chain** |
18
+ | **Bounded startup budget** | Manual | Top-K noise | **`brain_startup(limit)` priority-ranked** |
19
+
20
+ ---
21
+
22
+ ## 60-Second Quickstart
23
+
24
+ ### 1. Install
25
+
26
+ In a Python 3.11+ virtual environment on a POSIX host, run:
27
+
28
+ ```bash
29
+ git clone https://github.com/NextArkDAO/forever-brain-mcp.git
30
+ cd forever-brain-mcp
31
+ pip install -e .
32
+ ```
33
+
34
+ To run the test suite from the repository root:
35
+
36
+ ```bash
37
+ pip install -e '.[dev]'
38
+ python -m pytest -q
39
+ ```
40
+
41
+ #### Try point-in-time recall
42
+
43
+ This example calls the MCP tools in a temporary vault. It uses the first write’s returned `recorded_at` as the historical cutoff.
44
+
45
+ ```bash
46
+ FOREVER_BRAIN_DIR="$(mktemp -d)" python - <<'PYTHON'
47
+ import asyncio
48
+ from fastmcp import Client
49
+ from forever_brain_mcp.server import mcp
50
+
51
+ async def demo():
52
+ async with Client(mcp) as client:
53
+ saved = await client.call_tool("brain_remember", {
54
+ "record_id": "demo.room.v1", "topic": "demo.room",
55
+ "text": "Meet in Room A.", "source": "fictional invitation",
56
+ })
57
+ cutoff = saved.data["record"]["recorded_at"]
58
+ await asyncio.sleep(1.1) # The vault records timestamps to the second.
59
+ await client.call_tool("brain_correct", {
60
+ "old_record_id": "demo.room.v1", "new_record_id": "demo.room.v2",
61
+ "text": "Meet in Room B.", "source": "fictional update",
62
+ })
63
+ for label, filters in [("As of first write", {"as_of": cutoff}), ("Now", {})]:
64
+ result = await client.call_tool("brain_recall", {"query": "room", **filters})
65
+ print(label, result.data["records"][0]["text"], sep=": ")
66
+
67
+ asyncio.run(demo())
68
+ PYTHON
69
+ ```
70
+
71
+ Expected output:
72
+
73
+ ```text
74
+ As of first write: Meet in Room A.
75
+ Now: Meet in Room B.
76
+ ```
77
+
78
+ ### 2. Wire into Hermes Agent (`~/.hermes/config.yaml`)
79
+ ```yaml
80
+ mcp_servers:
81
+ forever-brain:
82
+ command: forever-brain-mcp
83
+ env:
84
+ FOREVER_BRAIN_DIR: ~/.forever-brain/vault
85
+ ```
86
+ Restart Hermes, and your agent immediately gets `brain_startup`, `brain_remember`, `brain_correct`, `brain_recall`, `brain_trace`, and `brain_health`.
87
+
88
+ ### 3. Or Install into Claude Code / Claude Desktop / Cursor
89
+ ```bash
90
+ fastmcp install claude-code src/forever_brain_mcp/server.py:mcp
91
+ fastmcp install claude-desktop src/forever_brain_mcp/server.py:mcp
92
+ fastmcp install cursor src/forever_brain_mcp/server.py:mcp -e .
93
+ ```
94
+
95
+ ### 4. Local Validation (Hermes FastMCP Quality Bar)
96
+ ```bash
97
+ fastmcp inspect src/forever_brain_mcp/server.py:mcp
98
+ fastmcp list src/forever_brain_mcp/server.py --json
99
+ fastmcp call src/forever_brain_mcp/server.py brain_health --json
100
+ ```
101
+
102
+ ---
103
+
104
+ ## Tools, Resources & Prompts
105
+
106
+ | Surface | Name | Purpose |
107
+ |---|---|---|
108
+ | Tool | `brain_startup(limit=12)` | Bounded session-start context (identity, principles, decisions, preferences, focus). |
109
+ | Tool | `brain_remember(...)` | Save an encrypted, source-attributed, bi-temporal record (idempotent on `record_id`). |
110
+ | Tool | `brain_correct(...)` | Non-destructively supersede an outdated record while preserving full history. |
111
+ | Tool | `brain_recall(...)` | Search active truth by default; optional `include_history=True` or point-in-time `as_of`. |
112
+ | Tool | `brain_trace(record_id)` | Trace full revision chain from original record to current truth. |
113
+ | Tool | `brain_health()` | Verify encryption, capacity pressure, record counts, and vault SHA-256. |
114
+ | Resource | `brain://status` | Read-only vault health summary. |
115
+ | Resource | `brain://recent` | 10 most recent active records. |
116
+ | Prompt | `session_handoff` | Reusable end-of-session memory hygiene template. |
117
+
118
+ ---
119
+
120
+ ## Environment Variables
121
+
122
+ | Variable | Default | Description |
123
+ |---|---|---|
124
+ | `FOREVER_BRAIN_DIR` | `~/.forever-brain/vault` | Private (`0700`) directory holding `vault.enc.json` and lockfile. |
125
+ | `FOREVER_BRAIN_KEY_FILE` | `<FOREVER_BRAIN_DIR>/vault.key` | Base64 encoding of 32 random bytes in an owner-private file. The default key is generated for a new vault. Provision any external key in advance. |
126
+ | `FOREVER_BRAIN_PASSPHRASE` | *(unset)* | Optional passphrase (PBKDF2-HMAC-SHA256, 200k iterations) instead of a keyfile. |
127
+
128
+ ## Recovery and local access
129
+
130
+ For keyfile mode, back up the ciphertext and its original key. Anyone holding both can decrypt the vault. For passphrase mode, retain the ciphertext, original vault.salt and the passphrase. Restore into a dedicated directory owned by the current user (0700), with owner-private files (0600). Back up a consistent snapshot while the server is stopped.
131
+
132
+ The supported transport is stdio for a trusted local client on POSIX. Every connected client can read and change the entire selected vault. Use a separate vault per trust boundary. Source and trust labels are supplied by the client. Corrections inherit the old trust label unless explicitly set. Keep untrusted inputs attributed as such. A third-party HTTP wrapper is outside the supported configuration.
133
+
134
+ A correction records its effective date in event_at. The as_of query shows the history the vault knew by the specified recorded time. A future effective date does not defer a saved correction. Set explicit event_at when effective time matters.
@@ -0,0 +1,57 @@
1
+ [build-system]
2
+ requires = ["hatchling>=1.24.0"]
3
+ build-backend = "hatchling.build"
4
+
5
+ [project]
6
+ name = "forever-brain-mcp"
7
+ version = "0.1.1"
8
+ description = "Local-first, encrypted, source-attributed, bi-temporal memory MCP server for Hermes, Claude, Cursor, Codex, and Antigravity."
9
+ readme = "README.md"
10
+ requires-python = ">=3.11"
11
+ license = "MIT"
12
+ license-files = ["LICENSE"]
13
+ authors = [{ name = "NextArk" }]
14
+ keywords = ["mcp", "fastmcp", "hermes", "memory", "ai-agents", "forever-brain"]
15
+ classifiers = [
16
+ "Development Status :: 4 - Beta",
17
+ "Intended Audience :: Developers",
18
+ "Operating System :: POSIX :: Linux",
19
+ "Operating System :: MacOS :: MacOS X",
20
+ "Programming Language :: Python :: 3",
21
+ "Programming Language :: Python :: 3.11",
22
+ "Programming Language :: Python :: 3.12",
23
+ "Programming Language :: Python :: 3.13",
24
+ "Programming Language :: Python :: 3.14",
25
+ "Topic :: Scientific/Engineering :: Artificial Intelligence",
26
+ "Topic :: Security :: Cryptography",
27
+ ]
28
+ dependencies = [
29
+ "fastmcp>=2.0.0",
30
+ "cryptography>=42.0.0",
31
+ ]
32
+
33
+ [project.urls]
34
+ Homepage = "https://github.com/NextArkDAO/forever-brain-mcp"
35
+ Repository = "https://github.com/NextArkDAO/forever-brain-mcp"
36
+ Issues = "https://github.com/NextArkDAO/forever-brain-mcp/issues"
37
+ Releases = "https://github.com/NextArkDAO/forever-brain-mcp/releases"
38
+
39
+ [project.optional-dependencies]
40
+ dev = [
41
+ "pytest>=8.0.0",
42
+ "build>=1.2.0",
43
+ "twine>=5.0.0",
44
+ ]
45
+
46
+ [project.scripts]
47
+ forever-brain-mcp = "forever_brain_mcp.server:main"
48
+
49
+ [tool.hatch.build.targets.wheel]
50
+ packages = ["src/forever_brain_mcp"]
51
+
52
+ [tool.hatch.build.targets.sdist]
53
+ include = ["/src", "/tests", "/README.md", "/LICENSE", "/pyproject.toml"]
54
+ exclude = ["**/__pycache__", "**/*.pyc"]
55
+
56
+ [tool.pytest.ini_options]
57
+ testpaths = ["tests"]
@@ -0,0 +1,3 @@
1
+ """Forever Brain — local-first, encrypted, bi-temporal memory MCP server."""
2
+
3
+ __version__ = "0.1.1"
@@ -0,0 +1,193 @@
1
+ """Forever Brain FastMCP server.
2
+
3
+ Single trusted local client over stdio.
4
+ """
5
+ from __future__ import annotations
6
+
7
+ import argparse
8
+ import json
9
+ import os
10
+ from typing import Literal
11
+
12
+ from fastmcp import FastMCP
13
+
14
+ from forever_brain_mcp.vault import ForeverBrainVault
15
+
16
+ os.umask(0o077)
17
+
18
+ mcp = FastMCP(
19
+ name="Forever Brain",
20
+ instructions=(
21
+ "Local-first, encrypted, source-attributed, bi-temporal memory for AI agents. "
22
+ "Call brain_startup at session start, brain_recall before assuming prior facts, "
23
+ "brain_remember for new durable facts/decisions, and brain_correct whenever a prior "
24
+ "fact changes so history is preserved without stale ghosts."
25
+ ),
26
+ )
27
+
28
+ _vault_instance: ForeverBrainVault | None = None
29
+
30
+
31
+ def _get_vault() -> ForeverBrainVault:
32
+ global _vault_instance
33
+ if _vault_instance is None:
34
+ _vault_instance = ForeverBrainVault()
35
+ return _vault_instance
36
+
37
+
38
+ @mcp.tool
39
+ def brain_startup(limit: int = 12) -> dict:
40
+ """Recall bounded startup context (identity, principles, active decisions, focus) for a new session."""
41
+ return _get_vault().startup(limit=limit)
42
+
43
+
44
+ @mcp.tool
45
+ def brain_remember(
46
+ record_id: str,
47
+ topic: str,
48
+ text: str,
49
+ source: str,
50
+ kind: Literal[
51
+ "identity",
52
+ "decision",
53
+ "principle",
54
+ "preference",
55
+ "work",
56
+ "lesson",
57
+ "focus",
58
+ "fact",
59
+ "history",
60
+ ] = "work",
61
+ status: Literal["current", "completed", "unknown"] = "current",
62
+ trust: Literal["user", "agent", "external"] = "agent",
63
+ event_at: str | None = None,
64
+ ) -> dict:
65
+ """Save an encrypted, source-attributed, bi-temporal memory record.
66
+
67
+ Args:
68
+ record_id: Stable lowercase slug (e.g. 'project.pricing.v1'). Reusing the exact
69
+ same ID and payload is an idempotent no-op.
70
+ topic: Dot-separated category (e.g. 'project.pricing', 'user.preferences').
71
+ text: The durable fact, decision, or lesson to remember (1-12000 chars).
72
+ source: Where this fact came from (file path, URL, conversation date, or user quote).
73
+ kind: Record type (identity, decision, principle, preference, work, lesson, focus, fact, history).
74
+ status: Lifecycle status (current, completed, unknown).
75
+ trust: Trust boundary (user, agent, external). External data is never automatic authority.
76
+ event_at: Optional ISO-8601 timestamp with timezone of WHEN this fact became true
77
+ (distinct from recorded_at, when the agent learned it).
78
+ """
79
+ return _get_vault().remember(
80
+ record_id=record_id,
81
+ topic=topic,
82
+ text=text,
83
+ source=source,
84
+ kind=kind,
85
+ status=status,
86
+ trust=trust,
87
+ event_at=event_at,
88
+ )
89
+
90
+
91
+ @mcp.tool
92
+ def brain_correct(
93
+ old_record_id: str,
94
+ new_record_id: str,
95
+ text: str,
96
+ source: str,
97
+ event_at: str | None = None,
98
+ status: Literal["current", "completed", "unknown"] | None = None,
99
+ trust: Literal["user", "agent", "external"] | None = None,
100
+ ) -> dict:
101
+ """Non-destructively supersede an outdated memory with a corrected fact.
102
+
103
+ Preserves the full audit trail while ensuring future brain_recall and brain_startup
104
+ calls return only the corrected truth.
105
+
106
+ Args:
107
+ old_record_id: The existing active record_id being replaced.
108
+ new_record_id: A new unique lowercase slug (e.g. 'project.pricing.v2').
109
+ text: The updated truth.
110
+ source: Evidence or attribution for why this changed.
111
+ event_at: Optional ISO-8601 timestamp with timezone of when the new truth took effect.
112
+ status: Optional updated status (defaults to the superseded record's status).
113
+ trust: Optional updated trust tier (defaults to the superseded record's trust tier).
114
+ """
115
+ return _get_vault().correct(
116
+ old_record_id=old_record_id,
117
+ new_record_id=new_record_id,
118
+ text=text,
119
+ source=source,
120
+ event_at=event_at,
121
+ status=status,
122
+ trust=trust,
123
+ )
124
+
125
+
126
+ @mcp.tool
127
+ def brain_recall(
128
+ query: str,
129
+ topic: str | None = None,
130
+ include_history: bool = False,
131
+ as_of: str | None = None,
132
+ limit: int = 10,
133
+ ) -> dict:
134
+ """Search memory records by keywords or topic.
135
+
136
+ Returns active (non-superseded) truth by default. Set include_history=True to inspect
137
+ superseded records, or pass as_of (ISO-8601 with timezone) to return what was recorded by that time. event_at is descriptive, not a query cutoff.
138
+ """
139
+ return _get_vault().recall(
140
+ query=query,
141
+ topic=topic,
142
+ include_history=include_history,
143
+ as_of=as_of,
144
+ limit=limit,
145
+ )
146
+
147
+
148
+ @mcp.tool
149
+ def brain_trace(record_id: str) -> dict:
150
+ """Trace the complete revision lineage (original -> corrections -> current truth) for a record_id."""
151
+ return _get_vault().trace(record_id=record_id)
152
+
153
+
154
+ @mcp.tool
155
+ def brain_health() -> dict:
156
+ """Check vault encryption, capacity pressure, record counts, and integrity hash without exposing secrets."""
157
+ return _get_vault().health()
158
+
159
+
160
+ @mcp.resource("brain://status")
161
+ def resource_status() -> str:
162
+ """Read-only JSON summary of Forever Brain vault health and capacity."""
163
+ return json.dumps(_get_vault().health(), indent=2)
164
+
165
+
166
+ @mcp.resource("brain://recent")
167
+ def resource_recent() -> str:
168
+ """Read-only JSON list of the 10 most recent active memory records."""
169
+ return json.dumps(_get_vault().recent(limit=10), indent=2)
170
+
171
+
172
+ @mcp.prompt
173
+ def session_handoff(project: str = "general") -> str:
174
+ """Reusable end-of-session prompt to save verified decisions and corrections to Forever Brain."""
175
+ return (
176
+ f"Before ending this '{project}' session, review what changed:\n"
177
+ "1. Call brain_recall to check if any existing record is now outdated.\n"
178
+ "2. For any changed fact or decision, call brain_correct with the old_record_id, a new_record_id, "
179
+ "exact source attribution, and event_at (when it became true).\n"
180
+ "3. For genuinely new durable decisions or lessons, call brain_remember with an explicit source and trust tier.\n"
181
+ "4. Never store secrets, API keys, or unverified guesses."
182
+ )
183
+
184
+
185
+ def main() -> None:
186
+ parser = argparse.ArgumentParser(description="Run the Forever Brain FastMCP server.")
187
+ parser.add_argument("--transport", choices=("stdio",), default="stdio")
188
+ parser.parse_args()
189
+ mcp.run(transport="stdio")
190
+
191
+
192
+ if __name__ == "__main__":
193
+ main()