@prmichaelsen/remember-mcp 2.0.0 → 2.0.2
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.
- package/AGENT.md +216 -2
- package/CHANGELOG.md +28 -0
- package/agent/design/design.template.md +136 -0
- package/agent/design/requirements.template.md +387 -0
- package/agent/milestones/milestone-1-{title}.template.md +206 -0
- package/agent/patterns/bootstrap.template.md +1237 -0
- package/agent/patterns/pattern.template.md +364 -0
- package/agent/progress.template.yaml +158 -0
- package/agent/progress.yaml +43 -7
- package/agent/scripts/check-for-updates.sh +88 -0
- package/agent/scripts/uninstall.sh +75 -0
- package/agent/scripts/update.sh +75 -0
- package/agent/tasks/task-1-{title}.template.md +225 -0
- package/dist/server-factory.js +78 -12
- package/dist/server.js +78 -12
- package/dist/utils/error-handler.d.ts +40 -0
- package/package.json +1 -1
- package/src/tools/create-memory.ts +8 -2
- package/src/tools/update-memory.ts +50 -10
- package/src/utils/error-handler.ts +79 -0
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
|
|
3
|
+
# Agent Context Protocol (ACP) Uninstall Script
|
|
4
|
+
# This script removes all ACP files from a project
|
|
5
|
+
# Usage: ./agent/scripts/uninstall.sh [-y]
|
|
6
|
+
|
|
7
|
+
set -e
|
|
8
|
+
|
|
9
|
+
# Colors for output
|
|
10
|
+
RED='\033[0;31m'
|
|
11
|
+
GREEN='\033[0;32m'
|
|
12
|
+
YELLOW='\033[1;33m'
|
|
13
|
+
BLUE='\033[0;34m'
|
|
14
|
+
NC='\033[0m' # No Color
|
|
15
|
+
|
|
16
|
+
# Check for -y flag
|
|
17
|
+
AUTO_CONFIRM=false
|
|
18
|
+
if [ "$1" = "-y" ]; then
|
|
19
|
+
AUTO_CONFIRM=true
|
|
20
|
+
fi
|
|
21
|
+
|
|
22
|
+
echo -e "${YELLOW}Agent Context Protocol (ACP) Uninstall${NC}"
|
|
23
|
+
echo "======================================"
|
|
24
|
+
echo ""
|
|
25
|
+
|
|
26
|
+
# Check if agent directory exists
|
|
27
|
+
if [ ! -d "agent" ] && [ ! -f "AGENT.md" ]; then
|
|
28
|
+
echo -e "${YELLOW}No ACP files found in current directory${NC}"
|
|
29
|
+
exit 0
|
|
30
|
+
fi
|
|
31
|
+
|
|
32
|
+
# If not auto-confirmed, show instructions for agents
|
|
33
|
+
if [ "$AUTO_CONFIRM" = false ]; then
|
|
34
|
+
echo -e "${BLUE}Note for AI Agents:${NC}"
|
|
35
|
+
echo "This script requires user confirmation to prevent accidental deletion."
|
|
36
|
+
echo "Please ask the user: 'Do you want to uninstall ACP from this project?'"
|
|
37
|
+
echo "If yes, rerun this script with: ./agent/scripts/uninstall.sh -y"
|
|
38
|
+
echo ""
|
|
39
|
+
echo -e "${RED}WARNING: This will permanently delete:${NC}"
|
|
40
|
+
echo " - agent/ directory (all contents)"
|
|
41
|
+
echo " - AGENT.md file"
|
|
42
|
+
echo ""
|
|
43
|
+
echo "Make sure you have committed any important changes to git."
|
|
44
|
+
echo ""
|
|
45
|
+
|
|
46
|
+
read -p "Are you sure you want to remove all ACP files? (y/N) " -n 1 -r
|
|
47
|
+
echo
|
|
48
|
+
|
|
49
|
+
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
|
|
50
|
+
echo "Uninstall cancelled. No files were deleted."
|
|
51
|
+
exit 0
|
|
52
|
+
fi
|
|
53
|
+
fi
|
|
54
|
+
|
|
55
|
+
echo ""
|
|
56
|
+
echo "Removing ACP files..."
|
|
57
|
+
|
|
58
|
+
# Remove agent directory
|
|
59
|
+
if [ -d "agent" ]; then
|
|
60
|
+
rm -rf agent
|
|
61
|
+
echo -e "${GREEN}✓${NC} Removed agent/ directory"
|
|
62
|
+
fi
|
|
63
|
+
|
|
64
|
+
# Remove AGENT.md
|
|
65
|
+
if [ -f "AGENT.md" ]; then
|
|
66
|
+
rm -f AGENT.md
|
|
67
|
+
echo -e "${GREEN}✓${NC} Removed AGENT.md"
|
|
68
|
+
fi
|
|
69
|
+
|
|
70
|
+
echo ""
|
|
71
|
+
echo -e "${GREEN}Uninstall complete!${NC}"
|
|
72
|
+
echo ""
|
|
73
|
+
echo "All ACP files have been removed from this project."
|
|
74
|
+
echo "Use 'git status' to see what was deleted."
|
|
75
|
+
echo ""
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
|
|
3
|
+
# Agent Context Protocol (ACP) Update Script
|
|
4
|
+
# This script updates AGENT.md, template files, and utility scripts from the repository
|
|
5
|
+
|
|
6
|
+
set -e
|
|
7
|
+
|
|
8
|
+
# Colors for output
|
|
9
|
+
RED='\033[0;31m'
|
|
10
|
+
GREEN='\033[0;32m'
|
|
11
|
+
YELLOW='\033[1;33m'
|
|
12
|
+
BLUE='\033[0;34m'
|
|
13
|
+
NC='\033[0m' # No Color
|
|
14
|
+
|
|
15
|
+
# Repository details
|
|
16
|
+
REPO_URL="https://github.com/prmichaelsen/agent-context-protocol.git"
|
|
17
|
+
BRANCH="mainline"
|
|
18
|
+
|
|
19
|
+
echo -e "${BLUE}Agent Context Protocol (ACP) Updater${NC}"
|
|
20
|
+
echo "======================================"
|
|
21
|
+
echo ""
|
|
22
|
+
|
|
23
|
+
# Check if AGENT.md exists
|
|
24
|
+
if [ ! -f "AGENT.md" ]; then
|
|
25
|
+
echo -e "${RED}Error: AGENT.md not found in current directory${NC}"
|
|
26
|
+
echo "This script should be run from your project root where AGENT.md is located."
|
|
27
|
+
exit 1
|
|
28
|
+
fi
|
|
29
|
+
|
|
30
|
+
# Create temporary directory
|
|
31
|
+
TEMP_DIR=$(mktemp -d)
|
|
32
|
+
trap "rm -rf $TEMP_DIR" EXIT
|
|
33
|
+
|
|
34
|
+
echo "Fetching latest ACP files..."
|
|
35
|
+
if ! git clone --depth 1 --branch "$BRANCH" "$REPO_URL" "$TEMP_DIR" &>/dev/null; then
|
|
36
|
+
echo -e "${RED}Error: Failed to fetch repository${NC}"
|
|
37
|
+
echo "Please check your internet connection and try again."
|
|
38
|
+
exit 1
|
|
39
|
+
fi
|
|
40
|
+
|
|
41
|
+
echo -e "${GREEN}✓${NC} Latest files fetched"
|
|
42
|
+
echo ""
|
|
43
|
+
|
|
44
|
+
echo "Updating ACP files..."
|
|
45
|
+
|
|
46
|
+
# Update template files
|
|
47
|
+
cp "$TEMP_DIR/agent/design/design.template.md" "agent/design/"
|
|
48
|
+
cp "$TEMP_DIR/agent/design/requirements.template.md" "agent/design/"
|
|
49
|
+
cp "$TEMP_DIR/agent/milestones/milestone-1-{title}.template.md" "agent/milestones/"
|
|
50
|
+
cp "$TEMP_DIR/agent/tasks/task-1-{title}.template.md" "agent/tasks/"
|
|
51
|
+
cp "$TEMP_DIR/agent/patterns/pattern.template.md" "agent/patterns/"
|
|
52
|
+
cp "$TEMP_DIR/agent/patterns/bootstrap.template.md" "agent/patterns/"
|
|
53
|
+
cp "$TEMP_DIR/agent/progress.template.yaml" "agent/"
|
|
54
|
+
|
|
55
|
+
# Update AGENT.md
|
|
56
|
+
cp "$TEMP_DIR/AGENT.md" "."
|
|
57
|
+
|
|
58
|
+
# Update scripts
|
|
59
|
+
cp "$TEMP_DIR/scripts/update.sh" "agent/scripts/"
|
|
60
|
+
cp "$TEMP_DIR/scripts/check-for-updates.sh" "agent/scripts/"
|
|
61
|
+
cp "$TEMP_DIR/scripts/uninstall.sh" "agent/scripts/"
|
|
62
|
+
chmod +x agent/scripts/*.sh
|
|
63
|
+
|
|
64
|
+
echo -e "${GREEN}✓${NC} All files updated"
|
|
65
|
+
echo ""
|
|
66
|
+
echo -e "${GREEN}Update complete!${NC}"
|
|
67
|
+
echo ""
|
|
68
|
+
echo -e "${BLUE}Next steps:${NC}"
|
|
69
|
+
echo "1. Review changes: git diff"
|
|
70
|
+
echo "2. See what changed: git status"
|
|
71
|
+
echo "3. Revert if needed: git checkout <file>"
|
|
72
|
+
echo ""
|
|
73
|
+
echo "For detailed changelog:"
|
|
74
|
+
echo " https://github.com/prmichaelsen/agent-context-protocol/blob/mainline/CHANGELOG.md"
|
|
75
|
+
echo ""
|
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
# Task {N}: {Descriptive Task Name}
|
|
2
|
+
|
|
3
|
+
**Milestone**: [M{N} - Milestone Name](../milestones/milestone-{N}-{name}.md)
|
|
4
|
+
**Estimated Time**: [e.g., "2 hours", "4 hours", "1 day"]
|
|
5
|
+
**Dependencies**: [List prerequisite tasks, or "None"]
|
|
6
|
+
**Status**: Not Started | In Progress | Completed
|
|
7
|
+
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
## Objective
|
|
11
|
+
|
|
12
|
+
[Clearly state what this task accomplishes. Be specific and focused on a single, achievable goal.]
|
|
13
|
+
|
|
14
|
+
**Example**: "Create the basic project structure with all necessary configuration files and directory organization for a TypeScript-based MCP server."
|
|
15
|
+
|
|
16
|
+
---
|
|
17
|
+
|
|
18
|
+
## Context
|
|
19
|
+
|
|
20
|
+
[Provide background information that helps understand why this task is necessary and how it fits into the larger milestone.]
|
|
21
|
+
|
|
22
|
+
**Example**: "This task establishes the foundation for the project. Without proper structure and configuration, subsequent development tasks cannot proceed. The structure follows industry best practices for TypeScript projects and MCP server organization."
|
|
23
|
+
|
|
24
|
+
---
|
|
25
|
+
|
|
26
|
+
## Steps
|
|
27
|
+
|
|
28
|
+
[Provide a detailed, sequential list of actions to complete this task. Each step should be concrete and actionable.]
|
|
29
|
+
|
|
30
|
+
### 1. [Step Category or Action]
|
|
31
|
+
[Detailed description of what to do]
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
# Command examples if applicable
|
|
35
|
+
command --with-flags
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
```typescript
|
|
39
|
+
// Code examples if applicable
|
|
40
|
+
const example = "code";
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
### 2. [Next Step]
|
|
44
|
+
[Detailed description]
|
|
45
|
+
|
|
46
|
+
### 3. [Next Step]
|
|
47
|
+
[Detailed description]
|
|
48
|
+
|
|
49
|
+
**Example**:
|
|
50
|
+
|
|
51
|
+
### 1. Create Project Directory
|
|
52
|
+
Create the root directory for the project and navigate into it:
|
|
53
|
+
|
|
54
|
+
```bash
|
|
55
|
+
mkdir -p my-project
|
|
56
|
+
cd my-project
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
### 2. Initialize npm Project
|
|
60
|
+
Initialize a new npm project with default settings:
|
|
61
|
+
|
|
62
|
+
```bash
|
|
63
|
+
npm init -y
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
### 3. Update package.json
|
|
67
|
+
Edit the generated package.json to include proper metadata and scripts:
|
|
68
|
+
|
|
69
|
+
```json
|
|
70
|
+
{
|
|
71
|
+
"name": "my-project",
|
|
72
|
+
"version": "0.1.0",
|
|
73
|
+
"description": "Description of what this project does",
|
|
74
|
+
"main": "dist/index.js",
|
|
75
|
+
"type": "module",
|
|
76
|
+
"scripts": {
|
|
77
|
+
"build": "node esbuild.build.js",
|
|
78
|
+
"dev": "tsx watch src/index.ts",
|
|
79
|
+
"start": "node dist/index.js",
|
|
80
|
+
"test": "vitest",
|
|
81
|
+
"typecheck": "tsc --noEmit"
|
|
82
|
+
},
|
|
83
|
+
"keywords": ["mcp", "relevant", "keywords"],
|
|
84
|
+
"author": "Your Name",
|
|
85
|
+
"license": "MIT"
|
|
86
|
+
}
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
### 4. Create Directory Structure
|
|
90
|
+
Create all necessary directories:
|
|
91
|
+
|
|
92
|
+
```bash
|
|
93
|
+
mkdir -p src/{types,utils,tools}
|
|
94
|
+
mkdir -p tests/{unit,integration}
|
|
95
|
+
mkdir -p agent/{design,milestones,patterns,tasks}
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
### 5. Create Configuration Files
|
|
99
|
+
Create TypeScript configuration, build scripts, and other config files.
|
|
100
|
+
|
|
101
|
+
**tsconfig.json**:
|
|
102
|
+
```json
|
|
103
|
+
{
|
|
104
|
+
"compilerOptions": {
|
|
105
|
+
"target": "ES2022",
|
|
106
|
+
"module": "Node16",
|
|
107
|
+
"moduleResolution": "Node16",
|
|
108
|
+
"lib": ["ES2022"],
|
|
109
|
+
"outDir": "./dist",
|
|
110
|
+
"rootDir": "./src",
|
|
111
|
+
"strict": true,
|
|
112
|
+
"esModuleInterop": true,
|
|
113
|
+
"skipLibCheck": true,
|
|
114
|
+
"forceConsistentCasingInFileNames": true,
|
|
115
|
+
"resolveJsonModule": true,
|
|
116
|
+
"declaration": true,
|
|
117
|
+
"declarationMap": true,
|
|
118
|
+
"sourceMap": true
|
|
119
|
+
},
|
|
120
|
+
"include": ["src/**/*"],
|
|
121
|
+
"exclude": ["node_modules", "dist", "tests"]
|
|
122
|
+
}
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
[Continue with other config files...]
|
|
126
|
+
|
|
127
|
+
---
|
|
128
|
+
|
|
129
|
+
## Verification
|
|
130
|
+
|
|
131
|
+
[Provide a checklist of items to verify the task is complete. Each item should be objectively verifiable.]
|
|
132
|
+
|
|
133
|
+
- [ ] Verification item 1: [Specific condition to check]
|
|
134
|
+
- [ ] Verification item 2: [Specific condition to check]
|
|
135
|
+
- [ ] Verification item 3: [Specific condition to check]
|
|
136
|
+
- [ ] Verification item 4: [Specific condition to check]
|
|
137
|
+
- [ ] Verification item 5: [Specific condition to check]
|
|
138
|
+
|
|
139
|
+
**Example**:
|
|
140
|
+
- [ ] Project directory created and contains expected subdirectories
|
|
141
|
+
- [ ] package.json exists and contains correct metadata
|
|
142
|
+
- [ ] tsconfig.json exists and is valid JSON
|
|
143
|
+
- [ ] All configuration files created (.gitignore, .env.example, etc.)
|
|
144
|
+
- [ ] Directory structure matches specification
|
|
145
|
+
- [ ] No syntax errors in configuration files
|
|
146
|
+
|
|
147
|
+
---
|
|
148
|
+
|
|
149
|
+
## Expected Output
|
|
150
|
+
|
|
151
|
+
[Describe what the project should look like after this task is complete.]
|
|
152
|
+
|
|
153
|
+
**File Structure**:
|
|
154
|
+
```
|
|
155
|
+
project-root/
|
|
156
|
+
├── file1
|
|
157
|
+
├── file2
|
|
158
|
+
└── directory/
|
|
159
|
+
└── file3
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
**Key Files Created**:
|
|
163
|
+
- `file1`: [Purpose]
|
|
164
|
+
- `file2`: [Purpose]
|
|
165
|
+
- `directory/file3`: [Purpose]
|
|
166
|
+
|
|
167
|
+
---
|
|
168
|
+
|
|
169
|
+
## Common Issues and Solutions
|
|
170
|
+
|
|
171
|
+
[Document potential problems and how to resolve them:]
|
|
172
|
+
|
|
173
|
+
### Issue 1: [Problem description]
|
|
174
|
+
**Symptom**: [What the user will see]
|
|
175
|
+
**Solution**: [How to fix it]
|
|
176
|
+
|
|
177
|
+
### Issue 2: [Problem description]
|
|
178
|
+
**Symptom**: [What the user will see]
|
|
179
|
+
**Solution**: [How to fix it]
|
|
180
|
+
|
|
181
|
+
**Example**:
|
|
182
|
+
|
|
183
|
+
### Issue 1: npm init fails
|
|
184
|
+
**Symptom**: Error message about permissions or missing npm
|
|
185
|
+
**Solution**: Ensure Node.js and npm are installed correctly. Run `node --version` and `npm --version` to verify.
|
|
186
|
+
|
|
187
|
+
### Issue 2: TypeScript configuration errors
|
|
188
|
+
**Symptom**: tsc complains about invalid configuration
|
|
189
|
+
**Solution**: Validate JSON syntax in tsconfig.json. Ensure all required fields are present.
|
|
190
|
+
|
|
191
|
+
---
|
|
192
|
+
|
|
193
|
+
## Resources
|
|
194
|
+
|
|
195
|
+
[Link to relevant documentation, examples, or references:]
|
|
196
|
+
|
|
197
|
+
- [Resource 1 Name](URL): Description
|
|
198
|
+
- [Resource 2 Name](URL): Description
|
|
199
|
+
- [Resource 3 Name](URL): Description
|
|
200
|
+
|
|
201
|
+
**Example**:
|
|
202
|
+
- [TypeScript Handbook](https://www.typescriptlang.org/docs/): Official TypeScript documentation
|
|
203
|
+
- [esbuild Documentation](https://esbuild.github.io/): Build tool documentation
|
|
204
|
+
- [MCP SDK Documentation](https://github.com/modelcontextprotocol/sdk): MCP protocol reference
|
|
205
|
+
|
|
206
|
+
---
|
|
207
|
+
|
|
208
|
+
## Notes
|
|
209
|
+
|
|
210
|
+
[Any additional context, warnings, or considerations:]
|
|
211
|
+
|
|
212
|
+
- Note 1: [Important information]
|
|
213
|
+
- Note 2: [Important information]
|
|
214
|
+
- Note 3: [Important information]
|
|
215
|
+
|
|
216
|
+
**Example**:
|
|
217
|
+
- This task creates the foundation for all subsequent work
|
|
218
|
+
- Configuration files may need adjustment based on specific project requirements
|
|
219
|
+
- Keep .env files out of version control (ensure .gitignore is correct)
|
|
220
|
+
|
|
221
|
+
---
|
|
222
|
+
|
|
223
|
+
**Next Task**: [Link to next task: task-{N+1}-{name}.md]
|
|
224
|
+
**Related Design Docs**: [Links to relevant design documents]
|
|
225
|
+
**Estimated Completion Date**: [YYYY-MM-DD or "TBD"]
|
package/dist/server-factory.js
CHANGED
|
@@ -786,6 +786,28 @@ function getMemoryCollection(userId) {
|
|
|
786
786
|
return client2.collections.get(collectionName);
|
|
787
787
|
}
|
|
788
788
|
|
|
789
|
+
// src/utils/error-handler.ts
|
|
790
|
+
function formatDetailedError(error, context) {
|
|
791
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
792
|
+
const errorStack = error instanceof Error ? error.stack : void 0;
|
|
793
|
+
logger.error(`${context.toolName} failed:`, {
|
|
794
|
+
error: errorMessage,
|
|
795
|
+
stack: errorStack,
|
|
796
|
+
...context
|
|
797
|
+
});
|
|
798
|
+
const contextStr = Object.entries(context).filter(([key]) => key !== "toolName").map(([key, value]) => `${key}=${value}`).join(", ");
|
|
799
|
+
return `Failed to ${context.operation || "execute"}: ${errorMessage}` + (errorStack ? `
|
|
800
|
+
|
|
801
|
+
Stack trace:
|
|
802
|
+
${errorStack}` : "") + (contextStr ? `
|
|
803
|
+
|
|
804
|
+
Context: ${contextStr}` : "");
|
|
805
|
+
}
|
|
806
|
+
function handleToolError(error, context) {
|
|
807
|
+
const detailedMessage = formatDetailedError(error, context);
|
|
808
|
+
throw new Error(detailedMessage);
|
|
809
|
+
}
|
|
810
|
+
|
|
789
811
|
// src/constants/content-types.ts
|
|
790
812
|
var CONTENT_TYPES = [
|
|
791
813
|
// Core types
|
|
@@ -1291,8 +1313,13 @@ async function handleCreateMemory(args, userId, context) {
|
|
|
1291
1313
|
};
|
|
1292
1314
|
return JSON.stringify(response, null, 2);
|
|
1293
1315
|
} catch (error) {
|
|
1294
|
-
|
|
1295
|
-
|
|
1316
|
+
handleToolError(error, {
|
|
1317
|
+
toolName: "remember_create_memory",
|
|
1318
|
+
operation: "create memory",
|
|
1319
|
+
userId,
|
|
1320
|
+
contentType: args.type,
|
|
1321
|
+
hasContent: !!args.content
|
|
1322
|
+
});
|
|
1296
1323
|
}
|
|
1297
1324
|
}
|
|
1298
1325
|
|
|
@@ -1689,11 +1716,23 @@ async function handleUpdateMemory(args, userId) {
|
|
|
1689
1716
|
try {
|
|
1690
1717
|
logger.info("Updating memory", { userId, memoryId: args.memory_id });
|
|
1691
1718
|
const collection = getMemoryCollection(userId);
|
|
1692
|
-
|
|
1693
|
-
|
|
1694
|
-
|
|
1719
|
+
let existingMemory;
|
|
1720
|
+
try {
|
|
1721
|
+
existingMemory = await collection.query.fetchObjectById(args.memory_id, {
|
|
1722
|
+
returnProperties: ["user_id", "doc_type", "version", "type", "weight", "base_weight"]
|
|
1723
|
+
});
|
|
1724
|
+
} catch (fetchError) {
|
|
1725
|
+
const fetchErrorMsg = fetchError instanceof Error ? fetchError.message : String(fetchError);
|
|
1726
|
+
logger.error("Failed to fetch memory for update:", {
|
|
1727
|
+
error: fetchErrorMsg,
|
|
1728
|
+
userId,
|
|
1729
|
+
memoryId: args.memory_id,
|
|
1730
|
+
collectionName: `Memory_${userId}`
|
|
1731
|
+
});
|
|
1732
|
+
throw new Error(`Failed to fetch memory ${args.memory_id}: ${fetchErrorMsg}`);
|
|
1733
|
+
}
|
|
1695
1734
|
if (!existingMemory) {
|
|
1696
|
-
throw new Error(`Memory not found: ${args.memory_id}
|
|
1735
|
+
throw new Error(`Memory not found: ${args.memory_id}. It may have been deleted or never existed.`);
|
|
1697
1736
|
}
|
|
1698
1737
|
if (existingMemory.properties.user_id !== userId) {
|
|
1699
1738
|
throw new Error("Unauthorized: Cannot update another user's memory");
|
|
@@ -1753,10 +1792,22 @@ async function handleUpdateMemory(args, userId) {
|
|
|
1753
1792
|
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
1754
1793
|
updates.updated_at = now;
|
|
1755
1794
|
updates.version = existingMemory.properties.version + 1;
|
|
1756
|
-
|
|
1757
|
-
|
|
1758
|
-
|
|
1759
|
-
|
|
1795
|
+
try {
|
|
1796
|
+
await collection.data.update({
|
|
1797
|
+
id: args.memory_id,
|
|
1798
|
+
properties: updates
|
|
1799
|
+
});
|
|
1800
|
+
} catch (updateError) {
|
|
1801
|
+
const updateErrorMsg = updateError instanceof Error ? updateError.message : String(updateError);
|
|
1802
|
+
logger.error("Failed to perform Weaviate update:", {
|
|
1803
|
+
error: updateErrorMsg,
|
|
1804
|
+
userId,
|
|
1805
|
+
memoryId: args.memory_id,
|
|
1806
|
+
updateFields: Object.keys(updates),
|
|
1807
|
+
collectionName: `Memory_${userId}`
|
|
1808
|
+
});
|
|
1809
|
+
throw new Error(`Failed to update memory in Weaviate: ${updateErrorMsg}`);
|
|
1810
|
+
}
|
|
1760
1811
|
logger.info("Memory updated successfully", {
|
|
1761
1812
|
userId,
|
|
1762
1813
|
memoryId: args.memory_id,
|
|
@@ -1772,8 +1823,23 @@ async function handleUpdateMemory(args, userId) {
|
|
|
1772
1823
|
};
|
|
1773
1824
|
return JSON.stringify(result, null, 2);
|
|
1774
1825
|
} catch (error) {
|
|
1775
|
-
|
|
1776
|
-
|
|
1826
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
1827
|
+
const errorStack = error instanceof Error ? error.stack : void 0;
|
|
1828
|
+
logger.error("Failed to update memory:", {
|
|
1829
|
+
error: errorMessage,
|
|
1830
|
+
stack: errorStack,
|
|
1831
|
+
userId,
|
|
1832
|
+
memoryId: args.memory_id,
|
|
1833
|
+
providedFields: Object.keys(args).filter((k) => k !== "memory_id")
|
|
1834
|
+
});
|
|
1835
|
+
throw new Error(
|
|
1836
|
+
`Failed to update memory: ${errorMessage}` + (errorStack ? `
|
|
1837
|
+
|
|
1838
|
+
Stack trace:
|
|
1839
|
+
${errorStack}` : "") + `
|
|
1840
|
+
|
|
1841
|
+
Context: userId=${userId}, memoryId=${args.memory_id}`
|
|
1842
|
+
);
|
|
1777
1843
|
}
|
|
1778
1844
|
}
|
|
1779
1845
|
|
package/dist/server.js
CHANGED
|
@@ -828,6 +828,28 @@ function getMemoryCollection(userId) {
|
|
|
828
828
|
return client2.collections.get(collectionName);
|
|
829
829
|
}
|
|
830
830
|
|
|
831
|
+
// src/utils/error-handler.ts
|
|
832
|
+
function formatDetailedError(error, context) {
|
|
833
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
834
|
+
const errorStack = error instanceof Error ? error.stack : void 0;
|
|
835
|
+
logger.error(`${context.toolName} failed:`, {
|
|
836
|
+
error: errorMessage,
|
|
837
|
+
stack: errorStack,
|
|
838
|
+
...context
|
|
839
|
+
});
|
|
840
|
+
const contextStr = Object.entries(context).filter(([key]) => key !== "toolName").map(([key, value]) => `${key}=${value}`).join(", ");
|
|
841
|
+
return `Failed to ${context.operation || "execute"}: ${errorMessage}` + (errorStack ? `
|
|
842
|
+
|
|
843
|
+
Stack trace:
|
|
844
|
+
${errorStack}` : "") + (contextStr ? `
|
|
845
|
+
|
|
846
|
+
Context: ${contextStr}` : "");
|
|
847
|
+
}
|
|
848
|
+
function handleToolError(error, context) {
|
|
849
|
+
const detailedMessage = formatDetailedError(error, context);
|
|
850
|
+
throw new Error(detailedMessage);
|
|
851
|
+
}
|
|
852
|
+
|
|
831
853
|
// src/constants/content-types.ts
|
|
832
854
|
var CONTENT_TYPES = [
|
|
833
855
|
// Core types
|
|
@@ -1333,8 +1355,13 @@ async function handleCreateMemory(args, userId, context) {
|
|
|
1333
1355
|
};
|
|
1334
1356
|
return JSON.stringify(response, null, 2);
|
|
1335
1357
|
} catch (error) {
|
|
1336
|
-
|
|
1337
|
-
|
|
1358
|
+
handleToolError(error, {
|
|
1359
|
+
toolName: "remember_create_memory",
|
|
1360
|
+
operation: "create memory",
|
|
1361
|
+
userId,
|
|
1362
|
+
contentType: args.type,
|
|
1363
|
+
hasContent: !!args.content
|
|
1364
|
+
});
|
|
1338
1365
|
}
|
|
1339
1366
|
}
|
|
1340
1367
|
|
|
@@ -1731,11 +1758,23 @@ async function handleUpdateMemory(args, userId) {
|
|
|
1731
1758
|
try {
|
|
1732
1759
|
logger.info("Updating memory", { userId, memoryId: args.memory_id });
|
|
1733
1760
|
const collection = getMemoryCollection(userId);
|
|
1734
|
-
|
|
1735
|
-
|
|
1736
|
-
|
|
1761
|
+
let existingMemory;
|
|
1762
|
+
try {
|
|
1763
|
+
existingMemory = await collection.query.fetchObjectById(args.memory_id, {
|
|
1764
|
+
returnProperties: ["user_id", "doc_type", "version", "type", "weight", "base_weight"]
|
|
1765
|
+
});
|
|
1766
|
+
} catch (fetchError) {
|
|
1767
|
+
const fetchErrorMsg = fetchError instanceof Error ? fetchError.message : String(fetchError);
|
|
1768
|
+
logger.error("Failed to fetch memory for update:", {
|
|
1769
|
+
error: fetchErrorMsg,
|
|
1770
|
+
userId,
|
|
1771
|
+
memoryId: args.memory_id,
|
|
1772
|
+
collectionName: `Memory_${userId}`
|
|
1773
|
+
});
|
|
1774
|
+
throw new Error(`Failed to fetch memory ${args.memory_id}: ${fetchErrorMsg}`);
|
|
1775
|
+
}
|
|
1737
1776
|
if (!existingMemory) {
|
|
1738
|
-
throw new Error(`Memory not found: ${args.memory_id}
|
|
1777
|
+
throw new Error(`Memory not found: ${args.memory_id}. It may have been deleted or never existed.`);
|
|
1739
1778
|
}
|
|
1740
1779
|
if (existingMemory.properties.user_id !== userId) {
|
|
1741
1780
|
throw new Error("Unauthorized: Cannot update another user's memory");
|
|
@@ -1795,10 +1834,22 @@ async function handleUpdateMemory(args, userId) {
|
|
|
1795
1834
|
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
1796
1835
|
updates.updated_at = now;
|
|
1797
1836
|
updates.version = existingMemory.properties.version + 1;
|
|
1798
|
-
|
|
1799
|
-
|
|
1800
|
-
|
|
1801
|
-
|
|
1837
|
+
try {
|
|
1838
|
+
await collection.data.update({
|
|
1839
|
+
id: args.memory_id,
|
|
1840
|
+
properties: updates
|
|
1841
|
+
});
|
|
1842
|
+
} catch (updateError) {
|
|
1843
|
+
const updateErrorMsg = updateError instanceof Error ? updateError.message : String(updateError);
|
|
1844
|
+
logger.error("Failed to perform Weaviate update:", {
|
|
1845
|
+
error: updateErrorMsg,
|
|
1846
|
+
userId,
|
|
1847
|
+
memoryId: args.memory_id,
|
|
1848
|
+
updateFields: Object.keys(updates),
|
|
1849
|
+
collectionName: `Memory_${userId}`
|
|
1850
|
+
});
|
|
1851
|
+
throw new Error(`Failed to update memory in Weaviate: ${updateErrorMsg}`);
|
|
1852
|
+
}
|
|
1802
1853
|
logger.info("Memory updated successfully", {
|
|
1803
1854
|
userId,
|
|
1804
1855
|
memoryId: args.memory_id,
|
|
@@ -1814,8 +1865,23 @@ async function handleUpdateMemory(args, userId) {
|
|
|
1814
1865
|
};
|
|
1815
1866
|
return JSON.stringify(result, null, 2);
|
|
1816
1867
|
} catch (error) {
|
|
1817
|
-
|
|
1818
|
-
|
|
1868
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
1869
|
+
const errorStack = error instanceof Error ? error.stack : void 0;
|
|
1870
|
+
logger.error("Failed to update memory:", {
|
|
1871
|
+
error: errorMessage,
|
|
1872
|
+
stack: errorStack,
|
|
1873
|
+
userId,
|
|
1874
|
+
memoryId: args.memory_id,
|
|
1875
|
+
providedFields: Object.keys(args).filter((k) => k !== "memory_id")
|
|
1876
|
+
});
|
|
1877
|
+
throw new Error(
|
|
1878
|
+
`Failed to update memory: ${errorMessage}` + (errorStack ? `
|
|
1879
|
+
|
|
1880
|
+
Stack trace:
|
|
1881
|
+
${errorStack}` : "") + `
|
|
1882
|
+
|
|
1883
|
+
Context: userId=${userId}, memoryId=${args.memory_id}`
|
|
1884
|
+
);
|
|
1819
1885
|
}
|
|
1820
1886
|
}
|
|
1821
1887
|
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Centralized error handling utilities for MCP tools
|
|
3
|
+
* Provides consistent error logging and formatting across all tools
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Error context for detailed logging
|
|
7
|
+
*/
|
|
8
|
+
export interface ErrorContext {
|
|
9
|
+
toolName: string;
|
|
10
|
+
userId?: string;
|
|
11
|
+
operation?: string;
|
|
12
|
+
[key: string]: any;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Format error with detailed context for logging and throwing
|
|
16
|
+
*
|
|
17
|
+
* @param error - The caught error
|
|
18
|
+
* @param context - Additional context about where/why the error occurred
|
|
19
|
+
* @returns Formatted error message with stack trace and context
|
|
20
|
+
*/
|
|
21
|
+
export declare function formatDetailedError(error: unknown, context: ErrorContext): string;
|
|
22
|
+
/**
|
|
23
|
+
* Handle tool execution error with detailed logging
|
|
24
|
+
* Logs the error and throws a formatted error with full context
|
|
25
|
+
*
|
|
26
|
+
* @param error - The caught error
|
|
27
|
+
* @param context - Additional context about the operation
|
|
28
|
+
* @throws Error with detailed message including stack trace and context
|
|
29
|
+
*/
|
|
30
|
+
export declare function handleToolError(error: unknown, context: ErrorContext): never;
|
|
31
|
+
/**
|
|
32
|
+
* Wrap an async operation with detailed error handling
|
|
33
|
+
*
|
|
34
|
+
* @param operation - The async operation to execute
|
|
35
|
+
* @param context - Error context for logging
|
|
36
|
+
* @returns Result of the operation
|
|
37
|
+
* @throws Error with detailed context if operation fails
|
|
38
|
+
*/
|
|
39
|
+
export declare function withErrorHandling<T>(operation: () => Promise<T>, context: ErrorContext): Promise<T>;
|
|
40
|
+
//# sourceMappingURL=error-handler.d.ts.map
|