There was an error while loading. Please reload this page.
1 parent 0d4ad7b commit 4614fd0Copy full SHA for 4614fd0
2 files changed
src/basic_memory/api/routers/resource_router.py
@@ -151,6 +151,20 @@ async def write_resource(
151
try:
152
# Get content from request body
153
154
+ # Defensive type checking: ensure content is a string
155
+ # FastAPI should validate this, but if a dict somehow gets through
156
+ # (e.g., via JSON body parsing), we need to catch it here
157
+ if isinstance(content, dict):
158
+ logger.error(
159
+ f"Error writing resource {file_path}: "
160
+ f"content is a dict, expected string. Keys: {list(content.keys())}"
161
+ )
162
+ raise HTTPException(
163
+ status_code=400,
164
+ detail="content must be a string, not a dict. "
165
+ "Ensure request body is sent as raw string content, not JSON object.",
166
167
+
168
# Ensure it's UTF-8 string content
169
if isinstance(content, bytes): # pragma: no cover
170
content_str = content.decode("utf-8")
src/basic_memory/mcp/tools/canvas.py
@@ -110,7 +110,14 @@ async def canvas(
110
111
# Write the file using the resource API
112
logger.info(f"Creating canvas file: {file_path} in project {project}")
113
- response = await call_put(client, f"{project_url}/resource/{file_path}", json=canvas_json)
+ # Send canvas_json as content string, not as json parameter
114
+ # The resource endpoint expects Body() string content, not JSON-encoded data
115
+ response = await call_put(
116
+ client,
117
+ f"{project_url}/resource/{file_path}",
118
+ content=canvas_json,
119
+ headers={"Content-Type": "text/plain"},
120
121
122
# Parse response
123
result = response.json()
0 commit comments