You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/AGENT-SETUP.md
+71-1Lines changed: 71 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -27,7 +27,7 @@ Engram works with **any MCP-compatible agent**. Pick your agent below.
27
27
28
28
### Project auto-detection (important)
29
29
30
-
**Do not pass `project` to write tools.** Engram auto-detects the project from the server's working directory (cwd) using `.engram/config.json`, git remote URL, repo root name, or directory basename. Agents that include `project` in `mem_save` or similar calls will have that argument silently discarded.
30
+
**Do not pass `project` to write tools during normal operation.** Engram auto-detects the project from the server's working directory (cwd) using `.engram/config.json`, git remote URL, repo root name, or directory basename. Agents that include `project` in `mem_save` or similar calls will have that argument ignored unless they are using the explicit ambiguous-project recovery flow below.
31
31
32
32
To lock write tools to the canonical project for a repo, add `.engram/config.json` at the repo root:
33
33
@@ -41,6 +41,76 @@ When present, `project_name` is used for writes from the repo and its subdirecto
41
41
42
42
**Recommended first call:**`mem_current_project` — confirms which project Engram detected before you start writing. Returns `project_source` (how it was detected) and `available_projects` (if cwd is ambiguous).
43
43
44
+
If a write tool returns `ambiguous_project`, the agent must not guess. This happens when the MCP server is started from a parent directory that contains multiple repositories, for example:
45
+
46
+
```text
47
+
/Users/you/work
48
+
├── alan-thegentleman/
49
+
├── angular-18-jest-playwright/
50
+
└── engram/
51
+
```
52
+
53
+
The first write fails with an error like:
54
+
55
+
```json
56
+
{
57
+
"error_code": "ambiguous_project",
58
+
"available_projects": [
59
+
"alan-thegentleman",
60
+
"angular-18-jest-playwright",
61
+
"engram"
62
+
]
63
+
}
64
+
```
65
+
66
+
Ask the user to choose exactly one value from `available_projects`, then retry only `mem_save` or `mem_save_prompt` with both recovery fields:
This is a narrow rescue path, not a free-form project override:
88
+
89
+
- Recovery is accepted only after cwd detection failed with `ambiguous_project`.
90
+
-`project_choice_reason` must be exactly `user_selected_after_ambiguous_project`.
91
+
-`project`, after trimming surrounding whitespace, must exactly match one of the reported `available_projects`.
92
+
- Normalized variants and guesses are rejected: if `available_projects` contains `foo--bar`, retry with `foo--bar`, not `foo-bar`.
93
+
- Empty or whitespace-only choices are rejected.
94
+
- In all non-ambiguous cases, `.engram/config.json`/git/cwd detection remains authoritative and the explicit `project` field is ignored.
95
+
96
+
Mental model:
97
+
98
+
```text
99
+
mem_save fails with ambiguous_project
100
+
↓
101
+
Engram returns available_projects
102
+
↓
103
+
agent asks the user to choose one exact value
104
+
↓
105
+
agent retries with project + project_choice_reason
106
+
↓
107
+
Engram validates the choice came from ambiguity
108
+
↓
109
+
Engram saves to the selected project
110
+
```
111
+
112
+
Alternatives: `cd` into the target repo before starting the MCP server, or add repo `.engram/config.json`.
113
+
44
114
**Read tools** (`mem_search`, `mem_context`, `mem_get_observation`, `mem_stats`, `mem_timeline`) accept an optional `project` override validated against the store. Omit it to auto-detect.
Copy file name to clipboardExpand all lines: internal/mcp/mcp.go
+121-6Lines changed: 121 additions & 6 deletions
Original file line number
Diff line number
Diff line change
@@ -19,6 +19,7 @@ import (
19
19
"errors"
20
20
"fmt"
21
21
"os"
22
+
"path/filepath"
22
23
"strings"
23
24
"time"
24
25
@@ -328,6 +329,12 @@ Examples:
328
329
mcp.WithString("topic_key",
329
330
mcp.Description("Optional topic identifier for upserts (e.g. architecture/auth-model). Reuses and updates the latest observation in same project+scope."),
330
331
),
332
+
mcp.WithString("project",
333
+
mcp.Description("Optional recovery target only after ambiguous_project. Ignored unless project_choice_reason is user_selected_after_ambiguous_project."),
334
+
),
335
+
mcp.WithString("project_choice_reason",
336
+
mcp.Description("Must be user_selected_after_ambiguous_project, and only after the user explicitly chose one of available_projects from an ambiguous_project error."),
mcp.Description("Session ID to associate with (default: manual-save-{project})"),
435
442
),
443
+
mcp.WithString("project",
444
+
mcp.Description("Optional recovery target only after ambiguous_project. Ignored unless project_choice_reason is user_selected_after_ambiguous_project."),
445
+
),
446
+
mcp.WithString("project_choice_reason",
447
+
mcp.Description("Must be user_selected_after_ambiguous_project, and only after the user explicitly chose one of available_projects from an ambiguous_project error."),
"Project choice is empty; choose exactly one value from available_projects and retry with project_choice_reason=user_selected_after_ambiguous_project",
2042
+
choiceErr.AvailableProjects,
2043
+
)
2044
+
}
2045
+
returnerrorWithMeta("invalid_project_choice",
2046
+
fmt.Sprintf("Project choice %q is not one of available_projects", choiceErr.Name),
envelope["hint"] ="Use mem_current_project to inspect detection results, or cd into one of the listed repositories."
2063
+
envelope["hint"] ="Ask the user to choose one of available_projects, then retry mem_save or mem_save_prompt with project and project_choice_reason=user_selected_after_ambiguous_project; alternatively cd into the target repo or add repo .engram/config.json."
2064
+
case"invalid_project_choice":
2065
+
envelope["hint"] ="Use exactly one of available_projects after asking the user, or cd into the target repo, or add repo .engram/config.json."
1951
2066
case"unknown_project":
1952
2067
envelope["hint"] ="Use one of the available_projects values, or omit project to auto-detect."
0 commit comments