Skip to content

Commit 6c7d7d5

Browse files
committed
Include external_id in create_memory_project response
Previously the JSON and text responses from create_memory_project omitted external_id (UUID), forcing callers that just created a project to make a second list_memory_projects() round-trip before they could use UUID routing via the new project_id parameter. Both code paths now include it: - already-exists branch: returns existing_match.external_id - new-project branch: returns status_response.new_project.external_id - text output: adds "External ID:" line to Project Details Tests cover: - already-exists JSON path returns valid external_id string - create-new JSON path returns valid external_id string - text output includes "External ID:" line Signed-off-by: phernandez <paul@basicmachines.co>
1 parent 25be29e commit 6c7d7d5

2 files changed

Lines changed: 25 additions & 0 deletions

File tree

src/basic_memory/mcp/tools/project_management.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -463,6 +463,7 @@ async def create_memory_project(
463463
if output_format == "json":
464464
return {
465465
"name": existing_match.name,
466+
"external_id": existing_match.external_id,
466467
"path": existing_match.path,
467468
"is_default": is_default,
468469
"created": False,
@@ -472,6 +473,7 @@ async def create_memory_project(
472473
f"✓ Project already exists: {existing_match.name}\n\n"
473474
f"Project Details:\n"
474475
f"• Name: {existing_match.name}\n"
476+
f"• External ID: {existing_match.external_id}\n"
475477
f"• Path: {existing_match.path}\n"
476478
f"{'• Set as default project\n' if is_default else ''}"
477479
"\nProject is already available for use in tool calls.\n"
@@ -486,6 +488,7 @@ async def create_memory_project(
486488
new_project = status_response.new_project
487489
return {
488490
"name": new_project.name if new_project else project_name,
491+
"external_id": new_project.external_id if new_project else None,
489492
"path": new_project.path if new_project else project_path,
490493
"is_default": bool(
491494
(new_project.is_default if new_project else False) or set_default
@@ -499,6 +502,7 @@ async def create_memory_project(
499502
if status_response.new_project:
500503
result += "Project Details:\n"
501504
result += f"• Name: {status_response.new_project.name}\n"
505+
result += f"• External ID: {status_response.new_project.external_id}\n"
502506
result += f"• Path: {status_response.new_project.path}\n"
503507

504508
if set_default:

tests/mcp/test_tool_json_output_modes.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,9 @@ async def test_list_and_create_project_text_and_json_modes(app, test_project, tm
215215
)
216216
assert isinstance(create_text, str)
217217
assert "mode-create-project" in create_text
218+
# external_id should appear in the human-readable output too, so users see
219+
# the UUID without re-listing projects.
220+
assert "External ID:" in create_text
218221

219222
create_json_again = await create_memory_project(
220223
project_name=project_name,
@@ -227,6 +230,24 @@ async def test_list_and_create_project_text_and_json_modes(app, test_project, tm
227230
assert Path(create_json_again["path"]) == Path(project_path)
228231
assert create_json_again["created"] is False
229232
assert create_json_again["already_exists"] is True
233+
# external_id (UUID) must be present so callers can immediately use it as
234+
# project_id in subsequent tool calls without a list_memory_projects() round-trip.
235+
assert isinstance(create_json_again["external_id"], str)
236+
assert len(create_json_again["external_id"]) > 0
237+
238+
# Verify create-new JSON path also returns external_id (not just already-exists).
239+
new_project_name = "mode-create-fresh"
240+
new_project_path = str(tmp_path.parent / (tmp_path.name + "-projects") / "mode-create-fresh")
241+
create_json_new = await create_memory_project(
242+
project_name=new_project_name,
243+
project_path=new_project_path,
244+
output_format="json",
245+
)
246+
assert isinstance(create_json_new, dict)
247+
assert create_json_new["created"] is True
248+
assert create_json_new["already_exists"] is False
249+
assert isinstance(create_json_new["external_id"], str)
250+
assert len(create_json_new["external_id"]) > 0
230251

231252
default_project_name = "mode-default-project"
232253
default_project_path = str(

0 commit comments

Comments
 (0)