mirror of
https://github.com/basicmachines-co/basic-memory
synced 2026-06-21 13:47:35 +00:00
fix(mcp): route workspace-qualified memory urls (#790)
Signed-off-by: phernandez <paul@basicmachines.co>
This commit is contained in:
@@ -224,18 +224,43 @@ def build_canonical_permalink(
|
||||
project_permalink: Optional[str],
|
||||
file_path: Union[Path, str, PathLike],
|
||||
include_project: bool = True,
|
||||
*,
|
||||
workspace_permalink: Optional[str] = None,
|
||||
) -> str:
|
||||
"""Build a canonical permalink, optionally prefixed with project slug.
|
||||
"""Build a canonical permalink, optionally prefixed with workspace/project slugs.
|
||||
|
||||
Args:
|
||||
project_permalink: URL-friendly project identifier (slug). If None, no prefix is added.
|
||||
file_path: Original file path or permalink-like string.
|
||||
include_project: When True, prefix with project slug.
|
||||
workspace_permalink: Optional URL-friendly workspace identifier. When provided,
|
||||
prefix the project-qualified permalink with this workspace slug.
|
||||
|
||||
Returns:
|
||||
Canonical permalink string.
|
||||
"""
|
||||
normalized_path = generate_permalink(file_path)
|
||||
normalized_workspace = generate_permalink(workspace_permalink) if workspace_permalink else None
|
||||
|
||||
if normalized_workspace:
|
||||
if not project_permalink:
|
||||
raise ValueError("workspace_permalink requires project_permalink")
|
||||
|
||||
normalized_project = generate_permalink(project_permalink)
|
||||
workspace_project_prefix = f"{normalized_workspace}/{normalized_project}"
|
||||
if normalized_path == workspace_project_prefix or normalized_path.startswith(
|
||||
f"{workspace_project_prefix}/"
|
||||
):
|
||||
return normalized_path
|
||||
|
||||
if normalized_path == normalized_project or normalized_path.startswith(
|
||||
f"{normalized_project}/"
|
||||
):
|
||||
project_path = normalized_path
|
||||
else:
|
||||
project_path = f"{normalized_project}/{normalized_path}"
|
||||
|
||||
return f"{normalized_workspace}/{project_path}"
|
||||
|
||||
if not include_project or not project_permalink:
|
||||
return normalized_path
|
||||
@@ -244,9 +269,11 @@ def build_canonical_permalink(
|
||||
if normalized_path == normalized_project or normalized_path.startswith(
|
||||
f"{normalized_project}/"
|
||||
):
|
||||
return normalized_path
|
||||
project_path = normalized_path
|
||||
else:
|
||||
project_path = f"{normalized_project}/{normalized_path}"
|
||||
|
||||
return f"{normalized_project}/{normalized_path}"
|
||||
return project_path
|
||||
|
||||
|
||||
def setup_logging(
|
||||
|
||||
Reference in New Issue
Block a user