Skip to content

Commit d43b8b1

Browse files
committed
fix: resolve doc_get paths missing project-specific prefix
1 parent 5840f6c commit d43b8b1

2 files changed

Lines changed: 35 additions & 4 deletions

File tree

src/holoviz_mcp/holoviz_mcp/data.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2092,6 +2092,32 @@ def _get_example_paths(self, project: str, limit: int = 5) -> list[str]:
20922092
except BaseException:
20932093
return []
20942094

2095+
def _resolve_path_by_suffix(self, path: str, project: str) -> str | None:
2096+
"""Find a stored source_path ending with *path* when the exact lookup misses.
2097+
2098+
Returns the full path only when exactly one candidate matches; None otherwise.
2099+
"""
2100+
try:
2101+
results = self.collection.get(
2102+
where={"project": project},
2103+
include=["metadatas"],
2104+
)
2105+
if not results["metadatas"]:
2106+
return None
2107+
2108+
all_paths = {_normalize_source_path(str(m.get("source_path", ""))) for m in results["metadatas"] if m.get("source_path")}
2109+
2110+
suffix = "/" + path.lstrip("/")
2111+
matches = [p for p in all_paths if p.endswith(suffix) or p == path]
2112+
2113+
if len(matches) == 1:
2114+
return matches[0]
2115+
return None
2116+
except (KeyboardInterrupt, SystemExit):
2117+
raise
2118+
except BaseException:
2119+
return None
2120+
20952121
def _reconstruct_document_content(self, source_path: str, project: str) -> str:
20962122
"""Reconstruct full document content from its chunks in ChromaDB.
20972123
@@ -2418,6 +2444,13 @@ async def get_document(self, path: str, project: str, ctx: Context | None = None
24182444

24192445
# Reconstruct full content from chunks
24202446
merged_content = self._reconstruct_document_content(normalized_path, project)
2447+
2448+
if not merged_content:
2449+
resolved_path = self._resolve_path_by_suffix(normalized_path, project)
2450+
if resolved_path:
2451+
normalized_path = resolved_path
2452+
merged_content = self._reconstruct_document_content(normalized_path, project)
2453+
24212454
if not merged_content:
24222455
# Provide example paths from this project to help discoverability
24232456
example_paths = self._get_example_paths(project, limit=5)

src/holoviz_mcp/holoviz_mcp/server.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -690,10 +690,7 @@ def _load_skill_utf8(self):
690690
raise FileNotFoundError(f"Skill directory not found: {self._skill_path}")
691691

692692
if not main_file.exists():
693-
raise FileNotFoundError(
694-
f"Main skill file not found: {main_file}. "
695-
f"Expected {self._main_file_name} in {self._skill_path}"
696-
)
693+
raise FileNotFoundError(f"Main skill file not found: {main_file}. " f"Expected {self._main_file_name} in {self._skill_path}")
697694

698695
content = main_file.read_text(encoding="utf-8")
699696
frontmatter, body = _skill_provider_module.parse_frontmatter(content)
@@ -793,6 +790,7 @@ def _add_skills_provider():
793790
provider = SkillsDirectoryProvider(roots=roots, supporting_files="resources")
794791
mcp.add_provider(provider)
795792

793+
796794
_add_agent_resources()
797795
_add_skills_provider()
798796

0 commit comments

Comments
 (0)